Skip to content

Commit 640b162

Browse files
mrserbgnu-andrew
authored andcommitted
8196770: Add JNDI test com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java
Reviewed-by: yan, andrew Backport-of: bc690b263b577c2f5b88c0c9932dacbd87b3d26d
1 parent 39221f8 commit 640b162

File tree

4 files changed

+906
-0
lines changed

4 files changed

+906
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8196770
27+
* @summary Verify capability to add a new entry to the directory using the
28+
* ADD operation.
29+
* @library ../../lib/
30+
* @build LDAPServer LDAPTestUtils
31+
* @run main/othervm AddNewEntry
32+
*/
33+
34+
import javax.naming.NamingEnumeration;
35+
import javax.naming.directory.Attribute;
36+
import javax.naming.directory.Attributes;
37+
import javax.naming.directory.BasicAttribute;
38+
import javax.naming.directory.BasicAttributes;
39+
import javax.naming.directory.DirContext;
40+
import javax.naming.directory.InitialDirContext;
41+
import javax.naming.directory.SearchControls;
42+
import java.net.ServerSocket;
43+
import java.util.Hashtable;
44+
45+
public class AddNewEntry {
46+
47+
public static void main(String[] args) throws Exception {
48+
ServerSocket serverSocket = new ServerSocket(0);
49+
50+
Hashtable<Object, Object> env;
51+
52+
// initialize test
53+
env = LDAPTestUtils
54+
.initEnv(serverSocket, AddNewEntry.class.getName(), args, true);
55+
56+
/* Build attribute set */
57+
String[] ids = { "objectClass", "sn", "cn", "telephoneNumber", "mail",
58+
"description", "uid" };
59+
Attribute objectClass = new BasicAttribute(ids[0]);
60+
objectClass.add("top");
61+
objectClass.add("person");
62+
objectClass.add("organizationalPerson");
63+
objectClass.add("inetOrgPerson");
64+
65+
Attribute sn = new BasicAttribute(ids[1], "Powers");
66+
Attribute cn = new BasicAttribute(ids[2],
67+
"Austin \\\"Danger\\\" Powers");
68+
Attribute telephoneNumber = new BasicAttribute(ids[3], "+44 582 10101");
69+
Attribute mail = new BasicAttribute(ids[4], "[email protected]");
70+
Attribute description = new BasicAttribute(ids[5], "Yea Baby!!");
71+
description.add("Behave!");
72+
Attribute uid = new BasicAttribute(ids[6], "secret_agent_man");
73+
74+
Attributes attrs = new BasicAttributes();
75+
attrs.put(objectClass);
76+
attrs.put(sn);
77+
attrs.put(cn);
78+
attrs.put(telephoneNumber);
79+
attrs.put(mail);
80+
attrs.put(description);
81+
attrs.put(uid);
82+
83+
DirContext ctx = null;
84+
String[] bases = new String[] { (String) env.get("client"),
85+
(String) env.get("vendor"), "Add" };
86+
String baseDN = LDAPTestUtils.buildDN(bases, (String) env.get("root"));
87+
String entryDN = "cn=Austin Powers," + baseDN;
88+
String expect = ""; // relative name
89+
90+
try {
91+
// connect to server
92+
ctx = new InitialDirContext(env);
93+
94+
// add entry
95+
ctx.createSubcontext(entryDN, attrs);
96+
97+
// specify base search
98+
SearchControls constraints = new SearchControls();
99+
constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
100+
101+
NamingEnumeration results = ctx
102+
.search(entryDN, "(objectclass=*)", constraints);
103+
104+
int found = LDAPTestUtils.checkResult(results, expect);
105+
106+
if (found != 1) {
107+
throw new RuntimeException(
108+
"Check result failed, expect found 1 but actual is "
109+
+ found);
110+
}
111+
112+
} finally {
113+
LDAPTestUtils.cleanupSubcontext(ctx, entryDN);
114+
LDAPTestUtils.cleanup(ctx);
115+
}
116+
}
117+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#
2+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
#
5+
# This code is free software; you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License version 2 only, as
7+
# published by the Free Software Foundation.
8+
#
9+
# This code is distributed in the hope that it will be useful, but WITHOUT
10+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
# version 2 for more details (a copy is included in the LICENSE file that
13+
# accompanied this code).
14+
#
15+
# You should have received a copy of the GNU General Public License version
16+
# 2 along with this work; if not, write to the Free Software Foundation,
17+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
#
19+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
# or visit www.oracle.com if you need additional information or have any
21+
# questions.
22+
#
23+
24+
################################################################################
25+
# Capture file for AddNewEntry.java
26+
#
27+
# NOTE: This hexadecimal dump of LDAP protocol messages was generated by
28+
# running the AddNewEntry application program against a real LDAP
29+
# server and setting the JNDI/LDAP environment property:
30+
# com.sun.jndi.ldap.trace.ber to activate LDAP message tracing.
31+
#
32+
################################################################################
33+
34+
35+
# LDAP BindRequest
36+
37+
0000: 30 27 02 01 01 60 22 02 01 03 04 13 63 6E 3D 61 0'...`".....cn=a
38+
0010: 64 6D 69 6E 2C 6F 3D 49 4D 43 2C 63 3D 55 53 80 dmin,o=IMC,c=US.
39+
0020: 08 73 65 63 72 65 74 39 39 .secret99
40+
41+
42+
# LDAP BindResponse
43+
44+
0000: 30 0C 02 01 01 61 07 0A 01 00 04 00 04 00 0....a........
45+
46+
47+
# LDAP AddRequest
48+
49+
0000: 30 82 01 5F 02 01 02 68 82 01 3B 04 38 63 6E 3D 0.._...h..;.8cn=
50+
0010: 41 75 73 74 69 6E 20 50 6F 77 65 72 73 2C 6F 75 Austin Powers,ou
51+
0020: 3D 43 6C 69 65 6E 74 31 2C 6F 75 3D 56 65 6E 64 =Client1,ou=Vend
52+
0030: 6F 72 31 2C 6F 75 3D 41 64 64 2C 6F 3D 49 4D 43 or1,ou=Add,o=IMC
53+
0040: 2C 63 3D 55 53 30 81 FE 30 41 04 0B 6F 62 6A 65 ,c=US0..0A..obje
54+
0050: 63 74 43 6C 61 73 73 31 32 04 03 74 6F 70 04 06 ctClass12..top..
55+
0060: 70 65 72 73 6F 6E 04 14 6F 72 67 61 6E 69 7A 61 person..organiza
56+
0070: 74 69 6F 6E 61 6C 50 65 72 73 6F 6E 04 0D 69 6E tionalPerson..in
57+
0080: 65 74 4F 72 67 50 65 72 73 6F 6E 30 22 04 04 6D etOrgPerson0"..m
58+
0090: 61 69 6C 31 1A 04 18 73 65 63 72 65 74 5F 61 67 ail1...secret_ag
59+
00A0: 65 6E 74 5F 6D 61 6E 40 69 6D 63 2E 6F 72 67 30 [email protected]
60+
00B0: 19 04 03 75 69 64 31 12 04 10 73 65 63 72 65 74 ...uid1...secret
61+
00C0: 5F 61 67 65 6E 74 5F 6D 61 6E 30 24 04 0B 64 65 _agent_man0$..de
62+
00D0: 73 63 72 69 70 74 69 6F 6E 31 15 04 0A 59 65 61 scription1...Yea
63+
00E0: 20 42 61 62 79 21 21 04 07 42 65 68 61 76 65 21 Baby!!..Behave!
64+
00F0: 30 0E 04 02 73 6E 31 08 04 06 50 6F 77 65 72 73 0...sn1...Powers
65+
0100: 30 22 04 0F 74 65 6C 65 70 68 6F 6E 65 4E 75 6D 0"..telephoneNum
66+
0110: 62 65 72 31 0F 04 0D 2B 34 34 20 35 38 32 20 31 ber1...+44 582 1
67+
0120: 30 31 30 31 30 20 04 02 63 6E 31 1A 04 18 41 75 01010 ..cn1...Au
68+
0130: 73 74 69 6E 20 5C 22 44 61 6E 67 65 72 5C 22 20 stin \"Danger\"
69+
0140: 50 6F 77 65 72 73 A0 1B 30 19 04 17 32 2E 31 36 Powers..0...2.16
70+
0150: 2E 38 34 30 2E 31 2E 31 31 33 37 33 30 2E 33 2E .840.1.113730.3.
71+
0160: 34 2E 32 4.2
72+
73+
74+
# LDAP AddResponse
75+
76+
0000: 30 0C 02 01 02 69 07 0A 01 00 04 00 04 00 0....i........
77+
78+
79+
# LDAP SearchRequest
80+
81+
0000: 30 7A 02 01 03 63 58 04 38 63 6E 3D 41 75 73 74 0z...cX.8cn=Aust
82+
0010: 69 6E 20 50 6F 77 65 72 73 2C 6F 75 3D 43 6C 69 in Powers,ou=Cli
83+
0020: 65 6E 74 31 2C 6F 75 3D 56 65 6E 64 6F 72 31 2C ent1,ou=Vendor1,
84+
0030: 6F 75 3D 41 64 64 2C 6F 3D 49 4D 43 2C 63 3D 55 ou=Add,o=IMC,c=U
85+
0040: 53 0A 01 00 0A 01 03 02 01 00 02 01 00 01 01 00 S...............
86+
0050: 87 0B 6F 62 6A 65 63 74 63 6C 61 73 73 30 00 A0 ..objectclass0..
87+
0060: 1B 30 19 04 17 32 2E 31 36 2E 38 34 30 2E 31 2E .0...2.16.840.1.
88+
0070: 31 31 33 37 33 30 2E 33 2E 34 2E 32 113730.3.4.2
89+
90+
91+
# LDAP SearchResultEntry
92+
93+
0000: 30 82 01 52 02 01 03 64 82 01 4B 04 38 63 6E 3D 0..R...d..K.8cn=
94+
0010: 41 75 73 74 69 6E 20 50 6F 77 65 72 73 2C 6F 75 Austin Powers,ou
95+
0020: 3D 43 6C 69 65 6E 74 31 2C 6F 75 3D 56 65 6E 64 =Client1,ou=Vend
96+
0030: 6F 72 31 2C 6F 75 3D 41 64 64 2C 6F 3D 49 4D 43 or1,ou=Add,o=IMC
97+
0040: 2C 63 3D 55 53 30 82 01 0D 30 41 04 0B 6F 62 6A ,c=US0...0A..obj
98+
0050: 65 63 74 43 6C 61 73 73 31 32 04 03 74 6F 70 04 ectClass12..top.
99+
0060: 06 70 65 72 73 6F 6E 04 14 6F 72 67 61 6E 69 7A .person..organiz
100+
0070: 61 74 69 6F 6E 61 6C 50 65 72 73 6F 6E 04 0D 69 ationalPerson..i
101+
0080: 6E 65 74 4F 72 67 50 65 72 73 6F 6E 30 22 04 04 netOrgPerson0"..
102+
0090: 6D 61 69 6C 31 1A 04 18 73 65 63 72 65 74 5F 61 mail1...secret_a
103+
00A0: 67 65 6E 74 5F 6D 61 6E 40 69 6D 63 2E 6F 72 67 [email protected]
104+
00B0: 30 19 04 03 75 69 64 31 12 04 10 73 65 63 72 65 0...uid1...secre
105+
00C0: 74 5F 61 67 65 6E 74 5F 6D 61 6E 30 24 04 0B 64 t_agent_man0$..d
106+
00D0: 65 73 63 72 69 70 74 69 6F 6E 31 15 04 0A 59 65 escription1...Ye
107+
00E0: 61 20 42 61 62 79 21 21 04 07 42 65 68 61 76 65 a Baby!!..Behave
108+
00F0: 21 30 0E 04 02 73 6E 31 08 04 06 50 6F 77 65 72 !0...sn1...Power
109+
0100: 73 30 22 04 0F 74 65 6C 65 70 68 6F 6E 65 4E 75 s0"..telephoneNu
110+
0110: 6D 62 65 72 31 0F 04 0D 2B 34 34 20 35 38 32 20 mber1...+44 582
111+
0120: 31 30 31 30 31 30 2F 04 02 63 6E 31 29 04 18 41 101010/..cn1)..A
112+
0130: 75 73 74 69 6E 20 5C 22 44 61 6E 67 65 72 5C 22 ustin \"Danger\"
113+
0140: 20 50 6F 77 65 72 73 04 0D 41 75 73 74 69 6E 20 Powers..Austin
114+
0150: 50 6F 77 65 72 73 Powers
115+
116+
117+
# LDAP SearchResultDone
118+
119+
0000: 30 0C 02 01 03 65 07 0A 01 00 04 00 04 00 0....e........
120+
121+
122+
# LDAP DeleteRequest
123+
124+
0000: 30 5A 02 01 04 4A 38 63 6E 3D 41 75 73 74 69 6E 0Z...J8cn=Austin
125+
0010: 20 50 6F 77 65 72 73 2C 6F 75 3D 43 6C 69 65 6E Powers,ou=Clien
126+
0020: 74 31 2C 6F 75 3D 56 65 6E 64 6F 72 31 2C 6F 75 t1,ou=Vendor1,ou
127+
0030: 3D 41 64 64 2C 6F 3D 49 4D 43 2C 63 3D 55 53 A0 =Add,o=IMC,c=US.
128+
0040: 1B 30 19 04 17 32 2E 31 36 2E 38 34 30 2E 31 2E .0...2.16.840.1.
129+
0050: 31 31 33 37 33 30 2E 33 2E 34 2E 32 113730.3.4.2
130+
131+
132+
# LDAP DeleteResponse
133+
134+
0000: 30 0C 02 01 04 6B 07 0A 01 00 04 00 04 00 0....k........
135+

0 commit comments

Comments
 (0)