]> source.dussan.org Git - archiva.git/commitdiff
Adding unit test - does not yet pass.
authorJames William Dumay <jdumay@apache.org>
Fri, 5 Sep 2008 08:22:33 +0000 (08:22 +0000)
committerJames William Dumay <jdumay@apache.org>
Fri, 5 Sep 2008 08:22:33 +0000 (08:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@692380 13f79535-47bb-0310-9956-ffa450edef68

MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/test/java/org/apache/maven/archiva/xmlrpc/security/XmlRpcAuthenticatorTest.java [new file with mode: 0644]

diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/test/java/org/apache/maven/archiva/xmlrpc/security/XmlRpcAuthenticatorTest.java b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/test/java/org/apache/maven/archiva/xmlrpc/security/XmlRpcAuthenticatorTest.java
new file mode 100644 (file)
index 0000000..e858a7d
--- /dev/null
@@ -0,0 +1,158 @@
+\r
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements.  See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership.  The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * "License"); you may not use this file except in compliance\r
+ * with the License.  You may obtain a copy of the License at\r
+ *\r
+ *  http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied.  See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+package org.apache.maven.archiva.xmlrpc.security;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.xmlrpc.XmlRpcRequest;\r
+import org.apache.xmlrpc.XmlRpcRequestConfig;\r
+import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;\r
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;\r
+import org.codehaus.plexus.redback.authentication.AuthenticationException;\r
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;\r
+import org.codehaus.plexus.redback.authorization.AuthorizationException;\r
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;\r
+import org.codehaus.plexus.redback.keys.KeyManager;\r
+import org.codehaus.plexus.redback.policy.AccountLockedException;\r
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;\r
+import org.codehaus.plexus.redback.system.SecuritySession;\r
+import org.codehaus.plexus.redback.system.SecuritySystem;\r
+import org.codehaus.plexus.redback.users.User;\r
+import org.codehaus.plexus.redback.users.UserManager;\r
+import org.codehaus.plexus.redback.users.UserNotFoundException;\r
+\r
+public class XmlRpcAuthenticatorTest extends TestCase\r
+{\r
+    private static final String USERNAME = "username";\r
+    private static final String PASSWORD = "password";\r
+\r
+    public void testAuthentication() throws Exception\r
+    {\r
+        MockSecuritySystem securitySystem = new MockSecuritySystem(true, true, USERNAME, PASSWORD);\r
+        XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator(securitySystem);\r
+        MockXmlRpcRequest request = new MockXmlRpcRequest(USERNAME, PASSWORD);\r
+        \r
+        assertTrue(authenticator.isAuthorized(request));\r
+    }\r
+\r
+    class MockXmlRpcRequest implements XmlRpcRequest\r
+    {\r
+        private final XmlRpcHttpRequestConfigImpl configImpl;\r
+        \r
+        public MockXmlRpcRequest(String username, String password)\r
+        {\r
+            configImpl = new XmlRpcHttpRequestConfigImpl();\r
+            configImpl.setBasicUserName(username);\r
+            configImpl.setBasicPassword(password);\r
+        }\r
+\r
+        public XmlRpcRequestConfig getConfig() {\r
+            return configImpl;\r
+        }\r
+\r
+        public String getMethodName() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public Object getParameter(int pIndex) {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public int getParameterCount() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+    }\r
+\r
+    class MockSecuritySystem implements SecuritySystem\r
+    {\r
+        private final boolean authorized;\r
+        private final boolean authenticate;\r
+        private final String username;\r
+        private final String password;\r
+\r
+        public MockSecuritySystem(boolean authorized, boolean authenticate, String username, String password)\r
+        {\r
+            this.authorized = authorized;\r
+            this.authenticate = authenticate;\r
+            this.username = username;\r
+            this.password = password;\r
+        }\r
+\r
+        public SecuritySession authenticate(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {\r
+            return new SecuritySession() {\r
+\r
+                public AuthenticationResult getAuthenticationResult() {\r
+                    throw new UnsupportedOperationException("Not supported yet.");\r
+                }\r
+\r
+                public User getUser() {\r
+                    throw new UnsupportedOperationException("Not supported yet.");\r
+                }\r
+\r
+                public boolean isAuthenticated() {\r
+                    throw new UnsupportedOperationException();\r
+                }\r
+            };\r
+        }\r
+\r
+        public AuthorizationResult authorize(SecuritySession session, Object arg1) throws AuthorizationException {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public AuthorizationResult authorize(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public String getAuthenticatorId() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public String getAuthorizerId() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public KeyManager getKeyManager() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public UserSecurityPolicy getPolicy() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public String getUserManagementId() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public UserManager getUserManager() {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public boolean isAuthenticated(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public boolean isAuthorized(SecuritySession session, Object arg1) throws AuthorizationException {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+\r
+        public boolean isAuthorized(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {\r
+            throw new UnsupportedOperationException("Not supported yet.");\r
+        }\r
+    }\r
+}\r