1 package org.kuali.student.kim.identity.mock;
2
3 import org.junit.Test;
4 import static org.junit.Assert.*;
5 import org.kuali.rice.core.api.config.property.ConfigContext;
6 import org.kuali.rice.core.api.encryption.EncryptionService;
7 import org.kuali.rice.core.impl.encryption.DemonstrationGradeEncryptionServiceImpl;
8
9 public class TestEncryptPassword {
10
11 private EncryptionService service = null;
12
13 public EncryptionService getService() {
14 if (service == null) {
15 try {
16
17 ConfigContext.init(new MockConfig());
18 service = new DemonstrationGradeEncryptionServiceImpl();
19 } catch (Exception ex) {
20 throw new RuntimeException(ex);
21 }
22 }
23 return service;
24 }
25
26 public void setService(EncryptionService service) {
27 this.service = service;
28 }
29
30 @Test
31 public void testEncryptPassword() throws Exception {
32 hashTest("admin", "0DPiKuNIrrVmD8IUCuw1hQxNqZc=");
33 hashTest("testadmin1", "2fD8gwn+QpOj4ZU3VvkbQ17mOdU=");
34 hash("kstone");
35 hash("bharris");
36 hash("criddle");
37 hash("nwelch");
38 hash("bmartin");
39 hash("nmcdonald");
40 hash("kthompson");
41 hash("ahopkins");
42 hash("jmanning");
43 hash("epittman");
44 hash("tburton");
45
46 }
47
48 private String hash(String clear) throws Exception {
49 String hashed = getService().hash(clear) + EncryptionService.HASH_POST_PREFIX;
50 System.out.println("hashed value for " + clear + "=[" + hashed + "]");
51 return hashed;
52 }
53
54 private String hashTest(String clear, String expectedHashed) throws Exception {
55 String hashed = getService().hash(clear);
56
57 assertEquals(hashed, expectedHashed);
58 return hashed;
59 }
60 }