Skip to content

Commit

Permalink
8196770: Add JNDI test com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java
Browse files Browse the repository at this point in the history
Reviewed-by: yan, andrew
Backport-of: bc690b263b577c2f5b88c0c9932dacbd87b3d26d
  • Loading branch information
mrserb committed Sep 29, 2024
1 parent c531e47 commit f2d72b7
Show file tree
Hide file tree
Showing 4 changed files with 906 additions and 0 deletions.
117 changes: 117 additions & 0 deletions jdk/test/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8196770
* @summary Verify capability to add a new entry to the directory using the
* ADD operation.
* @library ../../lib/
* @build LDAPServer LDAPTestUtils
* @run main/othervm AddNewEntry
*/

import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import java.net.ServerSocket;
import java.util.Hashtable;

public class AddNewEntry {

public static void main(String[] args) throws Exception {
ServerSocket serverSocket = new ServerSocket(0);

Hashtable<Object, Object> env;

// initialize test
env = LDAPTestUtils
.initEnv(serverSocket, AddNewEntry.class.getName(), args, true);

/* Build attribute set */
String[] ids = { "objectClass", "sn", "cn", "telephoneNumber", "mail",
"description", "uid" };
Attribute objectClass = new BasicAttribute(ids[0]);
objectClass.add("top");
objectClass.add("person");
objectClass.add("organizationalPerson");
objectClass.add("inetOrgPerson");

Attribute sn = new BasicAttribute(ids[1], "Powers");
Attribute cn = new BasicAttribute(ids[2],
"Austin \\\"Danger\\\" Powers");
Attribute telephoneNumber = new BasicAttribute(ids[3], "+44 582 10101");
Attribute mail = new BasicAttribute(ids[4], "secret_agent_man@imc.org");
Attribute description = new BasicAttribute(ids[5], "Yea Baby!!");
description.add("Behave!");
Attribute uid = new BasicAttribute(ids[6], "secret_agent_man");

Attributes attrs = new BasicAttributes();
attrs.put(objectClass);
attrs.put(sn);
attrs.put(cn);
attrs.put(telephoneNumber);
attrs.put(mail);
attrs.put(description);
attrs.put(uid);

DirContext ctx = null;
String[] bases = new String[] { (String) env.get("client"),
(String) env.get("vendor"), "Add" };
String baseDN = LDAPTestUtils.buildDN(bases, (String) env.get("root"));
String entryDN = "cn=Austin Powers," + baseDN;
String expect = ""; // relative name

try {
// connect to server
ctx = new InitialDirContext(env);

// add entry
ctx.createSubcontext(entryDN, attrs);

// specify base search
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.OBJECT_SCOPE);

NamingEnumeration results = ctx
.search(entryDN, "(objectclass=*)", constraints);

int found = LDAPTestUtils.checkResult(results, expect);

if (found != 1) {
throw new RuntimeException(
"Check result failed, expect found 1 but actual is "
+ found);
}

} finally {
LDAPTestUtils.cleanupSubcontext(ctx, entryDN);
LDAPTestUtils.cleanup(ctx);
}
}
}
135 changes: 135 additions & 0 deletions jdk/test/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.ldap
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

################################################################################
# Capture file for AddNewEntry.java
#
# NOTE: This hexadecimal dump of LDAP protocol messages was generated by
# running the AddNewEntry application program against a real LDAP
# server and setting the JNDI/LDAP environment property:
# com.sun.jndi.ldap.trace.ber to activate LDAP message tracing.
#
################################################################################


# LDAP BindRequest

0000: 30 27 02 01 01 60 22 02 01 03 04 13 63 6E 3D 61 0'...`".....cn=a
0010: 64 6D 69 6E 2C 6F 3D 49 4D 43 2C 63 3D 55 53 80 dmin,o=IMC,c=US.
0020: 08 73 65 63 72 65 74 39 39 .secret99


# LDAP BindResponse

0000: 30 0C 02 01 01 61 07 0A 01 00 04 00 04 00 0....a........


# LDAP AddRequest

0000: 30 82 01 5F 02 01 02 68 82 01 3B 04 38 63 6E 3D 0.._...h..;.8cn=
0010: 41 75 73 74 69 6E 20 50 6F 77 65 72 73 2C 6F 75 Austin Powers,ou
0020: 3D 43 6C 69 65 6E 74 31 2C 6F 75 3D 56 65 6E 64 =Client1,ou=Vend
0030: 6F 72 31 2C 6F 75 3D 41 64 64 2C 6F 3D 49 4D 43 or1,ou=Add,o=IMC
0040: 2C 63 3D 55 53 30 81 FE 30 41 04 0B 6F 62 6A 65 ,c=US0..0A..obje
0050: 63 74 43 6C 61 73 73 31 32 04 03 74 6F 70 04 06 ctClass12..top..
0060: 70 65 72 73 6F 6E 04 14 6F 72 67 61 6E 69 7A 61 person..organiza
0070: 74 69 6F 6E 61 6C 50 65 72 73 6F 6E 04 0D 69 6E tionalPerson..in
0080: 65 74 4F 72 67 50 65 72 73 6F 6E 30 22 04 04 6D etOrgPerson0"..m
0090: 61 69 6C 31 1A 04 18 73 65 63 72 65 74 5F 61 67 ail1...secret_ag
00A0: 65 6E 74 5F 6D 61 6E 40 69 6D 63 2E 6F 72 67 30 ent_man@imc.org0
00B0: 19 04 03 75 69 64 31 12 04 10 73 65 63 72 65 74 ...uid1...secret
00C0: 5F 61 67 65 6E 74 5F 6D 61 6E 30 24 04 0B 64 65 _agent_man0$..de
00D0: 73 63 72 69 70 74 69 6F 6E 31 15 04 0A 59 65 61 scription1...Yea
00E0: 20 42 61 62 79 21 21 04 07 42 65 68 61 76 65 21 Baby!!..Behave!
00F0: 30 0E 04 02 73 6E 31 08 04 06 50 6F 77 65 72 73 0...sn1...Powers
0100: 30 22 04 0F 74 65 6C 65 70 68 6F 6E 65 4E 75 6D 0"..telephoneNum
0110: 62 65 72 31 0F 04 0D 2B 34 34 20 35 38 32 20 31 ber1...+44 582 1
0120: 30 31 30 31 30 20 04 02 63 6E 31 1A 04 18 41 75 01010 ..cn1...Au
0130: 73 74 69 6E 20 5C 22 44 61 6E 67 65 72 5C 22 20 stin \"Danger\"
0140: 50 6F 77 65 72 73 A0 1B 30 19 04 17 32 2E 31 36 Powers..0...2.16
0150: 2E 38 34 30 2E 31 2E 31 31 33 37 33 30 2E 33 2E .840.1.113730.3.
0160: 34 2E 32 4.2


# LDAP AddResponse

0000: 30 0C 02 01 02 69 07 0A 01 00 04 00 04 00 0....i........


# LDAP SearchRequest

0000: 30 7A 02 01 03 63 58 04 38 63 6E 3D 41 75 73 74 0z...cX.8cn=Aust
0010: 69 6E 20 50 6F 77 65 72 73 2C 6F 75 3D 43 6C 69 in Powers,ou=Cli
0020: 65 6E 74 31 2C 6F 75 3D 56 65 6E 64 6F 72 31 2C ent1,ou=Vendor1,
0030: 6F 75 3D 41 64 64 2C 6F 3D 49 4D 43 2C 63 3D 55 ou=Add,o=IMC,c=U
0040: 53 0A 01 00 0A 01 03 02 01 00 02 01 00 01 01 00 S...............
0050: 87 0B 6F 62 6A 65 63 74 63 6C 61 73 73 30 00 A0 ..objectclass0..
0060: 1B 30 19 04 17 32 2E 31 36 2E 38 34 30 2E 31 2E .0...2.16.840.1.
0070: 31 31 33 37 33 30 2E 33 2E 34 2E 32 113730.3.4.2


# LDAP SearchResultEntry

0000: 30 82 01 52 02 01 03 64 82 01 4B 04 38 63 6E 3D 0..R...d..K.8cn=
0010: 41 75 73 74 69 6E 20 50 6F 77 65 72 73 2C 6F 75 Austin Powers,ou
0020: 3D 43 6C 69 65 6E 74 31 2C 6F 75 3D 56 65 6E 64 =Client1,ou=Vend
0030: 6F 72 31 2C 6F 75 3D 41 64 64 2C 6F 3D 49 4D 43 or1,ou=Add,o=IMC
0040: 2C 63 3D 55 53 30 82 01 0D 30 41 04 0B 6F 62 6A ,c=US0...0A..obj
0050: 65 63 74 43 6C 61 73 73 31 32 04 03 74 6F 70 04 ectClass12..top.
0060: 06 70 65 72 73 6F 6E 04 14 6F 72 67 61 6E 69 7A .person..organiz
0070: 61 74 69 6F 6E 61 6C 50 65 72 73 6F 6E 04 0D 69 ationalPerson..i
0080: 6E 65 74 4F 72 67 50 65 72 73 6F 6E 30 22 04 04 netOrgPerson0"..
0090: 6D 61 69 6C 31 1A 04 18 73 65 63 72 65 74 5F 61 mail1...secret_a
00A0: 67 65 6E 74 5F 6D 61 6E 40 69 6D 63 2E 6F 72 67 gent_man@imc.org
00B0: 30 19 04 03 75 69 64 31 12 04 10 73 65 63 72 65 0...uid1...secre
00C0: 74 5F 61 67 65 6E 74 5F 6D 61 6E 30 24 04 0B 64 t_agent_man0$..d
00D0: 65 73 63 72 69 70 74 69 6F 6E 31 15 04 0A 59 65 escription1...Ye
00E0: 61 20 42 61 62 79 21 21 04 07 42 65 68 61 76 65 a Baby!!..Behave
00F0: 21 30 0E 04 02 73 6E 31 08 04 06 50 6F 77 65 72 !0...sn1...Power
0100: 73 30 22 04 0F 74 65 6C 65 70 68 6F 6E 65 4E 75 s0"..telephoneNu
0110: 6D 62 65 72 31 0F 04 0D 2B 34 34 20 35 38 32 20 mber1...+44 582
0120: 31 30 31 30 31 30 2F 04 02 63 6E 31 29 04 18 41 101010/..cn1)..A
0130: 75 73 74 69 6E 20 5C 22 44 61 6E 67 65 72 5C 22 ustin \"Danger\"
0140: 20 50 6F 77 65 72 73 04 0D 41 75 73 74 69 6E 20 Powers..Austin
0150: 50 6F 77 65 72 73 Powers


# LDAP SearchResultDone

0000: 30 0C 02 01 03 65 07 0A 01 00 04 00 04 00 0....e........


# LDAP DeleteRequest

0000: 30 5A 02 01 04 4A 38 63 6E 3D 41 75 73 74 69 6E 0Z...J8cn=Austin
0010: 20 50 6F 77 65 72 73 2C 6F 75 3D 43 6C 69 65 6E Powers,ou=Clien
0020: 74 31 2C 6F 75 3D 56 65 6E 64 6F 72 31 2C 6F 75 t1,ou=Vendor1,ou
0030: 3D 41 64 64 2C 6F 3D 49 4D 43 2C 63 3D 55 53 A0 =Add,o=IMC,c=US.
0040: 1B 30 19 04 17 32 2E 31 36 2E 38 34 30 2E 31 2E .0...2.16.840.1.
0050: 31 31 33 37 33 30 2E 33 2E 34 2E 32 113730.3.4.2


# LDAP DeleteResponse

0000: 30 0C 02 01 04 6B 07 0A 01 00 04 00 04 00 0....k........

Loading

1 comment on commit f2d72b7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.