]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java
Adapt default LDIF
[lgpl/argeo-commons.git] / org.argeo.security.core / ext / test / org / argeo / osgi / useradmin / LdifParserTest.java
1 package org.argeo.osgi.useradmin;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.SortedMap;
6
7 import javax.naming.NamingEnumeration;
8 import javax.naming.directory.Attribute;
9 import javax.naming.directory.Attributes;
10 import javax.naming.ldap.LdapName;
11
12 import junit.framework.TestCase;
13
14 import org.apache.commons.codec.binary.Base64;
15 import org.apache.commons.codec.digest.DigestUtils;
16
17 public class LdifParserTest extends TestCase implements BasicTestConstants {
18 public void testBasicLdif() throws Exception {
19 LdifParser ldifParser = new LdifParser();
20 SortedMap<LdapName, Attributes> res = ldifParser.read(getClass()
21 .getResourceAsStream("basic.ldif"));
22 LdapName rootDn = new LdapName(ROOT_USER_DN);
23 Attributes rootAttributes = res.get(rootDn);
24 assertNotNull(rootAttributes);
25 assertEquals("Superuser", rootAttributes.get("description").get());
26 byte[] rawPwEntry = (byte[]) rootAttributes.get("userpassword").get();
27 assertEquals("{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE=",
28 new String(rawPwEntry));
29 byte[] hashedPassword = DigestUtils.sha1("demo".getBytes());
30 assertEquals("{SHA}" + Base64.encodeBase64String(hashedPassword),
31 new String(rawPwEntry));
32
33 LdapName adminDn = new LdapName(
34 ADMIN_GROUP_DN);
35 Attributes adminAttributes = res.get(adminDn);
36 assertNotNull(adminAttributes);
37 Attribute memberAttribute = adminAttributes.get("member");
38 assertNotNull(memberAttribute);
39 NamingEnumeration<?> members = memberAttribute.getAll();
40 List<String> users = new ArrayList<String>();
41 while (members.hasMore()) {
42 Object value = members.next();
43 users.add(value.toString());
44 }
45 assertEquals(1, users.size());
46 assertEquals(rootDn, new LdapName(users.get(0)));
47 }
48 }