1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.operations.compare;
21
22
23 import javax.naming.NamingEnumeration;
24 import javax.naming.NamingException;
25 import javax.naming.directory.DirContext;
26 import javax.naming.directory.SearchControls;
27 import javax.naming.directory.SearchResult;
28
29 import org.apache.directory.server.core.integ.Level;
30 import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
31 import org.apache.directory.server.core.integ.annotations.CleanupLevel;
32 import org.apache.directory.server.integ.ServerIntegrationUtils;
33 import org.apache.directory.server.integ.SiRunner;
34 import org.apache.directory.server.ldap.LdapService;
35
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import static org.junit.Assert.assertEquals;
39
40
41
42
43
44
45
46
47
48
49 @RunWith ( SiRunner.class )
50 @CleanupLevel ( Level.SUITE )
51 @ApplyLdifs( {
52
53 "dn: cn=Tori Amos,ou=system\n" +
54 "objectClass: person\n" +
55 "objectClass: top\n" +
56 "telephoneNumber: 1234567890\n" +
57 "userPassword: Secret1!\n" +
58 "cn: Tori Amos\n" +
59 "sn: Amos\n\n" +
60
61 "dn: cn=Artists,ou=system\n" +
62 "objectClass: groupOfNames\n" +
63 "objectClass: top\n" +
64 "cn: Artists\n" +
65 "member: cn=Tori Amos,ou=system\n\n"
66 }
67 )
68 public class MatchingRuleCompareIT
69 {
70 public static LdapService ldapService;
71
72 public static final String PERSON_CN = "Tori Amos";
73 public static final String PERSON_SN = "Amos";
74 public static final String PERSON_RDN = "cn=" + PERSON_CN;
75 public static final String PERSON_TELEPHONE = "1234567890";
76 public static final String PERSON_PWD = "Secret1!";
77
78 public static final String GROUP_CN = "Artists";
79 public static final String GROUP_RDN = "cn=" + GROUP_CN;
80
81
82
83
84
85
86
87 @Test
88 public void testCaseIgnoreMatch() throws Exception
89 {
90 DirContext ctx = ( DirContext ) ServerIntegrationUtils.getWiredContext( ldapService ).lookup( "ou=system" );
91
92
93 SearchControls ctls = new SearchControls();
94 ctls.setReturningAttributes( new String[]
95 {} );
96 ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
97
98 String[] values =
99 { PERSON_SN, PERSON_SN.toUpperCase(), PERSON_SN.toLowerCase(), PERSON_SN + "X" };
100 boolean[] expected =
101 { true, true, true, false };
102
103 for ( int i = 0; i < values.length; i++ )
104 {
105 String value = values[i];
106
107 NamingEnumeration<SearchResult> enumeration = ctx.search( PERSON_RDN, "sn={0}", new String[]
108 { value }, ctls );
109 boolean result = enumeration.hasMore();
110
111 assertEquals( "compare sn value '" + PERSON_SN + "' with '" + value + "'", expected[i], result );
112
113 enumeration.close();
114 }
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 @Test
195 public void testDistinguishedNameMatch() throws Exception
196 {
197 DirContext ctx = ( DirContext ) ServerIntegrationUtils.getWiredContext( ldapService ).lookup( "ou=system" );
198
199
200 DirContext member = ( DirContext ) ctx.lookup( PERSON_RDN );
201 String memberDN = member.getNameInNamespace();
202
203
204 SearchControls ctls = new SearchControls();
205 ctls.setReturningAttributes( new String[]
206 {} );
207 ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
208
209 String[] values =
210 { "", memberDN, "cn=nobody", memberDN, PERSON_RDN + " , " + ctx.getNameInNamespace() };
211 boolean[] expected =
212 { false, true, false, true, true };
213
214 for ( int i = 0; i < values.length; i++ )
215 {
216 String value = values[i];
217
218 NamingEnumeration<SearchResult> enumeration = ctx.search( GROUP_RDN, "member={0}", new Object[]
219 { value }, ctls );
220 boolean result = enumeration.hasMore();
221
222 assertEquals( "compare '" + memberDN + "' with '" + value + "'", expected[i], result );
223
224 enumeration.close();
225 }
226 }
227 }