harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r478146 - in /harmony/enhanced/classlib/trunk/modules/rmi/src: main/java/javax/rmi/ssl/ main/java/org/apache/harmony/rmi/internal/nls/ test/api/java/org/apache/harmony/rmi/tests/javax/ test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ t...
Date Wed, 22 Nov 2006 12:14:04 GMT
Author: apetrenko
Date: Wed Nov 22 04:14:03 2006
New Revision: 478146

URL: http://svn.apache.org/viewvc?view=rev&rev=478146
Log:
Patch for HARMONY-2064 "[classlib][rmi] javax.rmi.ssl unit tests and improvements"

Added:
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIClientSocketFactoryTest.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIServerSocketFactoryTest.java
Modified:
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIClientSocketFactory.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIServerSocketFactory.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/nls/messages.properties

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIClientSocketFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIClientSocketFactory.java?view=diff&rev=478146&r1=478145&r2=478146
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIClientSocketFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIClientSocketFactory.java
Wed Nov 22 04:14:03 2006
@@ -27,6 +27,8 @@
 import javax.net.ssl.SSLSocket;
 import javax.net.ssl.SSLSocketFactory;
 
+import org.apache.harmony.rmi.internal.nls.Messages;
+
 public class SslRMIClientSocketFactory implements RMIClientSocketFactory,
         Serializable {
 
@@ -34,12 +36,6 @@
 
     private static SSLSocketFactory factory;
 
-    private static String enabledCipherSuites;
-
-    private static String enabledProtocols;
-
-    private static boolean isEnabledInitialized;
-
     public SslRMIClientSocketFactory() {
         if (factory == null) {
             factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
@@ -49,25 +45,28 @@
     public Socket createSocket(String host, int port) throws IOException {
 
         SSLSocket soc = (SSLSocket) factory.createSocket(host, port);
-        if (!isEnabledInitialized) {
-            isEnabledInitialized = true;
-            AccessController.doPrivileged(new java.security.PrivilegedAction() {
-
-                public Object run() {
-                    enabledCipherSuites = System
-                            .getProperty("javax.rmi.ssl.client.enabledCipherSuites");
-                    enabledProtocols = System
-                            .getProperty("javax.rmi.ssl.client.enabledProtocols");
-                    return null;
+        String[] enabled =
+            AccessController.doPrivileged(new java.security.PrivilegedAction<String[]>()
{
+                public String[] run() {
+                    return new String[] {
+                        System.getProperty("javax.rmi.ssl.client.enabledCipherSuites"), //$NON-NLS-1$
+                        System.getProperty("javax.rmi.ssl.client.enabledProtocols")}; //$NON-NLS-1$
                 }
             });
-        }
-        if (enabledCipherSuites != null) {
-            soc.setEnabledCipherSuites(enabledCipherSuites.split(","));
-        }
-
-        if (enabledProtocols != null) {
-            soc.setEnabledProtocols(enabledProtocols.split(","));
+        try {
+            if (enabled[0] != null) { //enabledCipherSuites
+                soc.setEnabledCipherSuites(enabled[0].split(",")); //$NON-NLS-1$
+            }
+
+            if (enabled[1]!= null) { //enabledProtocols
+                soc.setEnabledProtocols(enabled[1].split(",")); //$NON-NLS-1$
+            }
+        } catch (IllegalArgumentException e) {
+            // rmi.96=Error in socket creation
+            IOException ioe = new IOException(Messages.getString("rmi.96")); //$NON-NLS-1$
+            ioe.initCause(e);
+            soc.close();
+            throw ioe;
         }
 
         return soc;
@@ -78,7 +77,7 @@
     }
 
     public int hashCode() {
-        return "javax.rmi.ssl.SslRMIClientSocketFactory".hashCode();
+        return "javax.rmi.ssl.SslRMIClientSocketFactory".hashCode(); //$NON-NLS-1$
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIServerSocketFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIServerSocketFactory.java?view=diff&rev=478146&r1=478145&r2=478146
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIServerSocketFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/javax/rmi/ssl/SslRMIServerSocketFactory.java
Wed Nov 22 04:14:03 2006
@@ -68,7 +68,8 @@
         } finally {
             try {
                 soc.close();
-            } catch (IOException e) {}
+            } catch (IOException e) {
+            }
         }
 
     }
@@ -88,7 +89,7 @@
     public ServerSocket createServerSocket(int port) throws IOException {
         SSLServerSocket soc;
 
-        soc = (SSLServerSocket) factory.createServerSocket();
+        soc = (SSLServerSocket) factory.createServerSocket(port);
         if (enabledProtocols != null) {
             soc.setEnabledProtocols(enabledProtocols);
         }
@@ -102,13 +103,14 @@
     public boolean equals(Object obj) {
 
         if (obj instanceof SslRMIServerSocketFactory
-                || Arrays.equals(enabledCipherSuites,
+                && Arrays.equals(enabledCipherSuites,
                         ((SslRMIServerSocketFactory) obj)
-                                .getEnabledCipherSuites())
-                || Arrays
-                        .equals(enabledProtocols,
-                                ((SslRMIServerSocketFactory) obj)
-                                        .getEnabledProtocols())) {
+                            .getEnabledCipherSuites())
+                && Arrays.equals(enabledProtocols,
+                         ((SslRMIServerSocketFactory) obj)
+                            .getEnabledProtocols())
+                && (this.needClientAuth == ((SslRMIServerSocketFactory) obj)
+                        .getNeedClientAuth())) {
             return true;
         }
         return false;
@@ -116,7 +118,7 @@
 
     public int hashCode() {
 
-        String hashSting = "javax.rmi.ssl.SslRMIServerSocketFactory";
+        String hashSting = "javax.rmi.ssl.SslRMIServerSocketFactory"; //$NON-NLS-1$
         if (enabledCipherSuites != null) {
             for (int i = 0; i < enabledCipherSuites.length; i++) {
                 hashSting = hashSting + enabledCipherSuites[i];

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/nls/messages.properties?view=diff&rev=478146&r1=478145&r2=478146
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/nls/messages.properties
Wed Nov 22 04:14:03 2006
@@ -166,6 +166,7 @@
 rmi.93=Object was not registered or already deactivated.
 rmi.94=Could not load class {0}(access to loader for codebase "{1}" denied).
 rmi.95=Connection to [{0}:{1}] timed out
+rmi.96=Error in socket creation
 
 # log messages
 rmi.log.00=ActivationID.activate: activator = {0}

Added: harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIClientSocketFactoryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIClientSocketFactoryTest.java?view=auto&rev=478146
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIClientSocketFactoryTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIClientSocketFactoryTest.java
Wed Nov 22 04:14:03 2006
@@ -0,0 +1,70 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.rmi.tests.javax.rmi.ssl;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import javax.rmi.ssl.SslRMIClientSocketFactory;
+import javax.rmi.ssl.SslRMIServerSocketFactory;
+import javax.net.ssl.SSLSocket;
+
+import junit.framework.TestCase;
+
+public class SslRMIClientSocketFactoryTest extends TestCase {
+
+    public void testSslRMIClientSocketFactory() {
+
+        SslRMIClientSocketFactory factory = new SslRMIClientSocketFactory();
+        SslRMIClientSocketFactory factory1 = new SslRMIClientSocketFactory();
+        assertTrue(factory.equals(factory1));
+        assertTrue(factory1.equals(factory));
+    }
+
+    public void testCreateSocket() throws Exception {
+
+        SslRMIClientSocketFactory factoryCln = new SslRMIClientSocketFactory();
+        SslRMIServerSocketFactory factorySrv = new SslRMIServerSocketFactory();
+
+        ServerSocket ssocket = factorySrv.createServerSocket(0);
+        SSLSocket csocket = (SSLSocket) factoryCln.createSocket("localhost",
+                ssocket.getLocalPort());
+        csocket.close();
+        ssocket.close();
+
+        String old = System
+                .getProperty("javax.rmi.ssl.client.enabledCipherSuites");
+        try {
+            System.setProperty("javax.rmi.ssl.client.enabledCipherSuites",
+                    "Incorrect");
+            ssocket = factorySrv.createServerSocket(0);
+            try {
+                factoryCln.createSocket("localhost", ssocket.getLocalPort());
+                fail("No expected IOException");
+            } catch (IOException e) {
+            }
+            ssocket.close();
+        } finally {
+            if (old == null) {
+                System.clearProperty("javax.rmi.ssl.client.enabledCipherSuites");
+            } else {
+                System.setProperty("javax.rmi.ssl.client.enabledCipherSuites", old);
+            }
+        }
+    }
+
+}

Added: harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIServerSocketFactoryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIServerSocketFactoryTest.java?view=auto&rev=478146
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIServerSocketFactoryTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/rmi/ssl/SslRMIServerSocketFactoryTest.java
Wed Nov 22 04:14:03 2006
@@ -0,0 +1,82 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.rmi.tests.javax.rmi.ssl;
+
+import javax.rmi.ssl.SslRMIServerSocketFactory;
+import javax.net.ssl.SSLServerSocketFactory;
+
+import junit.framework.TestCase;
+
+public class SslRMIServerSocketFactoryTest extends TestCase {
+
+    public void testSslRMIServerSocketFactory() {
+        SslRMIServerSocketFactory factory = new SslRMIServerSocketFactory();
+        SslRMIServerSocketFactory factory1 = new SslRMIServerSocketFactory(
+                null, null, false);
+        assertTrue(factory.equals(factory1));
+        assertTrue(factory1.equals(factory));
+        assertNull(factory.getEnabledCipherSuites());
+        assertNull(factory.getEnabledProtocols());
+        assertFalse(factory.getNeedClientAuth());
+
+        factory1 = new SslRMIServerSocketFactory(null, null, true);
+        assertTrue(factory1.getNeedClientAuth());
+        assertFalse(factory.equals(factory1));
+        assertFalse(factory1.equals(factory));
+
+        factory1 = new SslRMIServerSocketFactory(null,
+                new String[] { "TLSv1" }, false);
+        assertFalse(factory.equals(factory1));
+        assertFalse(factory1.equals(factory));
+        
+        SSLServerSocketFactory tmpfac = (SSLServerSocketFactory) SSLServerSocketFactory
+                .getDefault();        
+        factory1 = new SslRMIServerSocketFactory(tmpfac.getDefaultCipherSuites(),
+                null, false);
+        assertFalse(factory.equals(factory1));
+        assertFalse(factory1.equals(factory));
+
+        try {
+            new SslRMIServerSocketFactory(new String[] { "Incorrect" }, null,
+                    false);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+
+        try {
+            new SslRMIServerSocketFactory(null, new String[] { "Incorrect" },
+                    false);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+
+    }
+    
+    public void testCreateServerSocket() throws Exception {
+        SslRMIServerSocketFactory factory = new SslRMIServerSocketFactory();
+
+        factory.createServerSocket(0).close();
+        
+        try {
+            factory.createServerSocket(-1);
+            fail("No expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
+}



Mime
View raw message