Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/src/main/java/org/openstack4j/core/transport/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ public int hashCode() {
result = prime * result + ((natHostOrIP == null) ? 0 : natHostOrIP.hashCode());
result = prime * result + readTimeout;
result = prime * result + ((proxy == null) ? 0 : proxy.hashCode());
result = prime * result + ((sslContext == null) ? 0 : sslContext.hashCode());
result = prime * result + ((hostNameVerifier == null) ? 0 : hostNameVerifier.hashCode());
return result;
}

Expand Down Expand Up @@ -268,6 +270,21 @@ public boolean equals(Object obj) {
return false;
} else if (!proxy.equals(other.proxy))
return false;
if(sslContext == null) {
if(other.getSslContext() != null) {
return false;
}
} else if(!sslContext.equals(other.getSslContext())) {
return false;
}
if(hostNameVerifier == null) {
if(other.getHostNameVerifier() != null) {
return false;
}
} else if(!hostNameVerifier.equals(other.getHostNameVerifier())) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openstack4j.test.core.transport;

import java.security.SecureRandom;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;

import org.openstack4j.core.transport.Config;
import org.testng.Assert;
import org.testng.annotations.Test;

public class ConfigTest {

@Test
public void testUnequalConfigSsl() {
Config firstConfig = Config.newConfig();
try {
SSLContext firstSslContext = SSLContext.getInstance("SSL");

firstSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
firstConfig.withSSLContext(firstSslContext);
}catch(Exception e) {
e.printStackTrace();
}

Config secondConfig = Config.newConfig();
try {
SSLContext secondSslContext = SSLContext.getInstance("SSL");

secondSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
secondConfig.withSSLContext(secondSslContext);
}catch(Exception e) {
e.printStackTrace();
}

Assert.assertNotEquals(firstConfig, secondConfig);
}

@Test
public void testUnequalConfigHostnameVerifier() {
Config firstConfig = Config.newConfig();
firstConfig.withHostnameVerifier(new HostnameVerifier() {

@Override
public boolean verify(String hostname, SSLSession session) {
// TODO Auto-generated method stub
return false;
}
});

Config secondConfig = Config.newConfig();

Assert.assertNotEquals(firstConfig, secondConfig);
}
}