1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.core.authn;
22
23
24 import org.apache.directory.server.core.authn.SimpleAuthenticator;
25 import org.apache.directory.shared.ldap.util.StringTools;
26
27 import junit.framework.TestCase;
28
29
30
31
32
33
34
35 public class SimpleAuthenticatorOneWayEncryptedTest extends TestCase
36 {
37 private SimpleAuthenticator auth = null;
38
39
40 protected void setUp() throws Exception
41 {
42 super.setUp();
43 this.auth = new SimpleAuthenticator();
44 }
45
46
47 public void testGetAlgorithmForHashedPassword()
48 {
49 String digestetValue = "{SHA}LhkDrSoM6qr0fW6hzlfOJQW61tc=";
50 assertEquals( "SHA", auth.getAlgorithmForHashedPassword( StringTools.getBytesUtf8( digestetValue ) ) );
51 assertEquals( "SHA", auth.getAlgorithmForHashedPassword( digestetValue.getBytes() ) );
52
53 String noAlgorithm = "Secret1!";
54 assertEquals( null, auth.getAlgorithmForHashedPassword( StringTools.getBytesUtf8( noAlgorithm ) ) );
55 assertEquals( null, auth.getAlgorithmForHashedPassword( noAlgorithm.getBytes() ) );
56
57 String unknownAlgorithm = "{XYZ}LhkDrSoM6qr0fW6hzlfOJQW61tc=";
58 assertEquals( null, auth.getAlgorithmForHashedPassword( StringTools.getBytesUtf8( unknownAlgorithm ) ) );
59 assertEquals( null, auth.getAlgorithmForHashedPassword( unknownAlgorithm.getBytes() ) );
60 }
61
62
63 public void testCreateDigestedPassword() throws IllegalArgumentException
64 {
65 String pwd = "Secret1!";
66 String expected = "{SHA}znbJr3+tymFoQD4+Njh4ITtI7Cc=";
67 String digested = auth.createDigestedPassword( "SHA", StringTools.getBytesUtf8( pwd ) );
68
69 assertEquals( expected, digested );
70 }
71 }