geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r591214 - in /geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src: main/java/org/apache/geronimo/jmxremoting/Authenticator.java test/java/org/apache/geronimo/jmxremoting/AuthenticatorTest.java
Date Fri, 02 Nov 2007 03:47:43 GMT
Author: gawor
Date: Thu Nov  1 20:47:43 2007
New Revision: 591214

URL: http://svn.apache.org/viewvc?rev=591214&view=rev
Log:
improved jmx security unit tests

Modified:
    geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/main/java/org/apache/geronimo/jmxremoting/Authenticator.java
    geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/test/java/org/apache/geronimo/jmxremoting/AuthenticatorTest.java

Modified: geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/main/java/org/apache/geronimo/jmxremoting/Authenticator.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/main/java/org/apache/geronimo/jmxremoting/Authenticator.java?rev=591214&r1=591213&r2=591214&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/main/java/org/apache/geronimo/jmxremoting/Authenticator.java
(original)
+++ geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/main/java/org/apache/geronimo/jmxremoting/Authenticator.java
Thu Nov  1 20:47:43 2007
@@ -50,7 +50,7 @@
 
     public Subject authenticate(Object o) throws SecurityException {
         if (!(o instanceof String[])) {
-            throw new IllegalArgumentException("Expected String[2], got " + o == null ? null
: o.getClass().getName());
+            throw new IllegalArgumentException("Expected String[2], got " + (o == null ?
null : o.getClass().getName()));
         }
         String[] params = (String[]) o;
         if (params.length != 2) {

Modified: geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/test/java/org/apache/geronimo/jmxremoting/AuthenticatorTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/test/java/org/apache/geronimo/jmxremoting/AuthenticatorTest.java?rev=591214&r1=591213&r2=591214&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/test/java/org/apache/geronimo/jmxremoting/AuthenticatorTest.java
(original)
+++ geronimo/server/branches/2.0/modules/geronimo-jmx-remoting/src/test/java/org/apache/geronimo/jmxremoting/AuthenticatorTest.java
Thu Nov  1 20:47:43 2007
@@ -42,20 +42,63 @@
 public class AuthenticatorTest extends TestCase {
     private static final String CONFIG_NAME = "testConfig";
     private Configuration oldConfiguration;
-    private String[] credentials;
     private Authenticator authenticator;
 
-    public void testAuthenticateWithValidPassword() {
+    public void testLogin() {
         try {
+            String[] credentials = new String[]{"system", "manager"};
             Subject s = authenticator.authenticate(credentials);
             Set principals = s.getPrincipals();
-            assertTrue(principals.contains(new MockPrincipal("username")));
+            assertTrue(principals.contains(new MockPrincipal("system")));
         } catch (SecurityException e) {
             e.printStackTrace();
             fail();
         }
     }
-
+    
+    public void testBadPasswordLogin() throws Exception {   
+        testFailure("system", "managerr");
+    }
+    
+    public void testBadUser() throws Exception {  
+        testFailure("doesnotexist", "managerr");
+    }
+    
+    public void testNullPasswordLogin() throws Exception {        
+        testFailure("system", null);
+    }
+    
+    public void testNullUserLogin() throws Exception {        
+        testFailure(null, "manager");
+    }
+    
+    public void testNullCredentialsLogin() throws Exception {        
+        testFailure(null, null);
+    }
+    
+    public void testEmptyCredentialsLogin() throws Exception {        
+        testFailure("", "");
+    }
+    
+    private void testFailure(String usernane, String password) throws Exception {
+        try {
+            String[] credentials = new String[]{usernane, password};
+            Subject s = authenticator.authenticate(credentials);
+            fail("Did not throw expected exception");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+    
+    public void testNoCredentialsLogin() {
+        try {
+            Subject s = authenticator.authenticate(null);
+            fail("Did not throw expected exception");
+        } catch (Exception e) {
+            // expected
+        }
+    }
+    
     protected void setUp() throws Exception {
         super.setUp();
         try {
@@ -66,7 +109,6 @@
         Configuration loginConfig = new MockConfiguration();
         Configuration.setConfiguration(loginConfig);
 
-        credentials = new String[]{"username", "password"};
         authenticator = new Authenticator(CONFIG_NAME, getClass().getClassLoader());
     }
 
@@ -81,7 +123,7 @@
                 fail();
             }
             Map<String, Object> map = new HashMap<String, Object>();
-            map.put("username", "password");
+            map.put("system", "manager");
             AppConfigurationEntry entry = new AppConfigurationEntry(MockModule.class.getName(),
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, map);
             return new AppConfigurationEntry[] {entry};
         }



Mime
View raw message