|
| 1 | +package junit.localtests.protocols; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.IOException; |
| 5 | +import org.junit.After; |
| 6 | +import org.junit.AfterClass; |
| 7 | +import org.junit.Before; |
| 8 | +import org.junit.BeforeClass; |
| 9 | +import org.junit.Test; |
| 10 | +import popjava.PopJava; |
| 11 | +import popjava.baseobject.POPAccessPoint; |
| 12 | +import popjava.system.POPSystem; |
| 13 | +import popjava.util.Configuration; |
| 14 | +import popjava.util.Util; |
| 15 | +import popjava.util.ssl.KeyStoreCreationOptions; |
| 16 | +import popjava.util.ssl.SSLUtils; |
| 17 | + |
| 18 | +/** |
| 19 | + * |
| 20 | + * @author dosky |
| 21 | + */ |
| 22 | +public class IncompatibleConnectionsTest { |
| 23 | + |
| 24 | + A socket; |
| 25 | + A ssl; |
| 26 | + |
| 27 | + static File keystore; |
| 28 | + static File userConfig; |
| 29 | + static KeyStoreCreationOptions options; |
| 30 | + |
| 31 | + @BeforeClass |
| 32 | + public static void setup() throws IOException { |
| 33 | + userConfig = File.createTempFile("popjunit", ".properties"); |
| 34 | + keystore = new File(String.format("popjunit-%s.jks", Util.generateUUID())); |
| 35 | + options = new KeyStoreCreationOptions("myTest", "storepass", "keypass", keystore); |
| 36 | + |
| 37 | + Configuration conf = Configuration.getInstance(); |
| 38 | + conf.setDebug(true); |
| 39 | + |
| 40 | + SSLUtils.generateKeyStore(options); |
| 41 | + conf.setSSLKeyStoreOptions(options); |
| 42 | + conf.setUserConfig(userConfig); |
| 43 | + |
| 44 | + conf.store(); |
| 45 | + } |
| 46 | + |
| 47 | + @AfterClass |
| 48 | + public static void cleanup() { |
| 49 | + userConfig.deleteOnExit(); |
| 50 | + keystore.deleteOnExit(); |
| 51 | + } |
| 52 | + |
| 53 | + @Before |
| 54 | + public void before() { |
| 55 | + POPSystem.initialize(); |
| 56 | + socket = PopJava.newActive(A.class, "localhost", new String[]{"socket"}); |
| 57 | + ssl = PopJava.newActive(A.class, "localhost", new String[]{"ssl"}); |
| 58 | + } |
| 59 | + |
| 60 | + @After |
| 61 | + public void end() { |
| 62 | + POPSystem.end(); |
| 63 | + } |
| 64 | + |
| 65 | + @Test(timeout = 1000, expected = Exception.class) |
| 66 | + public void sslToSocket() { |
| 67 | + POPAccessPoint socketAP = socket.getAccessPoint(); |
| 68 | + POPAccessPoint socketAsSSL = new POPAccessPoint(socketAP.toString()); |
| 69 | + socketAsSSL.get(0).setProtocol("ssl"); |
| 70 | + |
| 71 | + System.out.format("From %s to %s\n", socketAP, socketAsSSL); |
| 72 | + A shouldThrow = PopJava.newActive(A.class, socketAsSSL); |
| 73 | + shouldThrow.sync(); |
| 74 | + } |
| 75 | + |
| 76 | + @Test(timeout = 1000, expected = Exception.class) |
| 77 | + public void socketToSSL() { |
| 78 | + POPAccessPoint sslAP = ssl.getAccessPoint(); |
| 79 | + POPAccessPoint sslAsSocket = new POPAccessPoint(sslAP.toString()); |
| 80 | + sslAsSocket.get(0).setProtocol("socket"); |
| 81 | + |
| 82 | + System.out.format("From %s to %s\n", sslAP, sslAsSocket); |
| 83 | + A shouldThrow = PopJava.newActive(A.class, sslAsSocket); |
| 84 | + shouldThrow.sync(); |
| 85 | + } |
| 86 | +} |
0 commit comments