Skip to content
Snippets Groups Projects
Commit 79ed99b5 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4870 check the empty values of smtpServer config

parent ac572ba0
No related branches found
No related tags found
No related merge requests found
...@@ -55,13 +55,21 @@ interface KeycloakRealmMapper { ...@@ -55,13 +55,21 @@ interface KeycloakRealmMapper {
@Named("smtpServer") @Named("smtpServer")
default Map<String, String> mapSmtpServer(OzgCloudKeycloakRealmSpec.KeycloakRealmSMTPServer server) { default Map<String, String> mapSmtpServer(OzgCloudKeycloakRealmSpec.KeycloakRealmSMTPServer server) {
Map<String, String> smtpServer = new HashMap<>(); Map<String, String> smtpServer = new HashMap<>();
if( server.getHost() != null )
smtpServer.put("host", server.getHost()); smtpServer.put("host", server.getHost());
if( server.getPort() != null )
smtpServer.put("port", server.getPort()); smtpServer.put("port", server.getPort());
if( server.getUser() != null )
smtpServer.put("user", server.getUser()); smtpServer.put("user", server.getUser());
if( server.getPassword() != null )
smtpServer.put("password", server.getPassword()); smtpServer.put("password", server.getPassword());
if( server.getStarttls() != null )
smtpServer.put("starttls", server.getStarttls()); smtpServer.put("starttls", server.getStarttls());
if( server.getAuth() != null )
smtpServer.put("auth", server.getAuth()); smtpServer.put("auth", server.getAuth());
if( server.getFrom() != null )
smtpServer.put("from", server.getFrom()); smtpServer.put("from", server.getFrom());
if( server.getFromDisplayName() != null )
smtpServer.put("fromDisplayName", server.getFromDisplayName()); smtpServer.put("fromDisplayName", server.getFromDisplayName());
return smtpServer; return smtpServer;
} }
......
...@@ -100,14 +100,14 @@ class KeycloakRealmMapperTest { ...@@ -100,14 +100,14 @@ class KeycloakRealmMapperTest {
@Test @Test
void shouldContainSmtpServerKeysValues() { void shouldContainSmtpServerKeysValues() {
var mapped = mapper.map(KeycloakRealmSmtpServerTestFactory.create()); var mapped = mapper.map(OzgCloudKeycloakRealmSpecTestFactory.create());
var mappedSmtpServer = mapped.getSmtpServer(); var mappedSmtpServer = mapped.getSmtpServer();
assertThat(mappedSmtpServer.get("host")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_HOST); assertThat(mappedSmtpServer.get("host")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_HOST);
assertThat(mappedSmtpServer.get("port")).isEqualTo("432"); assertThat(mappedSmtpServer.get("port")).isEqualTo("432");
assertThat(mappedSmtpServer.get("password")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_PASSWORD); assertThat(mappedSmtpServer.get("password")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_PASSWORD);
assertThat(mappedSmtpServer.get("user")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_USER); assertThat(mappedSmtpServer.get("user")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_USER);
assertThat(mappedSmtpServer.get("starttls")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_STARTTLS.toString()); assertThat(mappedSmtpServer.get("starttls")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_STARTTLS);
assertThat(mappedSmtpServer.get("auth")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_AUTH.toString()); assertThat(mappedSmtpServer.get("auth")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_AUTH);
assertThat(mappedSmtpServer.get("from")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM); assertThat(mappedSmtpServer.get("from")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM);
assertThat(mappedSmtpServer.get("fromDisplayName")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM_DISPLAY_NAME); assertThat(mappedSmtpServer.get("fromDisplayName")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM_DISPLAY_NAME);
......
...@@ -71,6 +71,12 @@ class KeycloakRealmReconcilerTest { ...@@ -71,6 +71,12 @@ class KeycloakRealmReconcilerTest {
assertThat(response.getResource().getStatus().getStatus()).isEqualTo(OzgCloudCustomResourceStatus.OK); assertThat(response.getResource().getStatus().getStatus()).isEqualTo(OzgCloudCustomResourceStatus.OK);
} }
@Test
void shouldCreateRealmWithSpecWithoutSMTPConfig() {
var response = reconciler.reconcile(OzgCloudKeycloakRealmTestFactory.create(), null);
assertThat(response.getResource().getStatus().getStatus()).isEqualTo(OzgCloudCustomResourceStatus.OK);
}
} }
@DisplayName("Cleanup") @DisplayName("Cleanup")
......
...@@ -16,13 +16,8 @@ public class KeycloakRealmSmtpServerTestFactory { ...@@ -16,13 +16,8 @@ public class KeycloakRealmSmtpServerTestFactory {
public final static KeycloakRealmSMTPServer SMTP_SERVER = KeycloakRealmSMTPServer.builder().host(SMTP_SERVER_HOST).user(SMTP_SERVER_USER). public final static KeycloakRealmSMTPServer SMTP_SERVER = KeycloakRealmSMTPServer.builder().host(SMTP_SERVER_HOST).user(SMTP_SERVER_USER).
password(SMTP_SERVER_PASSWORD).port(SMTP_SERVER_PORT).starttls(SMTP_SERVER_STARTTLS).auth(SMTP_SERVER_AUTH).from(SMTP_SERVER_FROM).fromDisplayName(SMTP_SERVER_FROM_DISPLAY_NAME).build(); password(SMTP_SERVER_PASSWORD).port(SMTP_SERVER_PORT).starttls(SMTP_SERVER_STARTTLS).auth(SMTP_SERVER_AUTH).from(SMTP_SERVER_FROM).fromDisplayName(SMTP_SERVER_FROM_DISPLAY_NAME).build();
public static OzgCloudKeycloakRealmSpec create() { public static OzgCloudKeycloakRealmSpec.KeycloakRealmSMTPServer create() {
return createBuilder().build(); return SMTP_SERVER;
}
public static OzgCloudKeycloakRealmSpec.OzgCloudKeycloakRealmSpecBuilder createBuilder() {
return OzgCloudKeycloakRealmSpec.builder()
.smtpServer(SMTP_SERVER);
} }
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package de.ozgcloud.operator.keycloak.realm; package de.ozgcloud.operator.keycloak.realm;
public class OzgCloudKeycloakRealmSpecTestFactory { public class OzgCloudKeycloakRealmSpecTestFactory {
public final static String DISPLAY_NAME = "TestDisplayName"; public final static String DISPLAY_NAME = "TestDisplayName";
...@@ -35,6 +36,7 @@ public class OzgCloudKeycloakRealmSpecTestFactory { ...@@ -35,6 +36,7 @@ public class OzgCloudKeycloakRealmSpecTestFactory {
public static OzgCloudKeycloakRealmSpec.OzgCloudKeycloakRealmSpecBuilder createBuilder() { public static OzgCloudKeycloakRealmSpec.OzgCloudKeycloakRealmSpecBuilder createBuilder() {
return OzgCloudKeycloakRealmSpec.builder() return OzgCloudKeycloakRealmSpec.builder()
.keepAfterDelete(KEEP_AFTER_DELETE) .keepAfterDelete(KEEP_AFTER_DELETE)
.displayName(DISPLAY_NAME); .displayName(DISPLAY_NAME)
.smtpServer(KeycloakRealmSmtpServerTestFactory.create());
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment