diff --git a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java index 3c9d6902..a1275399 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java @@ -179,16 +179,17 @@ public SymphonyClientConfig build() { SymphonyClientConfig result = new SymphonyClientConfig(); - result.set(SymphonyClientConfigID.SESSIONAUTH_URL, this.sessionAuthUrl); - result.set(SymphonyClientConfigID.KEYAUTH_URL, this.keyAuthUrl); - result.set(SymphonyClientConfigID.POD_URL, this.podUrl); - result.set(SymphonyClientConfigID.AGENT_URL, this.agentUrl); - result.set(SymphonyClientConfigID.TRUSTSTORE_FILE, this.trustStoreFilename); - result.set(SymphonyClientConfigID.TRUSTSTORE_PASSWORD, new String(this.trustStorePassword)); // SECURITY HOLE DUE TO STRING INTERNING - result.set(SymphonyClientConfigID.USER_EMAIL, this.userEmail); - result.set(SymphonyClientConfigID.USER_CERT_FILE, this.userCertFilename); - result.set(SymphonyClientConfigID.USER_CERT_PASSWORD, new String(this.userCertPassword)); // SECURITY HOLE DUE TO STRING INTERNING - result.set(SymphonyClientConfigID.RECEIVER_EMAIL, this.receiverEmail); + if (this.sessionAuthUrl != null) result.set(SymphonyClientConfigID.SESSIONAUTH_URL, this.sessionAuthUrl); + if (this.keyAuthUrl != null) result.set(SymphonyClientConfigID.KEYAUTH_URL, this.keyAuthUrl); + if (this.podUrl != null) result.set(SymphonyClientConfigID.POD_URL, this.podUrl); + if (this.agentUrl != null) result.set(SymphonyClientConfigID.AGENT_URL, this.agentUrl); + if (this.trustStoreFilename != null) result.set(SymphonyClientConfigID.TRUSTSTORE_FILE, this.trustStoreFilename); + if (this.trustStorePassword != null) result.set(SymphonyClientConfigID.TRUSTSTORE_PASSWORD, new String(this.trustStorePassword)); // SECURITY HOLE DUE TO STRING INTERNING + if (this.userEmail != null) result.set(SymphonyClientConfigID.USER_EMAIL, this.userEmail); + if (this.userCertFilename != null) result.set(SymphonyClientConfigID.USER_CERT_FILE, this.userCertFilename); + if (this.userCertPassword != null) result.set(SymphonyClientConfigID.USER_CERT_PASSWORD, new String(this.userCertPassword)); // SECURITY HOLE DUE TO STRING INTERNING + if (this.receiverEmail != null) result.set(SymphonyClientConfigID.RECEIVER_EMAIL, this.receiverEmail); + result.set(SymphonyClientConfigID.DISABLE_SERVICES, String.valueOf(!this.servicesEnabled)); result.set(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED, String.valueOf(this.jmxHealthCheckEnabled)); diff --git a/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java b/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java index 7b62b8b4..c2995edc 100644 --- a/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java +++ b/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java @@ -23,7 +23,7 @@ public class SymphonyClientConfigBuilderTest { @Test - public void configTest() + public void fullConfigBuildTest() { SymphonyClientConfig config = SymphonyClientConfigBuilder.newBuilder() .withSessionAuthUrl("dummyValue-SessionAuthUrl") @@ -37,17 +37,58 @@ public void configTest() .withJMXHealthcheck(true) .build(); - assertEquals(config.get(SymphonyClientConfigID.SESSIONAUTH_URL), "dummyValue-SessionAuthUrl"); - assertEquals(config.get(SymphonyClientConfigID.KEYAUTH_URL), "dummyValue-KeyAuthUrl"); - assertEquals(config.get(SymphonyClientConfigID.POD_URL), "dummyValue-PodUrl"); - assertEquals(config.get(SymphonyClientConfigID.AGENT_URL), "dummyValue-AgentUrl"); - assertEquals(config.get(SymphonyClientConfigID.TRUSTSTORE_FILE), "dummyValue-TrustStoreFile"); - assertEquals(config.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD), "dummyValue-TrustStorePassword"); - assertEquals(config.get(SymphonyClientConfigID.USER_EMAIL), "dummyValue-UserEmail"); - assertEquals(config.get(SymphonyClientConfigID.USER_CERT_FILE), "dummyValue-UserCertFile"); - assertEquals(config.get(SymphonyClientConfigID.USER_CERT_PASSWORD), "dummyValue-UserCertPassword"); - assertEquals(config.get(SymphonyClientConfigID.RECEIVER_EMAIL), "dummyValue-ReceiverEmail"); - assertEquals(config.get(SymphonyClientConfigID.DISABLE_SERVICES), String.valueOf(false)); - assertEquals(config.get(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED), String.valueOf(true)); + assertEquals("dummyValue-SessionAuthUrl", config.get(SymphonyClientConfigID.SESSIONAUTH_URL)); + assertEquals("dummyValue-KeyAuthUrl", config.get(SymphonyClientConfigID.KEYAUTH_URL)); + assertEquals("dummyValue-PodUrl", config.get(SymphonyClientConfigID.POD_URL)); + assertEquals("dummyValue-AgentUrl", config.get(SymphonyClientConfigID.AGENT_URL)); + assertEquals("dummyValue-TrustStoreFile", config.get(SymphonyClientConfigID.TRUSTSTORE_FILE)); + assertEquals("dummyValue-TrustStorePassword", config.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD)); + assertEquals("dummyValue-UserEmail", config.get(SymphonyClientConfigID.USER_EMAIL)); + assertEquals("dummyValue-UserCertFile", config.get(SymphonyClientConfigID.USER_CERT_FILE)); + assertEquals("dummyValue-UserCertPassword", config.get(SymphonyClientConfigID.USER_CERT_PASSWORD)); + assertEquals("dummyValue-ReceiverEmail", config.get(SymphonyClientConfigID.RECEIVER_EMAIL)); + assertEquals(String.valueOf(false), config.get(SymphonyClientConfigID.DISABLE_SERVICES)); + assertEquals(String.valueOf(true), config.get(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED)); + } + + @Test + public void nullConfigBuildTest() + { + SymphonyClientConfig config = SymphonyClientConfigBuilder.newBuilder() + .withSessionAuthUrl(null) + .withKeyAuthUrl(null) + .withPodUrl(null) + .withAgentUrl(null) + .withTrustStore(null, null) + .withUserCreds(null, null, null) + .withReceiverEmail(null) + .build(); + + assertEquals(null, config.get(SymphonyClientConfigID.SESSIONAUTH_URL)); + assertEquals(null, config.get(SymphonyClientConfigID.KEYAUTH_URL)); + assertEquals(null, config.get(SymphonyClientConfigID.POD_URL)); + assertEquals(null, config.get(SymphonyClientConfigID.AGENT_URL)); + assertEquals(null, config.get(SymphonyClientConfigID.TRUSTSTORE_FILE)); + assertEquals(null, config.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD)); + assertEquals(null, config.get(SymphonyClientConfigID.USER_EMAIL)); + assertEquals(null, config.get(SymphonyClientConfigID.USER_CERT_FILE)); + assertEquals(null, config.get(SymphonyClientConfigID.USER_CERT_PASSWORD)); + assertEquals(null, config.get(SymphonyClientConfigID.RECEIVER_EMAIL)); + } + + @Test + public void defaultConfigBuildTest() + { + SymphonyClientConfig config = SymphonyClientConfigBuilder.newBuilder() + .withSessionAuthUrl(null) + .withKeyAuthUrl(null) + .withPodUrl(null) + .withAgentUrl(null) + .withTrustStore(null, null) + .withUserCreds(null, null, null) + .build(); + + assertEquals(String.valueOf(false), config.get(SymphonyClientConfigID.DISABLE_SERVICES)); + assertEquals(String.valueOf(true), config.get(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED)); } }