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.encoding;
17:
18: import junit.framework.TestCase;
19:
20: /**
21: * <p>TestCase for PlaintextPasswordEncoder.</p>
22: *
23: * @author colin sampaleanu
24: * @author Ben Alex
25: * @author Ray Krueger
26: * @version $Id: Md5PasswordEncoderTests.java 1527 2006-05-31 03:03:18Z raykrueger $
27: */
28: public class Md5PasswordEncoderTests extends TestCase {
29: //~ Methods ========================================================================================================
30:
31: public void testBasicFunctionality() {
32: Md5PasswordEncoder pe = new Md5PasswordEncoder();
33: String raw = "abc123";
34: String badRaw = "abc321";
35: String salt = "THIS_IS_A_SALT";
36: String encoded = pe.encodePassword(raw, salt);
37: assertTrue(pe.isPasswordValid(encoded, raw, salt));
38: assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
39: assertEquals("a68aafd90299d0b137de28fb4bb68573", encoded);
40: assertEquals("MD5", pe.getAlgorithm());
41: }
42:
43: public void testBase64() throws Exception {
44: Md5PasswordEncoder pe = new Md5PasswordEncoder();
45: pe.setEncodeHashAsBase64(true);
46: String raw = "abc123";
47: String badRaw = "abc321";
48: String salt = "THIS_IS_A_SALT";
49: String encoded = pe.encodePassword(raw, salt);
50: assertTrue(pe.isPasswordValid(encoded, raw, salt));
51: assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
52: assertTrue(encoded.length() != 32);
53: }
54: }
|