01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.providers.ldap.authenticator;
17:
18: import junit.framework.TestCase;
19:
20: /**
21: * Tests {@link LdapShaPasswordEncoder}.
22: *
23: * @author Luke Taylor
24: * @version $Id: LdapShaPasswordEncoderTests.java 1496 2006-05-23 13:38:33Z benalex $
25: */
26: public class LdapShaPasswordEncoderTests extends TestCase {
27: //~ Instance fields ================================================================================================
28:
29: LdapShaPasswordEncoder sha;
30:
31: //~ Methods ========================================================================================================
32:
33: protected void setUp() throws Exception {
34: super .setUp();
35: sha = new LdapShaPasswordEncoder();
36: }
37:
38: public void testInvalidPasswordFails() {
39: assertFalse(sha.isPasswordValid(
40: "{SHA}ddSFGmjXYPbZC+NXR2kCzBRjqiE=", "wrongpassword",
41: null));
42: }
43:
44: public void testInvalidSaltedPasswordFails() {
45: assertFalse(sha.isPasswordValid(
46: "{SSHA}25ro4PKC8jhQZ26jVsozhX/xaP0suHgX",
47: "wrongpassword", null));
48: assertFalse(sha.isPasswordValid(
49: "{SSHA}PQy2j+6n5ytA+YlAKkM8Fh4p6u2JxfVd",
50: "wrongpassword", null));
51: }
52:
53: public void testNonByteArraySaltThrowsException() {
54: try {
55: sha.encodePassword("password", "AStringNotAByteArray");
56: } catch (IllegalArgumentException expected) {
57: }
58: }
59:
60: /**
61: * Test values generated by 'slappasswd -h {SHA} -s boabspasswurd'
62: */
63: public void testValidPasswordSucceeds() {
64: assertTrue(sha.isPasswordValid(
65: "{SHA}ddSFGmjXYPbZC+NXR2kCzBRjqiE=", "boabspasswurd",
66: null));
67: }
68:
69: /**
70: * Test values generated by 'slappasswd -s boabspasswurd'
71: */
72: public void testValidSaltedPasswordSucceeds() {
73: assertTrue(sha.isPasswordValid(
74: "{SSHA}25ro4PKC8jhQZ26jVsozhX/xaP0suHgX",
75: "boabspasswurd", null));
76: assertTrue(sha.isPasswordValid(
77: "{SSHA}PQy2j+6n5ytA+YlAKkM8Fh4p6u2JxfVd",
78: "boabspasswurd", null));
79: }
80: }
|