# HG changeset patch # User xyin # Date 1540187619 -28800 # Node ID a562c65c3c74b6bb6bec980f9aa1efeabe255315 # Parent cf3fafc740bb6df3f7f044e4ccc4976499cd24b3 8200151: Add 8 JNDI tests to com/sun/jndi/dns/ConfigTests/ Reviewed-by: vtewari, rriggs diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/ProblemList.txt --- a/test/jdk/ProblemList.txt Mon Oct 22 10:16:34 2018 +0530 +++ b/test/jdk/ProblemList.txt Mon Oct 22 13:53:39 2018 +0800 @@ -870,6 +870,8 @@ com/sun/jndi/ldap/LdapTimeoutTest.java 8151678 linux-all +com/sun/jndi/dns/ConfigTests/PortUnreachable.java 7164518 macosx-all + javax/rmi/ssl/SSLSocketParametersTest.sh 8162906 generic-all ############################################################################ diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/AuthDefault.dns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/AuthDefault.dns Mon Oct 22 13:53:39 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 AuthTest.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the AuthTest application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: E5 2C 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: FF 00 01 ... + + +# DNS Response + +0000: E5 2C 85 80 00 01 00 06 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: 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: 84 D9 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: 84 D9 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 35 06 6F 72 61 63 6C 65 nsmaster5.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 34 C0 59 C0 ...dnsmaster4.Y. +00E0: 6E 00 01 00 01 00 00 2A 30 00 04 C0 87 52 04 C0 n......*0....R.. +00F0: 6E 00 1C 00 01 00 00 2A 30 00 10 26 06 B4 00 14 n......*0..&.... +0100: 00 01 80 4F FF FF FF FF FF 9F 99 C0 A0 00 01 00 ...O............ +0110: 01 00 00 2A 30 00 04 C0 87 52 14 C0 A0 00 1C 00 ...*0....R...... +0120: 01 00 00 2A 30 00 10 26 06 B4 00 14 00 03 12 4F ...*0..&.......O +0130: FF FF FF FF FF 9F 99 C0 B9 00 01 00 01 00 00 2A ...............* +0140: 30 00 04 C0 87 52 54 C0 B9 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 46 C0 4E 00 1C 00 01 00 00 2A 30 00 10 26 .RF.N......*0..& +0180: 06 B4 00 14 00 42 40 4F FF FF FF FF FF 9F 99 C0 .....B@O........ +0190: D2 00 01 00 01 00 00 2A 30 00 04 C0 87 52 34 C0 .......*0....R4. +01A0: D2 00 1C 00 01 00 00 2A 30 00 10 26 06 B4 00 14 .......*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 ....... + + diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/AuthFalse.dns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/AuthFalse.dns Mon Oct 22 13:53:39 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 AuthTest.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the AuthTest application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 1C 7E 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: FF 00 01 ... + + +# DNS Response + +0000: 1C 7E 85 80 00 01 00 06 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: 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: E7 16 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: E7 16 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 33 06 6F 72 61 63 6C 65 nsmaster3.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 35 C0 59 C0 13 00 02 00 nsmaster5.Y..... +0080: 01 00 00 2A 30 00 0D 0A 64 6E 73 6D 61 73 74 65 ...*0...dnsmaste +0090: 72 32 C0 59 C0 13 00 02 00 01 00 00 2A 30 00 0D r2.Y........*0.. +00A0: 0A 64 6E 73 6D 61 73 74 65 72 31 C0 59 C0 13 00 .dnsmaster1.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 34 C0 59 C0 ...dnsmaster4.Y. +00E0: 6E 00 01 00 01 00 00 2A 30 00 04 C0 87 52 46 C0 n......*0....RF. +00F0: 6E 00 1C 00 01 00 00 2A 30 00 10 26 06 B4 00 14 n......*0..&.... +0100: 00 42 40 4F FF FF FF FF FF 9F 99 C0 4E 00 01 00 .B@O........N... +0110: 01 00 00 2A 30 00 04 C0 87 52 24 C0 4E 00 1C 00 ...*0....R$.N... +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 A0 00 01 00 01 00 00 2A ...............* +0140: 30 00 04 C0 87 52 04 C0 A0 00 1C 00 01 00 00 2A 0....R.........* +0150: 30 00 10 26 06 B4 00 14 00 01 80 4F FF FF FF FF 0..&.......O.... +0160: FF 9F 99 C0 B9 00 01 00 01 00 00 2A 30 00 04 C0 ...........*0... +0170: 87 52 54 C0 B9 00 1C 00 01 00 00 2A 30 00 10 26 .RT........*0..& +0180: 06 B4 00 14 00 41 40 4F FF FF FF FF FF 9F 99 C0 .....A@O........ +0190: D2 00 01 00 01 00 00 2A 30 00 04 C0 87 52 34 C0 .......*0....R4. +01A0: D2 00 1C 00 01 00 00 2A 30 00 10 26 06 B4 00 14 .......*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 14 C0 87 00 1C 00 ...*0....R...... +01D0: 01 00 00 2A 30 00 10 26 06 B4 00 14 00 03 12 4F ...*0..&.......O +01E0: FF FF FF FF FF 9F 99 ....... + + diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/AuthRecursiveBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/AuthRecursiveBase.java Mon Oct 22 13:53:39 2018 +0800 @@ -0,0 +1,115 @@ +/* + * 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.NamingException; +import javax.naming.directory.Attributes; + +/** + * Abstract test base for Config related tests, this class extends DNSTestBase. + * + * @see DNSTestBase + * @see TestBase + */ +abstract class AuthRecursiveBase extends DNSTestBase { + + private static final String KEY = "host1"; + private static final String[] MANDATORY_ATTRIBUTES = { "A", "MX", "HINFO", + "TXT", "29" }; + private static final String[] OPTIONAL_ATTRIBUTES = {}; + + private String fqdnUrl; + private String foreignFqdnUrl; + + /** + * 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 retrieveAndVerifyData, it will retrieve all of the + * attributes associated with given named object and do verification. + * + * @param name given named object + * @throws NamingException if a naming exception is encountered + */ + public void retrieveAndVerifyData(String name) throws NamingException { + Attributes retAttrs = context().getAttributes(name); + DNSTestUtils.verifySchema(retAttrs, MANDATORY_ATTRIBUTES, + OPTIONAL_ATTRIBUTES); + } + + /** + * Retrieves selected attributes associated with a named object and do + * verification. + * + * @param name given named object + * @param attrIds given ids of the attributes to retrieve + * @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); + } + + /** + * Return parsed flag from given test name. + * + * @return parsed flag from given test name + */ + public String parseFlagFromTestName() { + String name = (String) env().get("testname"); + if (name == null || name.isEmpty()) { + throw new RuntimeException("test name expecting not null/empty"); + } + + if (name.endsWith("Default")) { + return "default"; + } else if (name.endsWith("True")) { + return "true"; + } else if (name.endsWith("False")) { + return "false"; + } else { + throw new RuntimeException("Invalid test name " + name); + } + } + + public String getFqdnUrl() { + return fqdnUrl; + } + + public String getForeignFqdnUrl() { + return foreignFqdnUrl; + } +} diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/AuthTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/AuthTest.java Mon Oct 22 13:53:39 2018 +0800 @@ -0,0 +1,103 @@ +/* + * 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. + */ + +import javax.naming.Context; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.InitialDirContext; +import java.util.Hashtable; + +/* + * @test + * @bug 8200151 + * @summary Tests that we can get the attributes of DNS entries for + * authoritative data. And nonauthoritative data by default or + * java.naming.authoritative is set to false, but cannot when + * java.naming.authoritative is set to true. + * @library ../lib/ + * @modules java.base/sun.security.util + * @run main AuthTest -Dtestname=AuthDefault + * @run main AuthTest -Dtestname=AuthFalse + * @run main AuthTest -Dtestname=AuthTrue + */ + +public class AuthTest extends AuthRecursiveBase { + + public static void main(String[] args) throws Exception { + new AuthTest().run(args); + } + + /* + * Tests that we can get the attributes of DNS entries for + * authoritative data. And nonauthoritative data by default or + * java.naming.authoritative is set to false, but cannot when + * java.naming.authoritative is set to true. + */ + @Override + public void runTest() throws Exception { + String flag = parseFlagFromTestName(); + + if (flag.equalsIgnoreCase("default")) { + setContext(new InitialDirContext()); + } else { + Hashtable env = new Hashtable<>(); + DNSTestUtils.debug("set java.naming.authoritative to " + flag); + // java.naming.authoritative is set to true or false + env.put(Context.AUTHORITATIVE, flag); + setContext(new InitialDirContext(env)); + } + + retrieveAndVerifyAuthData(); + retrieveNonAuthData(Boolean.parseBoolean(flag)); + } + + private void retrieveAndVerifyAuthData() throws NamingException { + // Ensure that auth data retrieval is OK + retrieveAndVerifyData(getFqdnUrl(), new String[] { "*" }); + } + + /* + * If isAuth == true, ensure that nonauth data retrieval cannot be retrieved. + * If isAuth == false, ensure that nonauth data retrieval is OK, skip + * checking attributes for foreign; just successful operation is sufficient. + */ + private void retrieveNonAuthData(boolean isAuth) throws NamingException { + try { + Attributes retAttrs = context() + .getAttributes(getForeignFqdnUrl(), new String[] { "*" }); + DNSTestUtils.debug(retAttrs); + if (isAuth) { + throw new RuntimeException( + "Failed: Expecting nonauth entry not found " + + getForeignFqdnUrl()); + } + } catch (NameNotFoundException e) { + if (isAuth) { + System.out.println("Got expected exception: " + e); + } else { + throw e; + } + } + } +} diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/AuthTrue.dns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/AuthTrue.dns Mon Oct 22 13:53:39 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 AuthTest.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the AuthTest application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 1E 74 01 00 00 01 00 00 00 00 00 00 05 68 6F 73 .t...........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: 1E 74 85 80 00 01 00 06 00 01 00 01 05 68 6F 73 .t...........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: 8C F4 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: 8C F4 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: 25 8D 00 0E 0B 73 75 6E 77 65 62 2D 70 73 72 76 %....sunweb-psrv +0040: C0 13 C0 13 00 02 00 01 00 00 25 8D 00 14 0A 64 ..........%....d +0050: 6E 73 6D 61 73 74 65 72 33 06 6F 72 61 63 6C 65 nsmaster3.oracle +0060: C0 1F C0 13 00 02 00 01 00 00 25 8D 00 0D 0A 64 ..........%....d +0070: 6E 73 6D 61 73 74 65 72 34 C0 59 C0 13 00 02 00 nsmaster4.Y..... +0080: 01 00 00 25 8D 00 0D 0A 64 6E 73 6D 61 73 74 65 ...%....dnsmaste +0090: 72 31 C0 59 C0 13 00 02 00 01 00 00 25 8D 00 0D r1.Y........%... +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 25 8D 00 0D 0A 64 6E 73 6D 61 73 .....%....dnsmas +00C0: 74 65 72 36 C0 59 C0 13 00 02 00 01 00 00 25 8D ter6.Y........%. +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 25 8D 00 04 C0 87 52 46 C0 .......%.....RF. +00F0: D2 00 1C 00 01 00 00 25 8D 00 10 26 06 B4 00 14 .......%...&.... +0100: 00 42 40 4F FF FF FF FF FF 9F 99 C0 4E 00 01 00 .B@O........N... +0110: 01 00 00 25 8D 00 04 C0 87 52 24 C0 4E 00 1C 00 ...%.....R$.N... +0120: 01 00 00 25 8D 00 10 26 06 B4 00 14 00 80 40 4F ...%...&......@O +0130: FF FF FF FF FF 9F 99 C0 87 00 01 00 01 00 00 25 ...............% +0140: 8D 00 04 C0 87 52 04 C0 87 00 1C 00 01 00 00 25 .....R.........% +0150: 8D 00 10 26 06 B4 00 14 00 01 80 4F FF FF FF FF ...&.......O.... +0160: FF 9F 99 C0 B9 00 01 00 01 00 00 25 8D 00 04 C0 ...........%.... +0170: 87 52 54 C0 B9 00 1C 00 01 00 00 25 8D 00 10 26 .RT........%...& +0180: 06 B4 00 14 00 41 40 4F FF FF FF FF FF 9F 99 C0 .....A@O........ +0190: 6E 00 01 00 01 00 00 25 8D 00 04 C0 87 52 34 C0 n......%.....R4. +01A0: 6E 00 1C 00 01 00 00 25 8D 00 10 26 06 B4 00 14 n......%...&.... +01B0: 00 81 40 4F FF FF FF FF FF 9F 99 C0 A0 00 01 00 ..@O............ +01C0: 01 00 00 25 8D 00 04 C0 87 52 14 C0 A0 00 1C 00 ...%.....R...... +01D0: 01 00 00 25 8D 00 10 26 06 B4 00 14 00 03 12 4F ...%...&.......O +01E0: FF FF FF FF FF 9F 99 ....... + + diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/PortUnreachable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/PortUnreachable.java Mon Oct 22 13:53:39 2018 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + */ + +import javax.naming.CommunicationException; +import javax.naming.Context; +import javax.naming.directory.InitialDirContext; + +/* + * @test + * @bug 8200151 + * @summary Tests that when a DNS server is unreachable and an ICMP Destination + * Unreachable packet is received, we fail quickly and don't wait for + * the full timeout interval. This could be caused, for example, by a + * dead DNS server or a flakey router. + * @library ../lib/ + * @modules java.base/sun.security.util + * @run main PortUnreachable + */ + +public class PortUnreachable extends DNSTestBase { + + // Port 25 is the SMTP port, used here to simulate a dead DNS server. + private static final int PORT = 25; + + // Threshold in ms for elapsed time of request failed. Normally, it should + // be very quick, but consider to different platform and test machine + // performance, here we define 1000 ms as threshold which acceptable for + // this test. + private static final int THRESHOLD = 1000; + + private long startTime; + + public PortUnreachable() { + setLocalServer(false); + } + + public static void main(String[] args) throws Exception { + new PortUnreachable().run(args); + } + + /* + * Tests that when a DNS server is unreachable and an ICMP Destination + * Unreachable packet is received, we fail quickly and don't wait for + * the full timeout interval. + */ + @Override + public void runTest() throws Exception { + String deadServerUrl = "dns://localhost:" + PORT; + env().put(Context.PROVIDER_URL, deadServerUrl); + setContext(new InitialDirContext(env())); + + // Any request should fail quickly. + startTime = System.currentTimeMillis(); + context().getAttributes(""); + + // You're running a DNS server on your SMTP port? + throw new RuntimeException( + "Failed: getAttributes succeeded unexpectedly"); + } + + @Override + public boolean handleException(Exception e) { + if (e instanceof CommunicationException) { + long elapsedTime = System.currentTimeMillis() - startTime; + + Throwable cause = ((CommunicationException) e).getRootCause(); + if (!(cause instanceof java.net.PortUnreachableException)) { + DNSTestUtils.debug("Bug 7164518 can cause this failure on mac"); + return false; + } + + DNSTestUtils.debug("Elapsed (ms): " + elapsedTime); + + // Check that elapsed time is less than defined threshold. + if (elapsedTime < THRESHOLD) { + return true; + } + + throw new RuntimeException("Failed: call took " + elapsedTime + + " ms, expected less than " + THRESHOLD + " ms"); + } + + return super.handleException(e); + } +} diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveDefault.dns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveDefault.dns Mon Oct 22 13:53:39 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 RecursiveTest.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the RecursiveTest application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: A9 3C 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: FF 00 FF ... + + +# DNS Response + +0000: A9 3C 85 80 00 01 00 06 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: FF 00 FF 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: 87 6D 01 00 00 01 00 00 00 00 00 00 06 73 75 6E .m...........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 FF COM..... + + +# DNS Response + +0000: 87 6D 81 80 00 01 00 01 00 06 00 0C 06 73 75 6E .m...........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 FF C0 0C 00 05 00 01 00 00 COM............. +0030: 1C 50 00 0E 0B 73 75 6E 77 65 62 2D 70 73 72 76 .P...sunweb-psrv +0040: C0 13 C0 13 00 02 00 01 00 00 1C 50 00 14 0A 64 ...........P...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 1C 50 00 0D 0A 64 ...........P...d +0070: 6E 73 6D 61 73 74 65 72 34 C0 59 C0 13 00 02 00 nsmaster4.Y..... +0080: 01 00 00 1C 50 00 0D 0A 64 6E 73 6D 61 73 74 65 ....P...dnsmaste +0090: 72 35 C0 59 C0 13 00 02 00 01 00 00 1C 50 00 0D r5.Y.........P.. +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 1C 50 00 0D 0A 64 6E 73 6D 61 73 ......P...dnsmas +00C0: 74 65 72 31 C0 59 C0 13 00 02 00 01 00 00 1C 50 ter1.Y.........P +00D0: 00 0D 0A 64 6E 73 6D 61 73 74 65 72 36 C0 59 C0 ...dnsmaster6.Y. +00E0: B9 00 01 00 01 00 00 1C 50 00 04 C0 87 52 04 C0 ........P....R.. +00F0: B9 00 1C 00 01 00 00 1C 50 00 10 26 06 B4 00 14 ........P..&.... +0100: 00 01 80 4F FF FF FF FF FF 9F 99 C0 4E 00 01 00 ...O........N... +0110: 01 00 00 1C 50 00 04 C0 87 52 14 C0 4E 00 1C 00 ....P....R..N... +0120: 01 00 00 1C 50 00 10 26 06 B4 00 14 00 03 12 4F ....P..&.......O +0130: FF FF FF FF FF 9F 99 C0 D2 00 01 00 01 00 00 1C ................ +0140: 50 00 04 C0 87 52 54 C0 D2 00 1C 00 01 00 00 1C P....RT......... +0150: 50 00 10 26 06 B4 00 14 00 41 40 4F FF FF FF FF P..&.....A@O.... +0160: FF 9F 99 C0 87 00 01 00 01 00 00 1C 50 00 04 C0 ............P... +0170: 87 52 46 C0 87 00 1C 00 01 00 00 1C 50 00 10 26 .RF.........P..& +0180: 06 B4 00 14 00 42 40 4F FF FF FF FF FF 9F 99 C0 .....B@O........ +0190: 6E 00 01 00 01 00 00 1C 50 00 04 C0 87 52 34 C0 n.......P....R4. +01A0: 6E 00 1C 00 01 00 00 1C 50 00 10 26 06 B4 00 14 n.......P..&.... +01B0: 00 81 40 4F FF FF FF FF FF 9F 99 C0 A0 00 01 00 ..@O............ +01C0: 01 00 00 1C 50 00 04 C0 87 52 24 C0 A0 00 1C 00 ....P....R$..... +01D0: 01 00 00 1C 50 00 10 26 06 B4 00 14 00 80 40 4F ....P..&......@O +01E0: FF FF FF FF FF 9F 99 ....... + + diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveFalse.dns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveFalse.dns Mon Oct 22 13:53:39 2018 +0800 @@ -0,0 +1,76 @@ +# +# 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 RecursiveTest.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the RecursiveTest application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 55 B1 00 00 00 01 00 00 00 00 00 00 05 68 6F 73 U............hos +0010: 74 31 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 t1.domain1.com.. +0020: FF 00 FF ... + + +# DNS Response + +0000: 55 B1 84 80 00 01 00 06 00 01 00 01 05 68 6F 73 U............hos +0010: 74 31 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 t1.domain1.com.. +0020: FF 00 FF 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: 97 49 00 00 00 01 00 00 00 00 00 00 06 73 75 6E .I...........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 FF COM..... + + +# DNS Response + +0000: 97 49 80 80 00 01 00 00 00 03 00 00 06 73 75 6E .I...........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 FF 00 00 02 00 01 05 F5 E0 COM............. +0030: FF 00 0E 07 65 6E 67 64 6E 73 33 03 45 6E 67 C0 ....engdns3.Eng. +0040: 1B 00 00 02 00 01 05 F5 E0 FF 00 07 04 64 6E 73 .............dns +0050: 31 C0 3B 00 00 02 00 01 05 F5 E0 FF 00 0A 07 65 1.;............e +0060: 6E 67 64 6E 73 32 C0 3B ngdns2.; + + diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveTest.java Mon Oct 22 13:53:39 2018 +0800 @@ -0,0 +1,96 @@ +/* + * 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. + */ + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.InitialDirContext; +import java.util.Hashtable; + +/* + * @test + * @bug 8200151 + * @summary Tests that we can get the attributes of DNS entries of + * nonrecursive data. And recursive data by default or when + * com.sun.jndi.dns.recursion is set to true, but not when + * com.sun.jndi.dns.recursion is set to false. + * @library ../lib/ + * @modules java.base/sun.security.util + * @run main RecursiveTest -Dtestname=RecursiveDefault + * @run main RecursiveTest -Dtestname=RecursiveFalse + * @run main RecursiveTest -Dtestname=RecursiveTrue + */ + +public class RecursiveTest extends AuthRecursiveBase { + + public static void main(String[] args) throws Exception { + new RecursiveTest().run(args); + } + + /* + * Tests that we can get the attributes of DNS entries of + * nonrecursive data. And recursive data by default or when + * com.sun.jndi.dns.recursion is set to true, but not when + * com.sun.jndi.dns.recursion is set to false. + */ + @Override + public void runTest() throws Exception { + String flag = parseFlagFromTestName(); + + if (flag.equalsIgnoreCase("default")) { + setContext(new InitialDirContext()); + } else { + Hashtable env = new Hashtable<>(); + DNSTestUtils.debug("set com.sun.jndi.dns.recursion to " + flag); + // com.sun.jndi.dns.recursion is set to true or false + env.put("com.sun.jndi.dns.recursion", flag); + setContext(new InitialDirContext(env)); + } + + retrieveAndVerifyNonRecursiveData(); + retrieveRecursiveData( + flag.equalsIgnoreCase("default") || Boolean.parseBoolean(flag)); + } + + private void retrieveAndVerifyNonRecursiveData() throws NamingException { + // Ensure that nonrecursive data retrieval is OK + retrieveAndVerifyData(getFqdnUrl()); + } + + /* + * If isRecur == true, ensure that recursive data retrieval is OK. + * If isRecur == false, ensure that recursive data retrieval fails. + */ + private void retrieveRecursiveData(boolean isRecur) throws NamingException { + Attributes retAttrs = context().getAttributes(getForeignFqdnUrl()); + if (isRecur) { + DNSTestUtils.verifySchema(retAttrs, new String[] { "CNAME" }, + new String[] {}); + } else { + DNSTestUtils.debug(retAttrs); + if (retAttrs.size() > 0) { + throw new RuntimeException("Expecting recursive data not found " + + getForeignFqdnUrl()); + } + } + } +} diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveTrue.dns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveTrue.dns Mon Oct 22 13:53:39 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 RecursiveTest.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the RecursiveTest application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: EA B1 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: FF 00 FF ... + + +# DNS Response + +0000: EA B1 85 80 00 01 00 06 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: FF 00 FF 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: 07 E5 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 FF COM..... + + +# DNS Response + +0000: 07 E5 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 FF C0 0C 00 05 00 01 00 00 COM............. +0030: 15 7B 00 0E 0B 73 75 6E 77 65 62 2D 70 73 72 76 .....sunweb-psrv +0040: C0 13 C0 13 00 02 00 01 00 00 15 7B 00 14 0A 64 ...............d +0050: 6E 73 6D 61 73 74 65 72 31 06 6F 72 61 63 6C 65 nsmaster1.oracle +0060: C0 1F C0 13 00 02 00 01 00 00 15 7B 00 0D 0A 64 ...............d +0070: 6E 73 6D 61 73 74 65 72 33 C0 59 C0 13 00 02 00 nsmaster3.Y..... +0080: 01 00 00 15 7B 00 0D 0A 64 6E 73 6D 61 73 74 65 ........dnsmaste +0090: 72 34 C0 59 C0 13 00 02 00 01 00 00 15 7B 00 0D r4.Y............ +00A0: 0A 64 6E 73 6D 61 73 74 65 72 35 C0 59 C0 13 00 .dnsmaster5.Y... +00B0: 02 00 01 00 00 15 7B 00 0D 0A 64 6E 73 6D 61 73 ..........dnsmas +00C0: 74 65 72 36 C0 59 C0 13 00 02 00 01 00 00 15 7B ter6.Y.......... +00D0: 00 0D 0A 64 6E 73 6D 61 73 74 65 72 32 C0 59 C0 ...dnsmaster2.Y. +00E0: 4E 00 01 00 01 00 00 15 7B 00 04 C0 87 52 04 C0 N............R.. +00F0: 4E 00 1C 00 01 00 00 15 7B 00 10 26 06 B4 00 14 N..........&.... +0100: 00 01 80 4F FF FF FF FF FF 9F 99 C0 D2 00 01 00 ...O............ +0110: 01 00 00 15 7B 00 04 C0 87 52 14 C0 D2 00 1C 00 .........R...... +0120: 01 00 00 15 7B 00 10 26 06 B4 00 14 00 03 12 4F .......&.......O +0130: FF FF FF FF FF 9F 99 C0 B9 00 01 00 01 00 00 15 ................ +0140: 7B 00 04 C0 87 52 54 C0 B9 00 1C 00 01 00 00 15 .....RT......... +0150: 7B 00 10 26 06 B4 00 14 00 41 40 4F FF FF FF FF ...&.....A@O.... +0160: FF 9F 99 C0 A0 00 01 00 01 00 00 15 7B 00 04 C0 ................ +0170: 87 52 46 C0 A0 00 1C 00 01 00 00 15 7B 00 10 26 .RF............& +0180: 06 B4 00 14 00 42 40 4F FF FF FF FF FF 9F 99 C0 .....B@O........ +0190: 87 00 01 00 01 00 00 15 7B 00 04 C0 87 52 34 C0 .............R4. +01A0: 87 00 1C 00 01 00 00 15 7B 00 10 26 06 B4 00 14 ...........&.... +01B0: 00 81 40 4F FF FF FF FF FF 9F 99 C0 6E 00 01 00 ..@O........n... +01C0: 01 00 00 15 7B 00 04 C0 87 52 24 C0 6E 00 1C 00 .........R$.n... +01D0: 01 00 00 15 7B 00 10 26 06 B4 00 14 00 80 40 4F .......&......@O +01E0: FF FF FF FF FF 9F 99 ....... + + diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/ConfigTests/Timeout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/com/sun/jndi/dns/ConfigTests/Timeout.java Mon Oct 22 13:53:39 2018 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + */ + +import javax.naming.CommunicationException; +import javax.naming.Context; +import javax.naming.directory.InitialDirContext; +import java.net.SocketTimeoutException; +import java.time.Duration; +import java.time.Instant; + +/* + * @test + * @bug 8200151 + * @summary Tests that we can set the initial UDP timeout interval and the + * number of retries. + * @library ../lib/ + * @modules java.base/sun.security.util + * @run main Timeout + */ + +public class Timeout extends DNSTestBase { + // Host 10.0.0.0 is a bit bucket, used here to simulate a DNS server that + // doesn't respond. 10.0.0.0 server shouldn't be reachable. + // Ping to this address should not give any reply + private static final String HOST = "10.0.0.0"; + // Port 9 is a bit bucket, used here to simulate a DNS server that + // doesn't respond. + private static final int PORT = 9; + // initial timeout = 1/4 sec + private static final int TIMEOUT = 250; + // try 5 times per server + private static final int RETRIES = 5; + + private Instant startTime; + + public Timeout() { + setLocalServer(false); + } + + public static void main(String[] args) throws Exception { + new Timeout().run(args); + } + + /* + * Tests that we can set the initial UDP timeout interval and the + * number of retries. + */ + @Override + public void runTest() throws Exception { + String allQuietUrl = "dns://" + HOST + ":" + PORT; + env().put(Context.PROVIDER_URL, allQuietUrl); + env().put("com.sun.jndi.dns.timeout.initial", String.valueOf(TIMEOUT)); + env().put("com.sun.jndi.dns.timeout.retries", String.valueOf(RETRIES)); + setContext(new InitialDirContext(env())); + + // Any request should fail after timeouts have expired. + startTime = Instant.now(); + context().getAttributes(""); + + throw new RuntimeException( + "Failed: getAttributes succeeded unexpectedly"); + } + + @Override + public boolean handleException(Exception e) { + if (e instanceof CommunicationException) { + Duration elapsedTime = Duration.between(startTime, Instant.now()); + if (!(((CommunicationException) e) + .getRootCause() instanceof SocketTimeoutException)) { + return false; + } + + Duration expectedTime = Duration.ofMillis(TIMEOUT) + .multipliedBy((1 << RETRIES) - 1); + DNSTestUtils.debug("Elapsed (ms): " + elapsedTime.toMillis()); + DNSTestUtils.debug("Expected (ms): " + expectedTime.toMillis()); + + // Check that elapsed time is as long as expected, and + // not more than 50% greater. + if (elapsedTime.compareTo(expectedTime) >= 0 && + elapsedTime.multipliedBy(2) + .compareTo(expectedTime.multipliedBy(3)) <= 0) { + System.out.println("elapsed time is as long as expected."); + return true; + } + throw new RuntimeException( + "Failed: timeout in " + elapsedTime.toMillis() + + " ms, expected" + expectedTime.toMillis() + "ms"); + } + + return super.handleException(e); + } +} diff -r cf3fafc740bb -r a562c65c3c74 test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java --- a/test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java Mon Oct 22 10:16:34 2018 +0530 +++ b/test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java Mon Oct 22 13:53:39 2018 +0800 @@ -119,6 +119,12 @@ debug = Boolean.valueOf(System.getProperty("debug", "true")); + // override testname here if it's been specified + String newTestName = (String) env.get("testname"); + if (newTestName != null && !newTestName.isEmpty()) { + testname = newTestName; + } + if (env.get("DNS_SERVER") != null) { String port = (String) env.get("DNS_PORT"); String portSuffix = (port == null) ? "" : ":" + port;