diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-27 15:44:23 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-27 15:44:23 +0000 |
commit | 66765100f4257159622cefe57bed50125a5ad017 (patch) | |
tree | a88ee23bb194eb91f0ebb2d9b23ff423e3ea8e37 /qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java | |
parent | 1aeaa7b16e5ce54f10c901d75c4d40f9f88b9db6 (diff) | |
parent | 88b98b2f4152ef59a671fad55a0d08338b6b78ca (diff) | |
download | qpid-python-rajith_jms_client.tar.gz |
Creating a branch for experimenting with some ideas for JMS client.rajith_jms_client
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/rajith_jms_client@1128369 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java')
-rw-r--r-- | qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java new file mode 100644 index 0000000000..f51ce0b6c6 --- /dev/null +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java @@ -0,0 +1,209 @@ +/* + * + * 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.qpid.server.security.auth.manager; + +import java.security.Provider; +import java.security.Security; + +import javax.security.sasl.SaslException; +import javax.security.sasl.SaslServer; + +import org.apache.qpid.server.security.auth.AuthenticationResult; +import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; +import org.apache.qpid.server.util.InternalBrokerBaseCase; + +/** + * + * Tests the public methods of PrincipalDatabaseAuthenticationManager. + * + */ +public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase +{ + private PrincipalDatabaseAuthenticationManager _manager = null; + + /** + * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown() + */ + @Override + public void tearDown() throws Exception + { + super.tearDown(); + if (_manager != null) + { + _manager.close(); + } + } + + /** + * @see org.apache.qpid.server.util.InternalBrokerBaseCase#setUp() + */ + @Override + public void setUp() throws Exception + { + super.setUp(); + + _manager = new PrincipalDatabaseAuthenticationManager(); + } + + /** + * Tests that the PDAM registers SASL mechanisms correctly with the runtime. + */ + public void testRegisteredMechanisms() throws Exception + { + assertNotNull(_manager.getMechanisms()); + // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager + assertEquals("PLAIN CRAM-MD5", _manager.getMechanisms()); + + Provider qpidProvider = Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME); + assertNotNull(qpidProvider); + } + + /** + * Tests that the SASL factory method createSaslServer correctly + * returns a non-null implementation. + */ + public void testSaslMechanismCreation() throws Exception + { + SaslServer server = _manager.createSaslServer("CRAM-MD5", "localhost"); + assertNotNull(server); + // Merely tests the creation of the mechanism. Mechanisms themselves are tested + // by their own tests. + } + + /** + * + * Tests that the authenticate method correctly interprets an + * authentication success. + * + */ + public void testAuthenticationSuccess() throws Exception + { + SaslServer testServer = createTestSaslServer(true, false); + + AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); + assertEquals(AuthenticationStatus.SUCCESS, result.status); + } + + /** + * + * Tests that the authenticate method correctly interprets an + * authentication not complete. + * + */ + public void testAuthenticationNotCompleted() throws Exception + { + SaslServer testServer = createTestSaslServer(false, false); + + AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); + assertEquals(AuthenticationStatus.CONTINUE, result.status); + } + + /** + * + * Tests that the authenticate method correctly interprets an + * authentication error. + * + */ + public void testAuthenticationError() throws Exception + { + SaslServer testServer = createTestSaslServer(false, true); + + AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes()); + assertEquals(AuthenticationStatus.ERROR, result.status); + } + + /** + * Tests the ability to de-register the provider. + */ + public void testClose() throws Exception + { + assertEquals("PLAIN CRAM-MD5", _manager.getMechanisms()); + assertNotNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME)); + + _manager.close(); + + // Check provider has been removed. + assertNull(_manager.getMechanisms()); + assertNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME)); + _manager = null; + } + + /** + * Test SASL implementation used to test the authenticate() method. + */ + private SaslServer createTestSaslServer(final boolean complete, final boolean throwSaslException) + { + return new SaslServer() + { + + @Override + public String getMechanismName() + { + return null; + } + + @Override + public byte[] evaluateResponse(byte[] response) throws SaslException + { + if (throwSaslException) + { + throw new SaslException("Mocked exception"); + } + return null; + } + + @Override + public boolean isComplete() + { + return complete; + } + + @Override + public String getAuthorizationID() + { + return null; + } + + @Override + public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException + { + return null; + } + + @Override + public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException + { + return null; + } + + @Override + public Object getNegotiatedProperty(String propName) + { + return null; + } + + @Override + public void dispose() throws SaslException + { + } + }; + } +} |