1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers.encoding;
17
18 import junit.framework.TestCase;
19
20
21 /***
22 * <p>
23 * TestCase for ShaPasswordEncoder.
24 * </p>
25 *
26 * @author colin sampaleanu
27 * @author Ben Alex
28 * @version $Id: ShaPasswordEncoderTests.java,v 1.2 2005/11/17 00:56:08 benalex Exp $
29 */
30 public class ShaPasswordEncoderTests extends TestCase {
31
32
33 public void testBasicFunctionality() {
34 ShaPasswordEncoder pe = new ShaPasswordEncoder();
35 String raw = "abc123";
36 String badRaw = "abc321";
37 String salt = "THIS_IS_A_SALT";
38 String encoded = pe.encodePassword(raw, salt);
39 assertTrue(pe.isPasswordValid(encoded, raw, salt));
40 assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
41 assertTrue(encoded.length() == 40);
42
43
44 pe.setEncodeHashAsBase64(true);
45 encoded = pe.encodePassword(raw, salt);
46 assertTrue(pe.isPasswordValid(encoded, raw, salt));
47 assertFalse(pe.isPasswordValid(encoded, badRaw, salt));
48 assertTrue(encoded.length() != 40);
49 }
50 }