Skip to content

Commit 616349b

Browse files
authored
Fix for endpoint format string regression (#42)
* Fix for endpoint format string regression And additional unit test to catch it * Fix && which should have been || .. thanks @alienzach!
1 parent 46cc58b commit 616349b

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/main/java/com/ibm/etcd/client/config/EtcdClusterConfig.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ private EtcdClient newClient() throws IOException, CertificateException {
103103
TlsMode ssl = tlsMode;
104104
if (ssl == TlsMode.AUTO || ssl == null) {
105105
String ep = endpointList.get(0);
106-
if (ep.startsWith("http://")) ssl = TlsMode.PLAINTEXT;
107-
else if (certificate != null || clientCertificate != null
108-
|| ep.startsWith("https://")) {
109-
ssl = TlsMode.TLS;
110-
}
106+
ssl = ep.startsWith("https://")
107+
|| (!ep.startsWith("http://")
108+
&& (certificate != null || clientCertificate != null))
109+
? TlsMode.TLS : TlsMode.PLAINTEXT;
111110
}
112111
if (ssl == TlsMode.PLAINTEXT) {
113112
builder.withPlainText();

src/test/java/com/ibm/etcd/client/JsonConfigTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public void testBasicConfig() throws Exception {
5454
runBasicTests(EtcdClusterConfig.fromJson(json));
5555
}
5656

57+
@Test
58+
public void testBasicConfigNoScheme() throws Exception {
59+
ByteSource json = makeJson("localhost:2379", null, null, null);
60+
runBasicTests(EtcdClusterConfig.fromJson(json));
61+
}
62+
5763
@Test
5864
public void testSslConfig() throws Exception {
5965
ByteSource json = makeJson("https://localhost:2360", EtcdTestSuite.serverCert, null, null);

0 commit comments

Comments
 (0)