changeset 51751:7939b3c4e408 jdk-12+6

8208279: Add 8 JNDI tests to com/sun/jndi/dns/EnvTests/ Reviewed-by: vtewari, rriggs
author xyin
date Wed, 08 Aug 2018 10:21:23 +0800
parents edd33b9946ca
children c25572739e7c
files test/jdk/com/sun/jndi/dns/EnvTests/AddInherited.dns test/jdk/com/sun/jndi/dns/EnvTests/AddInherited.java test/jdk/com/sun/jndi/dns/EnvTests/AddOps.dns test/jdk/com/sun/jndi/dns/EnvTests/AddOps.java test/jdk/com/sun/jndi/dns/EnvTests/EnvTestBase.java test/jdk/com/sun/jndi/dns/EnvTests/GetEnv.dns test/jdk/com/sun/jndi/dns/EnvTests/GetEnv.java test/jdk/com/sun/jndi/dns/EnvTests/ProviderUrlGen.java test/jdk/com/sun/jndi/dns/EnvTests/RemoveInherited.dns test/jdk/com/sun/jndi/dns/EnvTests/RemoveInherited.java test/jdk/com/sun/jndi/dns/EnvTests/RemoveOps.dns test/jdk/com/sun/jndi/dns/EnvTests/RemoveOps.java test/jdk/com/sun/jndi/dns/EnvTests/SubcontextAdd.dns test/jdk/com/sun/jndi/dns/EnvTests/SubcontextAdd.java test/jdk/com/sun/jndi/dns/EnvTests/SubcontextRemove.dns test/jdk/com/sun/jndi/dns/EnvTests/SubcontextRemove.java
diffstat 16 files changed, 1273 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/AddInherited.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,50 @@
+#
+# 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 AddInherited.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the AddInherited application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 09 5A 00 00 00 01 00 00   00 00 00 00 05 68 6F 73  .Z...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: 09 5A 84 80 00 01 00 01   00 01 00 01 05 68 6F 73  .Z...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/AddInherited.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that when we add environment properties to a context, its
+ *          changes are reflected in the environment properties of any child
+ *          context derived from the context.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main AddInherited
+ */
+
+import javax.naming.Context;
+import javax.naming.directory.InitialDirContext;
+import java.util.Hashtable;
+
+public class AddInherited extends EnvTestBase {
+
+    public static void main(String[] args) throws Exception {
+        new AddInherited().run(args);
+    }
+
+    /*
+     * Tests that when we add environment properties to a context, its
+     * changes are reflected in the environment properties of any child
+     * context derived from the context.
+     */
+    @Override public void runTest() throws Exception {
+        setContext(new InitialDirContext(env()));
+
+        addToEnvAndVerifyOldValIsNull("com.sun.jndi.dns.recursion", "false");
+        addToEnvAndVerifyOldValIsNull("some.irrelevant.property", "somevalue");
+
+        Context child = (Context) context().lookup(getKey());
+
+        Hashtable envParent = context().getEnvironment();
+        Hashtable envChild = child.getEnvironment();
+
+        DNSTestUtils.debug(child);
+        DNSTestUtils.debug("Parent env: " + envParent);
+        DNSTestUtils.debug("Child env: " + envChild);
+
+        verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");
+        verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envChild, "some.irrelevant.property", "somevalue");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/AddOps.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,100 @@
+#
+# 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 AddOps.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the AddOps application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 38 D7 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  8............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: 38 D7 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  8............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
+# DNS Request
+
+0000: D8 67 01 00 00 01 00 00   00 00 00 00 06 73 75 6E  .g...........sun
+0010: 77 65 62 07 43 65 6E 74   72 61 6C 03 53 75 6E 03  web.Central.Sun.
+0020: 43 4F 4D 00 00 FF 00 01                            COM.....
+
+
+# DNS Response
+
+0000: D8 67 81 80 00 01 00 01   00 06 00 0C 06 73 75 6E  .g...........sun
+0010: 77 65 62 07 43 65 6E 74   72 61 6C 03 53 75 6E 03  web.Central.Sun.
+0020: 43 4F 4D 00 00 FF 00 01   C0 0C 00 05 00 01 00 00  COM.............
+0030: 2A 30 00 0E 0B 73 75 6E   77 65 62 2D 70 73 72 76  *0...sunweb-psrv
+0040: C0 13 C0 13 00 02 00 01   00 00 2A 30 00 14 0A 64  ..........*0...d
+0050: 6E 73 6D 61 73 74 65 72   34 06 6F 72 61 63 6C 65  nsmaster4.oracle
+0060: C0 1F C0 13 00 02 00 01   00 00 2A 30 00 0D 0A 64  ..........*0...d
+0070: 6E 73 6D 61 73 74 65 72   31 C0 59 C0 13 00 02 00  nsmaster1.Y.....
+0080: 01 00 00 2A 30 00 0D 0A   64 6E 73 6D 61 73 74 65  ...*0...dnsmaste
+0090: 72 33 C0 59 C0 13 00 02   00 01 00 00 2A 30 00 0D  r3.Y........*0..
+00A0: 0A 64 6E 73 6D 61 73 74   65 72 32 C0 59 C0 13 00  .dnsmaster2.Y...
+00B0: 02 00 01 00 00 2A 30 00   0D 0A 64 6E 73 6D 61 73  .....*0...dnsmas
+00C0: 74 65 72 36 C0 59 C0 13   00 02 00 01 00 00 2A 30  ter6.Y........*0
+00D0: 00 0D 0A 64 6E 73 6D 61   73 74 65 72 35 C0 59 C0  ...dnsmaster5.Y.
+00E0: B9 00 01 00 01 00 00 2A   30 00 04 C0 87 52 54 C0  .......*0....RT.
+00F0: B9 00 1C 00 01 00 00 2A   30 00 10 26 06 B4 00 14  .......*0..&....
+0100: 00 41 40 4F FF FF FF FF   FF 9F 99 C0 D2 00 01 00  .A@O............
+0110: 01 00 00 2A 30 00 04 C0   87 52 46 C0 D2 00 1C 00  ...*0....RF.....
+0120: 01 00 00 2A 30 00 10 26   06 B4 00 14 00 42 40 4F  ...*0..&.....B@O
+0130: FF FF FF FF FF 9F 99 C0   6E 00 01 00 01 00 00 2A  ........n......*
+0140: 30 00 04 C0 87 52 04 C0   6E 00 1C 00 01 00 00 2A  0....R..n......*
+0150: 30 00 10 26 06 B4 00 14   00 01 80 4F FF FF FF FF  0..&.......O....
+0160: FF 9F 99 C0 A0 00 01 00   01 00 00 2A 30 00 04 C0  ...........*0...
+0170: 87 52 14 C0 A0 00 1C 00   01 00 00 2A 30 00 10 26  .R.........*0..&
+0180: 06 B4 00 14 00 03 12 4F   FF FF FF FF FF 9F 99 C0  .......O........
+0190: 4E 00 01 00 01 00 00 2A   30 00 04 C0 87 52 34 C0  N......*0....R4.
+01A0: 4E 00 1C 00 01 00 00 2A   30 00 10 26 06 B4 00 14  N......*0..&....
+01B0: 00 81 40 4F FF FF FF FF   FF 9F 99 C0 87 00 01 00  ..@O............
+01C0: 01 00 00 2A 30 00 04 C0   87 52 24 C0 87 00 1C 00  ...*0....R$.....
+01D0: 01 00 00 2A 30 00 10 26   06 B4 00 14 00 80 40 4F  ...*0..&......@O
+01E0: FF FF FF FF FF 9F 99                               .......
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/AddOps.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that when we add the authoritative property to a context,
+ *          that it affects subsequent context operations.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main AddOps
+ */
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+
+public class AddOps extends EnvTestBase {
+
+    public static void main(String[] args) throws Exception {
+        new AddOps().run(args);
+    }
+
+    /*
+     * Tests that when we add the authoritative property to a context,
+     * that it affects subsequent context operations.
+     */
+    @Override public void runTest() throws Exception {
+        setContext(new InitialDirContext(env()));
+        addToEnvAndVerifyOldValIsNull(Context.AUTHORITATIVE, "true");
+        retrieveAndVerifyAuthData();
+        retrieveNonAuthData();
+    }
+
+    private void retrieveAndVerifyAuthData() throws NamingException {
+        // Ensure that auth data retrieval is OK
+        retrieveAndVerifyData(getFqdnUrl(), new String[] { "*" });
+    }
+
+    private void retrieveNonAuthData() throws NamingException {
+        try {
+            // Ensure that nonauth data retrieval cannot be retrieved
+            Attributes retAttrs = context()
+                    .getAttributes(getForeignFqdnUrl(), new String[] { "*" });
+            DNSTestUtils.debug(context().getEnvironment());
+            DNSTestUtils.debug(retAttrs);
+            throw new RuntimeException(
+                    "Failed: Expecting nonauth entry not found "
+                            + getForeignFqdnUrl());
+
+        } catch (NameNotFoundException e) {
+            System.out.println("Got expected exception: " + e);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/EnvTestBase.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import java.util.Hashtable;
+
+/**
+ * Abstract test base for most of Env Tests, this class extends DNSTestBase.
+ *
+ * @see DNSTestBase
+ * @see TestBase
+ */
+abstract class EnvTestBase extends DNSTestBase {
+    private static final String[] MANDATORY_ATTRIBUTES = { "A", "MX", "HINFO",
+            "TXT", "29" };
+    private static final String[] OPTIONAL_ATTRIBUTES = {};
+
+    private String key;
+    private String fqdnUrl;
+    private String foreignFqdnUrl;
+
+    public EnvTestBase() {
+        // set default test data
+        setKey("host1");
+    }
+
+    /**
+     * Setup test before real test run, it overrides the method of TestBase.
+     */
+    @Override public void setupTest() {
+        super.setupTest();
+        String fqdn = DNSTestUtils.buildFqdn(key, env(), true);
+
+        String foreignLeaf = (String) env().get("FOREIGN_LEAF");
+        String foreignFqdn = DNSTestUtils.buildFqdn(foreignLeaf, env(), false);
+
+        fqdnUrl = DNSTestUtils.getRootUrl(env()) + "/" + fqdn;
+        foreignFqdnUrl = DNSTestUtils.getRootUrl(env()) + "/" + foreignFqdn;
+    }
+
+    /**
+     * Overload method of addToEnvAndVerifyOldValIsNull, use context() as
+     * context.
+     *
+     * @param propName given property name
+     * @param propVal  given property value
+     * @throws NamingException if a naming exception is encountered
+     */
+    public void addToEnvAndVerifyOldValIsNull(String propName, Object propVal)
+            throws NamingException {
+        addToEnvAndVerifyOldValIsNull(context(), propName, propVal);
+    }
+
+    /**
+     * Add given property name/value to the environment of given context and
+     * verify the previous old property value is null which means the property
+     * was not in the environment before.
+     *
+     * @param context  given context
+     * @param propName given property name
+     * @param propVal  given property value
+     * @throws NamingException if a naming exception is encountered
+     */
+    public void addToEnvAndVerifyOldValIsNull(Context context, String propName,
+            Object propVal) throws NamingException {
+        Object oldValue = context.addToEnvironment(propName, propVal);
+        DNSTestUtils.debug("Old Value for " + propName + " : " + oldValue);
+        if (oldValue != null) {
+            throw new RuntimeException(
+                    "Failed: old value expected to be null for " + propName
+                            + " but actual is : " + oldValue);
+        }
+    }
+
+    /**
+     * Verify the value of specified property in given environment matched with
+     * given expected value. If property not exist and given expected value is
+     * null, we think verify passed. RuntimeException will be thrown if verify
+     * failed.
+     *
+     * @param env         given environment
+     * @param propName    given property name to verify
+     * @param expectedVal expected property value
+     */
+    public void verifyEnvProperty(Hashtable<?, ?> env, String propName,
+            Object expectedVal) {
+        boolean equals = true;
+        Object actualVal = env.get(propName);
+        if (actualVal != null && expectedVal != null) {
+            if (!expectedVal.equals(actualVal)) {
+                equals = false;
+            }
+        } else {
+            if (actualVal != null || expectedVal != null) {
+                equals = false;
+            }
+        }
+
+        if (!equals) {
+            throw new RuntimeException(
+                    "Failed: value not match for " + propName + " expected: "
+                            + expectedVal + " actual: " + actualVal);
+        }
+    }
+
+    /**
+     * Retrieve attributes by given name and attributes ids and verify
+     * attributes contains the mandatory attributes and the right
+     * objectclass attribute, will throw RuntimeException if verify failed.
+     *
+     * @param name    given name
+     * @param attrIds given attribute ids
+     * @throws NamingException if a naming exception is encountered
+     */
+    public void retrieveAndVerifyData(String name, String[] attrIds)
+            throws NamingException {
+        Attributes retAttrs = context().getAttributes(name, attrIds);
+        DNSTestUtils.verifySchema(retAttrs, MANDATORY_ATTRIBUTES,
+                OPTIONAL_ATTRIBUTES);
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getFqdnUrl() {
+        return fqdnUrl;
+    }
+
+    public String getForeignFqdnUrl() {
+        return foreignFqdnUrl;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/GetEnv.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,50 @@
+#
+# 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 GetEnv.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetEnv application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: BE 2D 00 00 00 01 00 00   00 00 00 00 05 68 6F 73  .-...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: BE 2D 84 80 00 01 00 01   00 01 00 01 05 68 6F 73  .-...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/GetEnv.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that we can get the environment properties of a DNS context
+ *          and its derived context, and check that they contain relevant and
+ *          irrelevant properties.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main GetEnv
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import java.util.Hashtable;
+
+public class GetEnv extends EnvTestBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetEnv().run(args);
+    }
+
+    /*
+     * Tests that we can get the environment properties of a DNS context
+     * and its derived context, and check that they contain relevant and
+     * irrelevant properties.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        Context child = (Context) context().lookup(getKey());
+
+        Hashtable envParent = context().getEnvironment();
+        Hashtable envChild = child.getEnvironment();
+
+        DNSTestUtils.debug(child);
+        DNSTestUtils.debug("Parent env: " + envParent);
+        DNSTestUtils.debug("Child env: " + envChild);
+
+        verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");
+        verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envChild, "some.irrelevant.property", "somevalue");
+    }
+
+    private void initContext() throws NamingException {
+        env().put("com.sun.jndi.dns.recursion", "false");
+        env().put("some.irrelevant.property", "somevalue");
+        setContext(new InitialDirContext(env()));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/ProviderUrlGen.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2002, 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 8208279
+ * @summary If DNS name resolution is configured normally for the local
+ *          machine, construct a context using the configured servers and verify
+ *          that a PROVIDER_URL property is generated for the context.
+ *          If DNS is not configured, or if JDK version is earlier than 1.4.1,
+ *          then this test is a no-op (it passes without doing anything).
+ * @library ../lib/
+ * @modules jdk.naming.dns/com.sun.jndi.dns
+ *          java.base/sun.security.util
+ * @run main ProviderUrlGen
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import java.lang.reflect.InvocationTargetException;
+
+public class ProviderUrlGen extends DNSTestBase {
+
+    public ProviderUrlGen() {
+        setLocalServer(false);
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (!isPlatformServersAvailable()) {
+            DNSTestUtils.debug("DNS not configured. There's nothing to test.");
+            return;
+        }
+
+        new ProviderUrlGen().run(args);
+    }
+
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        String providerUrl = (String) context().getEnvironment()
+                .get(Context.PROVIDER_URL);
+
+        if (providerUrl == null) {
+            throw new RuntimeException("Failed: PROVIDER_URL not set");
+        }
+
+        DNSTestUtils.debug("PROVIDER_URL = \"" + providerUrl + "\"");
+
+        // We don't know exactly what providerUrl's value should be.
+        // Check that it is a space-separated list of one or more URLs
+        // of the form "dns://xxxxxx".
+
+        String[] urls = providerUrl.split(" ");
+        if (urls.length < 1) {
+            throw new RuntimeException("Failed:  PROVIDER_URL is empty");
+        }
+
+        for (String url : urls) {
+            DNSTestUtils.debug(url);
+            if (!checkUrl(url)) {
+                throw new RuntimeException(
+                        "Failed:  Unexpected DNS URL: " + url);
+            }
+        }
+    }
+
+    private void initContext() throws NamingException {
+        env().remove(Context.PROVIDER_URL);
+        setContext(new InitialDirContext(env()));
+    }
+
+    private static boolean checkUrl(String url) {
+        return url.startsWith("dns://") && url.length() >= 7;
+    }
+
+    private static boolean isPlatformServersAvailable() {
+        try {
+            java.lang.reflect.Method psa = com.sun.jndi.dns.DnsContextFactory.class
+                    .getMethod("platformServersAvailable", null);
+            return (Boolean) psa.invoke(null, null);
+        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/RemoveInherited.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,50 @@
+#
+# 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 RemoveInherited.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the RemoveInherited application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: AB CC 00 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: AB CC 84 80 00 01 00 01   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/RemoveInherited.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that when we remove environment properties from a context,
+ *          its changes are reflected in the environment properties of any
+ *          child context derived from the context.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main RemoveInherited
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import java.util.Hashtable;
+
+public class RemoveInherited extends EnvTestBase {
+
+    private static final String IRRELEVANT_PROPERTY_NAME = "some.irrelevant.property";
+    private static final String IRRELEVANT_PROPERTY_VALUE = "somevalue";
+    private static final String DNS_RECURSION_PROPERTY_NAME = "com.sun.jndi.dns.recursion";
+    private static final String DNS_RECURSION_PROPERTY_VALUE = "false";
+
+    public static void main(String[] args) throws Exception {
+        new RemoveInherited().run(args);
+    }
+
+    /*
+     * Tests that when we remove environment properties from a context,
+     * its changes are reflected in the environment properties of any
+     * child context derived from the context.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        // some.irrelevant.property been set in initContext(), should not be null
+        Object val = context().removeFromEnvironment(IRRELEVANT_PROPERTY_NAME);
+
+        if (!IRRELEVANT_PROPERTY_VALUE.equals(val)) {
+            throw new RuntimeException(
+                    "Failed: unexpected return value for removeFromEnvironment: "
+                            + val);
+        }
+
+        Context child = (Context) context().lookup(getKey());
+
+        Hashtable envParent = context().getEnvironment();
+        Hashtable envChild = child.getEnvironment();
+
+        DNSTestUtils.debug(child);
+        DNSTestUtils.debug("Parent env: " + envParent);
+        DNSTestUtils.debug("Child env: " + envChild);
+
+        verifyEnvProperty(envParent, DNS_RECURSION_PROPERTY_NAME,
+                DNS_RECURSION_PROPERTY_VALUE);
+        verifyEnvProperty(envParent, IRRELEVANT_PROPERTY_NAME, null);
+        verifyEnvProperty(envChild, DNS_RECURSION_PROPERTY_NAME,
+                DNS_RECURSION_PROPERTY_VALUE);
+        verifyEnvProperty(envChild, IRRELEVANT_PROPERTY_NAME, null);
+    }
+
+    private void initContext() throws NamingException {
+        env().put(DNS_RECURSION_PROPERTY_NAME, DNS_RECURSION_PROPERTY_VALUE);
+        env().put(IRRELEVANT_PROPERTY_NAME, IRRELEVANT_PROPERTY_VALUE);
+        setContext(new InitialDirContext(env()));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/RemoveOps.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,100 @@
+#
+# 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 RemoveOps.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the RemoveOps application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 0C 4D 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .M...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: 0C 4D 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .M...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 11 00 0A 05 72 65  ..............re
+0090: 6C 61 79 04 6F 68 69 6F   02 75 73 00 C0 0C 00 0F  lay.ohio.us.....
+00A0: 00 01 00 00 8C A0 00 10   00 14 05 72 65 6C 61 79  ...........relay
+00B0: 05 74 65 78 61 73 C0 98   C0 0C 00 01 00 01 00 01  .texas..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
+# DNS Request
+
+0000: 01 15 01 00 00 01 00 00   00 00 00 00 06 73 75 6E  .............sun
+0010: 77 65 62 07 43 65 6E 74   72 61 6C 03 53 75 6E 03  web.Central.Sun.
+0020: 43 4F 4D 00 00 FF 00 01                            COM.....
+
+
+# DNS Response
+
+0000: 01 15 81 80 00 01 00 01   00 06 00 0C 06 73 75 6E  .............sun
+0010: 77 65 62 07 43 65 6E 74   72 61 6C 03 53 75 6E 03  web.Central.Sun.
+0020: 43 4F 4D 00 00 FF 00 01   C0 0C 00 05 00 01 00 00  COM.............
+0030: 2A 30 00 0E 0B 73 75 6E   77 65 62 2D 70 73 72 76  *0...sunweb-psrv
+0040: C0 13 C0 13 00 02 00 01   00 00 2A 30 00 14 0A 64  ..........*0...d
+0050: 6E 73 6D 61 73 74 65 72   32 06 6F 72 61 63 6C 65  nsmaster2.oracle
+0060: C0 1F C0 13 00 02 00 01   00 00 2A 30 00 0D 0A 64  ..........*0...d
+0070: 6E 73 6D 61 73 74 65 72   34 C0 59 C0 13 00 02 00  nsmaster4.Y.....
+0080: 01 00 00 2A 30 00 0D 0A   64 6E 73 6D 61 73 74 65  ...*0...dnsmaste
+0090: 72 36 C0 59 C0 13 00 02   00 01 00 00 2A 30 00 0D  r6.Y........*0..
+00A0: 0A 64 6E 73 6D 61 73 74   65 72 33 C0 59 C0 13 00  .dnsmaster3.Y...
+00B0: 02 00 01 00 00 2A 30 00   0D 0A 64 6E 73 6D 61 73  .....*0...dnsmas
+00C0: 74 65 72 31 C0 59 C0 13   00 02 00 01 00 00 2A 30  ter1.Y........*0
+00D0: 00 0D 0A 64 6E 73 6D 61   73 74 65 72 35 C0 59 C0  ...dnsmaster5.Y.
+00E0: D2 00 01 00 01 00 00 2A   30 00 04 C0 87 52 46 C0  .......*0....RF.
+00F0: D2 00 1C 00 01 00 00 2A   30 00 10 26 06 B4 00 14  .......*0..&....
+0100: 00 42 40 4F FF FF FF FF   FF 9F 99 C0 A0 00 01 00  .B@O............
+0110: 01 00 00 2A 30 00 04 C0   87 52 24 C0 A0 00 1C 00  ...*0....R$.....
+0120: 01 00 00 2A 30 00 10 26   06 B4 00 14 00 80 40 4F  ...*0..&......@O
+0130: FF FF FF FF FF 9F 99 C0   87 00 01 00 01 00 00 2A  ...............*
+0140: 30 00 04 C0 87 52 54 C0   87 00 1C 00 01 00 00 2A  0....RT........*
+0150: 30 00 10 26 06 B4 00 14   00 41 40 4F FF FF FF FF  0..&.....A@O....
+0160: FF 9F 99 C0 4E 00 01 00   01 00 00 2A 30 00 04 C0  ....N......*0...
+0170: 87 52 14 C0 4E 00 1C 00   01 00 00 2A 30 00 10 26  .R..N......*0..&
+0180: 06 B4 00 14 00 03 12 4F   FF FF FF FF FF 9F 99 C0  .......O........
+0190: 6E 00 01 00 01 00 00 2A   30 00 04 C0 87 52 34 C0  n......*0....R4.
+01A0: 6E 00 1C 00 01 00 00 2A   30 00 10 26 06 B4 00 14  n......*0..&....
+01B0: 00 81 40 4F FF FF FF FF   FF 9F 99 C0 B9 00 01 00  ..@O............
+01C0: 01 00 00 2A 30 00 04 C0   87 52 04 C0 B9 00 1C 00  ...*0....R......
+01D0: 01 00 00 2A 30 00 10 26   06 B4 00 14 00 01 80 4F  ...*0..&.......O
+01E0: FF FF FF FF FF 9F 99                               .......
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/RemoveOps.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that when we remove the authoritative property from a context,
+ *          that it affects subsequent context operations.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main RemoveOps
+ */
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+
+public class RemoveOps extends EnvTestBase {
+
+    public static void main(String[] args) throws Exception {
+        new RemoveOps().run(args);
+    }
+
+    /*
+     * Tests that when we remove the authoritative property from a context,
+     * that it affects subsequent context operations.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        // Context.AUTHORITATIVE been set in initContext(), should not be null
+        Object val = context().removeFromEnvironment(Context.AUTHORITATIVE);
+
+        if (!"true".equals(val)) {
+            throw new RuntimeException(
+                    "Failed: unexpected return value for removeFromEnvironment: "
+                            + val);
+        }
+
+        retrieveAndVerifyAuthData();
+        retrieveNonAuthData();
+    }
+
+    private void initContext() throws NamingException {
+        // Make authoritative
+        env().put(Context.AUTHORITATIVE, "true");
+        setContext(new InitialDirContext(env()));
+    }
+
+    private void retrieveAndVerifyAuthData() throws NamingException {
+        // Ensure that auth data retrieval is OK
+        retrieveAndVerifyData(getFqdnUrl(), new String[] { "*" });
+    }
+
+    private void retrieveNonAuthData() throws NamingException {
+        try {
+            // Ensure that nonauth data retrieval succeeds
+            Attributes retAttrs = context()
+                    .getAttributes(getForeignFqdnUrl(), new String[] { "*" });
+            DNSTestUtils.debug(context().getEnvironment());
+            DNSTestUtils.debug(retAttrs);
+
+        } catch (NameNotFoundException e) {
+            throw new RuntimeException(
+                    "Failed: Expecting nonauthoritative entry found: "
+                            + getForeignFqdnUrl(), e);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/SubcontextAdd.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,50 @@
+#
+# 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 SubcontextAdd.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the SubcontextAdd application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: A4 83 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: A4 83 85 80 00 01 00 01   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/SubcontextAdd.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that when we add environment properties to a child context,
+ *          its changes do not affect the environment properties of the parent
+ *          context.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main SubcontextAdd
+ */
+
+import javax.naming.Context;
+import javax.naming.directory.InitialDirContext;
+import java.util.Hashtable;
+
+public class SubcontextAdd extends EnvTestBase {
+
+    public static void main(String[] args) throws Exception {
+        new SubcontextAdd().run(args);
+    }
+
+    /*
+     * Tests that when we add environment properties to a child context,
+     * its changes do not affect the environment properties of the parent
+     * context.
+     */
+    @Override public void runTest() throws Exception {
+        setContext(new InitialDirContext(env()));
+
+        Context child = (Context) context().lookup(getKey());
+
+        addToEnvAndVerifyOldValIsNull(child, "com.sun.jndi.dns.recursion",
+                "false");
+        addToEnvAndVerifyOldValIsNull(child, "some.irrelevant.property",
+                "somevalue");
+
+        Hashtable envParent = context().getEnvironment();
+        Hashtable envChild = child.getEnvironment();
+
+        DNSTestUtils.debug(child);
+        DNSTestUtils.debug("Parent env: " + envParent);
+        DNSTestUtils.debug("Child env: " + envChild);
+
+        verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", null);
+        verifyEnvProperty(envParent, "some.irrelevant.property", null);
+        verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envChild, "some.irrelevant.property", "somevalue");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/SubcontextRemove.dns	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,50 @@
+#
+# 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 SubcontextRemove.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the SubcontextRemove application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 75 45 00 00 00 01 00 00   00 00 00 00 05 68 6F 73  uE...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: 75 45 84 80 00 01 00 01   00 01 00 01 05 68 6F 73  uE...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/com/sun/jndi/dns/EnvTests/SubcontextRemove.java	Wed Aug 08 10:21:23 2018 +0800
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2000, 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 8208279
+ * @summary Tests that when we remove environment properties from a child
+ *          context, its changes do not affect the environment properties of
+ *          the parent context.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @run main SubcontextRemove
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+import java.util.Hashtable;
+
+public class SubcontextRemove extends EnvTestBase {
+
+    public static void main(String[] args) throws Exception {
+        new SubcontextRemove().run(args);
+    }
+
+    /*
+     * Tests that when we remove environment properties from a child
+     * context, its changes do not affect the environment properties of
+     * the parent context.
+     */
+    @Override public void runTest() throws Exception {
+        initContext();
+
+        Context child = (Context) context().lookup(getKey());
+
+        // some.irrelevant.property been set in initContext(), should not be null
+        Object val = child.removeFromEnvironment("some.irrelevant.property");
+
+        if (!"somevalue".equals(val)) {
+            throw new RuntimeException(
+                    "Failed: unexpected return value for removeFromEnvironment: "
+                            + val);
+        }
+
+        Hashtable envParent = context().getEnvironment();
+        Hashtable envChild = child.getEnvironment();
+
+        DNSTestUtils.debug(child);
+        DNSTestUtils.debug("Parent env: " + envParent);
+        DNSTestUtils.debug("Child env: " + envChild);
+
+        verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");
+        verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
+        verifyEnvProperty(envChild, "some.irrelevant.property", null);
+    }
+
+    private void initContext() throws NamingException {
+        env().put("com.sun.jndi.dns.recursion", "false");
+        env().put("some.irrelevant.property", "somevalue");
+        setContext(new InitialDirContext(env()));
+    }
+}