geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r591216 - in /geronimo/server/trunk/testsuite/security-testsuite/test-security: pom.xml src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java
Date Fri, 02 Nov 2007 03:49:46 GMT
Author: gawor
Date: Thu Nov  1 20:49:45 2007
New Revision: 591216

URL: http://svn.apache.org/viewvc?rev=591216&view=rev
Log:
more jmx security tests

Added:
    geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java
  (with props)
Modified:
    geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml

Modified: geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml?rev=591216&r1=591215&r2=591216&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml (original)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/pom.xml Thu Nov  1 20:49:45
2007
@@ -26,7 +26,7 @@
 
     <parent>
         <groupId>org.apache.geronimo.testsuite</groupId>
-        <artifactId>web-testsuite</artifactId>
+        <artifactId>security-testsuite</artifactId>
         <version>2.1-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
@@ -49,6 +49,11 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
     <profiles>

Added: geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java?rev=591216&view=auto
==============================================================================
--- geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java
(added)
+++ geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java
Thu Nov  1 20:49:45 2007
@@ -0,0 +1,108 @@
+/**
+ *  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.geronimo.testsuite.security;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.geronimo.testsupport.TestSupport;
+import org.testng.annotations.Test;
+
+public class TestJMXSecurity extends TestSupport {
+
+    @Test
+    public void testLogin() throws Exception {        
+        Map environment = new HashMap();
+        environment.put(JMXConnector.CREDENTIALS, new String[] {"system", "manager"});
+        
+        MBeanServerConnection conn = getConnection(environment);
+        System.out.println(conn.getDefaultDomain());
+        assertEquals("geronimo", conn.getDefaultDomain());        
+    }
+
+    @Test
+    public void testBadPasswordLogin() throws Exception {   
+        testFailure("system", "managerr");
+    }
+    
+    @Test
+    public void testBadUser() throws Exception {  
+        testFailure("doesnotexist", "managerr");
+    }
+    
+    @Test
+    public void testNullPasswordLogin() throws Exception {        
+        testFailure("system", null);
+    }
+    
+    @Test
+    public void testNullUserLogin() throws Exception {        
+        testFailure(null, "manager");
+    }
+    
+    @Test
+    public void testNullCredentialsLogin() throws Exception {        
+        testFailure(null, null);
+    }
+    
+    @Test
+    public void testEmptyCredentialsLogin() throws Exception {        
+        testFailure("", "");
+    }
+            
+    private void testFailure(String username, String password) throws Exception {
+        Map environment = new HashMap();
+        environment.put(JMXConnector.CREDENTIALS, new String[] {username, password});
+        try {
+            MBeanServerConnection conn = getConnection(environment);
+            fail("Did not throw security exception");
+        } catch (SecurityException e) {
+            // expected
+        }
+    }
+    
+    @Test
+    public void testNoCredentialsLogin() throws Exception {        
+        Map environment = new HashMap();
+        
+        try {
+            MBeanServerConnection conn = getConnection(environment);
+            fail("Did not throw exception");
+        } catch (Exception e) {
+            // expected
+        }
+    }
+    
+    private MBeanServerConnection getConnection(Map<String, ?> env) throws IOException
{     
+        String hostname = "localhost";       
+        String port = "9999";
+        String url = "service:jmx:rmi:///jndi/rmi://" + hostname + "/JMXConnector";
+        JMXServiceURL serviceURL = new JMXServiceURL(url);
+        JMXConnector connector = JMXConnectorFactory.connect(serviceURL, env);
+        return connector.getMBeanServerConnection();
+    }
+    
+}

Propchange: geronimo/server/trunk/testsuite/security-testsuite/test-security/src/test/java/org/apache/geronimo/testsuite/security/TestJMXSecurity.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message