--- old/test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java 2018-07-12 14:53:08.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAny.java 2018-07-12 14:53:08.000000000 +0800 @@ -28,54 +28,33 @@ * qualifiers. * @modules java.base/sun.security.util * @library ../lib/ - * @build DNSTestUtils DNSServer DNSTracer * @run main GetAny */ import javax.naming.directory.Attributes; -import javax.naming.directory.DirContext; -import javax.naming.directory.InitialDirContext; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.util.Hashtable; -public class GetAny { - private static final String KEY = "host1"; +public class GetAny extends GetAttrsBase { - private static final String[] MANDATORY = { "A", "MX", "HINFO", "TXT", "29" - // "LOC" - }; - - private static final String[] OPTIONAL = {}; - - public static void main(String argv[]) throws Exception { - // Create socket on localhost only to avoid possible noise packet - DatagramSocket socket = new DatagramSocket(0, - InetAddress.getLoopbackAddress()); - - // initialize test - Hashtable env; - - env = DNSTestUtils.initEnv(socket, GetAny.class.getName(), argv); - - DirContext ctx = null; + public static void main(String[] args) throws Exception { + new GetAny().run(args); + } - try { - // connect to server - ctx = new InitialDirContext(env); + @Override public Attributes getAttributes() { + return null; + } - // Any type from IN class - Attributes retAttrs = ctx.getAttributes(KEY, new String[] { "*" }); - DNSTestUtils.verifySchema(retAttrs, MANDATORY, OPTIONAL); + @Override public void runTest() throws Exception { + initContext(); - retAttrs = ctx.getAttributes(KEY, new String[] { "* *" }); - DNSTestUtils.verifySchema(retAttrs, MANDATORY, OPTIONAL); + // Any type from IN class + Attributes retAttrs = context() + .getAttributes(getKey(), new String[] { "*" }); + verifyAttributes(retAttrs); - retAttrs = ctx.getAttributes(KEY, new String[] { "IN *" }); - DNSTestUtils.verifySchema(retAttrs, MANDATORY, OPTIONAL); + retAttrs = context().getAttributes(getKey(), new String[] { "* *" }); + verifyAttributes(retAttrs); - } finally { - DNSTestUtils.cleanup(ctx); - } + retAttrs = context().getAttributes(getKey(), new String[] { "IN *" }); + verifyAttributes(retAttrs); } } --- old/test/jdk/com/sun/jndi/dns/lib/DNSServer.java 2018-07-12 14:53:10.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/lib/DNSServer.java 2018-07-12 14:53:09.000000000 +0800 @@ -26,6 +26,8 @@ import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.SocketException; import java.nio.ByteBuffer; import java.nio.file.Paths; import java.util.ArrayList; @@ -49,7 +51,7 @@ * Typically, DNS protocol exchange is generated by DNSTracer who captures * communication messages between DNS application program and real DNS server */ -public class DNSServer implements Runnable { +public class DNSServer extends Thread implements Server { public class Pair { private F first; @@ -87,19 +89,21 @@ private boolean loop; private final List> cache = new ArrayList<>(); private ByteBuffer reqBuffer = ByteBuffer.allocate(DNS_PACKET_SIZE); + private volatile boolean isRunning; - public DNSServer(DatagramSocket socket, String filename) { - this(socket, filename, false); + public DNSServer(String filename) throws SocketException { + this(filename, false); } - public DNSServer(DatagramSocket socket, String filename, boolean loop) { - this.socket = socket; + public DNSServer(String filename, boolean loop) throws SocketException { + this.socket = new DatagramSocket(0, InetAddress.getLoopbackAddress()); this.filename = filename; this.loop = loop; } public void run() { try { + isRunning = true; System.out.println( "DNSServer: Loading DNS cache data from : " + filename); loadCaptureFile(filename); @@ -112,30 +116,25 @@ int playbackIndex = 0; while (playbackIndex < cache.size()) { - DatagramPacket reqPacket = new DatagramPacket(reqBuffer.array(), - reqBuffer.array().length); - socket.receive(reqPacket); - - System.out.println( - "DNSServer: received query message from " + reqPacket - .getSocketAddress()); + DatagramPacket reqPacket = receiveQuery(); if (!verifyRequestMsg(reqPacket, playbackIndex)) { - throw new RuntimeException( - "DNSServer: Error: Failed to verify DNS request. " - + "Not identical request message : \n" - + encoder.encodeBuffer( - Arrays.copyOf(reqPacket.getData(), - reqPacket.getLength()))); + if (playbackIndex > 0 && verifyRequestMsg(reqPacket, + playbackIndex - 1)) { + System.out.println( + "DNSServer: received retry query, resend"); + playbackIndex--; + } else { + throw new RuntimeException( + "DNSServer: Error: Failed to verify DNS request. " + + "Not identical request message : \n" + + encoder.encodeBuffer( + Arrays.copyOf(reqPacket.getData(), + reqPacket.getLength()))); + } } - byte[] payload = generateResponsePayload(reqPacket, - playbackIndex); - socket.send(new DatagramPacket(payload, payload.length, - reqPacket.getSocketAddress())); - System.out.println( - "DNSServer: send response message to " + reqPacket - .getSocketAddress()); + sendResponse(reqPacket, playbackIndex); playbackIndex++; if (loop && playbackIndex >= cache.size()) { @@ -145,11 +144,54 @@ System.out.println( "DNSServer: Done for all cached messages playback"); + + System.out.println( + "DNSServer: Still listening for possible retry query"); + while (true) { + DatagramPacket reqPacket = receiveQuery(); + + // here we only handle the retry query for last one + if (!verifyRequestMsg(reqPacket, playbackIndex - 1)) { + throw new RuntimeException( + "DNSServer: Error: Failed to verify DNS request. " + + "Not identical request message : \n" + + encoder.encodeBuffer( + Arrays.copyOf(reqPacket.getData(), + reqPacket.getLength()))); + } + + sendResponse(reqPacket, playbackIndex - 1); + } } catch (Exception e) { - System.err.println("DNSServer: Error: " + e); + if (isRunning) { + System.err.println("DNSServer: Error: " + e); + e.printStackTrace(); + } else { + System.out.println("DNSServer: Exit"); + } } } + private DatagramPacket receiveQuery() throws IOException { + DatagramPacket reqPacket = new DatagramPacket(reqBuffer.array(), + reqBuffer.array().length); + socket.receive(reqPacket); + + System.out.println("DNSServer: received query message from " + reqPacket + .getSocketAddress()); + + return reqPacket; + } + + private void sendResponse(DatagramPacket reqPacket, int playbackIndex) + throws IOException { + byte[] payload = generateResponsePayload(reqPacket, playbackIndex); + socket.send(new DatagramPacket(payload, payload.length, + reqPacket.getSocketAddress())); + System.out.println("DNSServer: send response message to " + reqPacket + .getSocketAddress()); + } + /* * Load a capture file containing an DNS protocol exchange in the * hexadecimal dump format emitted by sun.misc.HexDumpEncoder: @@ -299,4 +341,23 @@ } return -1; } + + @Override public void stopServer() { + isRunning = false; + if (socket != null) { + try { + socket.close(); + } catch (Exception e) { + // ignore + } + } + } + + @Override public int getPort() { + if (socket != null) { + return socket.getLocalPort(); + } else { + return -1; + } + } } --- old/test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java 2018-07-12 14:53:11.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/lib/DNSTestUtils.java 2018-07-12 14:53:10.000000000 +0800 @@ -24,6 +24,7 @@ import javax.naming.Context; import javax.naming.NamingException; import javax.naming.directory.Attributes; +import java.io.Closeable; import java.io.PrintStream; import java.net.DatagramSocket; import java.nio.file.Files; @@ -73,7 +74,7 @@ /* * Process command line arguments and init env */ - public static Hashtable initEnv(DatagramSocket socket, + public static Hashtable initEnv(boolean localServer, String testname, String[] args) { Hashtable env = new Hashtable<>(); @@ -111,23 +112,23 @@ env.put(Context.PROVIDER_URL, url + "/" + env.get("DNS_DOMAIN")); } - Runnable inst = null; + Thread inst = null; if (traceEnable) { - inst = createDNSTracer(socket, testname, env); + inst = createDNSTracer(testname, env); } else { - if (socket != null) { - inst = createDNSServer(socket, testname, loopPlayback); + if (localServer) { + inst = createDNSServer(testname, loopPlayback); } else { // for tests which run against remote server // or no server required - debug("Skip local DNS Server creation " - + "since DatagramSocket is null"); + debug("Skip local DNS Server creation "); } } if (inst != null) { - env.put(TEST_DNS_SERVER_THREAD, startServer(inst)); - String url = "dns://localhost:" + socket.getLocalPort(); + env.put(TEST_DNS_SERVER_THREAD, inst); + inst.start(); + String url = "dns://localhost:" + ((Server) inst).getPort(); env.put(TEST_DNS_ROOT_URL, url); env.put(Context.PROVIDER_URL, url + "/" + env.get("DNS_DOMAIN")); @@ -149,6 +150,19 @@ } } + /* + * Clean up given closable resource + */ + public static void cleanupClosableRes(Closeable res) { + if (res != null) { + try { + res.close(); + } catch (Exception e) { + // ignore + } + } + } + private static void extractProperty(String propString, Hashtable env) { int index; @@ -162,17 +176,11 @@ } } - public static DNSTracer createDNSTracer(DatagramSocket socket, - String testname, Hashtable env) { - if (socket == null) { - throw new RuntimeException("Error: failed to create DNSTracer " - + "since DatagramSocket is null"); - } - + public static DNSTracer createDNSTracer(String testname, + Hashtable env) { try { PrintStream outStream = new PrintStream(getCaptureFile(testname)); - return new DNSTracer(socket, outStream, - (String) env.get("DNS_SERVER"), + return new DNSTracer(outStream, (String) env.get("DNS_SERVER"), Integer.parseInt((String) env.get("DNS_PORT"))); } catch (Exception e) { throw new RuntimeException( @@ -180,16 +188,16 @@ } } - public static DNSServer createDNSServer(DatagramSocket socket, - String testname, boolean loop) { - if (socket == null) { - throw new RuntimeException("Error: failed to create DNSServer " - + "since DatagramSocket is null"); - } - + public static DNSServer createDNSServer(String testname, boolean loop) { String path = getCaptureFile(testname); if (Files.exists(Paths.get(path))) { - return new DNSServer(socket, path, loop); + try { + return new DNSServer(path, loop); + } catch (Exception e) { + throw new RuntimeException( + "Error: failed to create DNSServer : " + e.getMessage(), + e); + } } else { throw new RuntimeException( "Error: failed to create DNSServer, not found dns " @@ -197,12 +205,6 @@ } } - public static Thread startServer(Runnable runnable) { - Thread thread = new Thread(runnable); - thread.start(); - return thread; - } - public static String getCaptureFile(String testname) { return Paths.get(System.getProperty("test.src")) .resolve(testname + ".dns").toString(); @@ -243,4 +245,21 @@ throw new RuntimeException("Check schema failed."); } } + + public static String getRootUrl(Hashtable env) { + return (String) env.get(TEST_DNS_ROOT_URL); + } + + /* + * Assemble a fully-qualified domain name from the base component and the + * domain name. + */ + public static String buildFqdn(String base, Hashtable env, + boolean primary) { + String domain = (String) (primary ? + env.get("DNS_DOMAIN") : + env.get("FOREIGN_DOMAIN")); + + return base + "." + domain; + } } --- old/test/jdk/com/sun/jndi/dns/lib/DNSTracer.java 2018-07-12 14:53:12.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/lib/DNSTracer.java 2018-07-12 14:53:12.000000000 +0800 @@ -26,6 +26,7 @@ import java.io.PrintStream; import java.net.DatagramPacket; import java.net.DatagramSocket; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.SocketException; @@ -46,7 +47,7 @@ * * Typically, the capture file data will be used by DNSServer for playback */ -public class DNSTracer implements Runnable { +public class DNSTracer extends Thread implements Server { public static final int DNS_DEFAULT_PORT = 53; public static final int DNS_PACKET_SIZE = 512; static HexDumpEncoder encoder = new HexDumpEncoder(); @@ -56,28 +57,30 @@ private ByteBuffer reqBuffer = ByteBuffer.allocate(DNS_PACKET_SIZE); private ByteBuffer resBuffer = ByteBuffer.allocate(DNS_PACKET_SIZE); private PrintStream out = null; + private volatile boolean isRunning; - public DNSTracer(DatagramSocket socket, String dnsHostname) { - this(socket, dnsHostname, DNS_DEFAULT_PORT); + public DNSTracer(String dnsHostname) throws SocketException { + this(dnsHostname, DNS_DEFAULT_PORT); } - public DNSTracer(DatagramSocket socket, PrintStream outStream, - String dnsHostname) { - this(socket, outStream, dnsHostname, DNS_DEFAULT_PORT); + public DNSTracer(PrintStream outStream, String dnsHostname) + throws SocketException { + this(outStream, dnsHostname, DNS_DEFAULT_PORT); } - public DNSTracer(DatagramSocket socket, String dnsHostname, int dnsPort) { - this(socket, System.out, dnsHostname, dnsPort); + public DNSTracer(String dnsHostname, int dnsPort) throws SocketException { + this(System.out, dnsHostname, dnsPort); } - public DNSTracer(DatagramSocket socket, PrintStream outStream, - String dnsHostname, int dnsPort) { - inSocket = socket; + public DNSTracer(PrintStream outStream, String dnsHostname, int dnsPort) + throws SocketException { + inSocket = new DatagramSocket(0, InetAddress.getLoopbackAddress()); out = outStream; dnsServerAddress = new InetSocketAddress(dnsHostname, dnsPort); } public void run() { + isRunning = true; System.out.println( "DNSTracer: listening on port " + inSocket.getLocalPort()); @@ -116,7 +119,7 @@ resPacket.getLength(), reqPacket.getSocketAddress())); } } catch (SocketException se) { - if (inSocket.isClosed()) { + if (!isRunning) { out.flush(); System.out.println("DNSTracer: Exit"); } else { @@ -127,4 +130,22 @@ } } + @Override public void stopServer() { + isRunning = false; + if (inSocket != null) { + try { + inSocket.close(); + } catch (Exception e) { + // ignore + } + } + } + + @Override public int getPort() { + if (inSocket != null) { + return inSocket.getLocalPort(); + } else { + return -1; + } + } } --- /dev/null 2018-07-12 14:53:13.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrs.dns 2018-07-12 14:53:13.000000000 +0800 @@ -0,0 +1,58 @@ +# +# 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 GetAttrs.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetAttrs application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 2F EA 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: 2F EA 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 ......... + + --- /dev/null 2018-07-12 14:53:14.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrs.java 2018-07-12 14:53:14.000000000 +0800 @@ -0,0 +1,55 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry. + * Use getAttributes form that has no attrIds parameter. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetAttrs + */ + +import javax.naming.directory.Attributes; + +public class GetAttrs extends GetAttrsBase { + + public static void main(String[] args) throws Exception { + new GetAttrs().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + + /* + * Tests that we can get the attributes of a DNS entry. + * Use getAttributes form that has no attrIds parameter. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKey()); + } +} --- /dev/null 2018-07-12 14:53:15.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsBase.java 2018-07-12 14:53:15.000000000 +0800 @@ -0,0 +1,72 @@ +/* + * 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.directory.Attributes; +import javax.naming.directory.InitialDirContext; + +public abstract class GetAttrsBase extends DNSTestBase { + private String key; + private String[] mandatoryAttrs; + + { + // set default test data + setKey("host1"); + setMandatoryAttrs( + new String[] { "A", "MX", "HINFO", "TXT", "29" // "LOC" + }); + } + + private static final String[] OPTIONAL_ATTRIBUTES = {}; + + public void initContext() throws Exception { + setContext(new InitialDirContext(env())); + } + + public abstract Attributes getAttributes() throws Exception; + + public void verifyAttributes(Attributes retAttrs) throws Exception { + if (retAttrs != null) { + DNSTestUtils.verifySchema(retAttrs, mandatoryAttrs, + OPTIONAL_ATTRIBUTES); + } else { + throw new RuntimeException( + "Failed, Attributes which required to verify was null unexpectedly"); + } + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String[] getMandatoryAttrs() { + return mandatoryAttrs; + } + + public void setMandatoryAttrs(String[] mandatoryAttrs) { + this.mandatoryAttrs = mandatoryAttrs; + } +} --- /dev/null 2018-07-12 14:53:16.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsEmptyAttrIds.dns 2018-07-12 14:53:16.000000000 +0800 @@ -0,0 +1,58 @@ +# +# 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 GetAttrsEmptyAttrIds.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetAttrsEmptyAttrIds application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: BC 12 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: BC 12 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 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 ......... + + --- /dev/null 2018-07-12 14:53:17.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsEmptyAttrIds.java 2018-07-12 14:53:17.000000000 +0800 @@ -0,0 +1,59 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry. + * Specify that no attributes are to be returned. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetAttrsEmptyAttrIds + */ + +import javax.naming.directory.Attributes; + +public class GetAttrsEmptyAttrIds extends GetAttrsBase { + { + // set new test data instead of default value + setMandatoryAttrs(new String[] {}); + } + + public static void main(String[] args) throws Exception { + new GetAttrsEmptyAttrIds().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + + /* + * Tests that we can get the attributes of a DNS entry. + * Specify that no attributes are to be returned. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKey(), new String[] {}); + } +} --- /dev/null 2018-07-12 14:53:18.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNonExistentAttrIds.dns 2018-07-12 14:53:18.000000000 +0800 @@ -0,0 +1,58 @@ +# +# 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 GetAttrsNonExistentAttrIds.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetAttrsNonExistentAttrIds application program against +# a real DNS server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: FC 9A 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: FC 9A 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 ......... + + --- /dev/null 2018-07-12 14:53:19.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNonExistentAttrIds.java 2018-07-12 14:53:19.000000000 +0800 @@ -0,0 +1,62 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry. + * Supply at least one nonexistent attribute name in attrIds + * (should be ignored). + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetAttrsNonExistentAttrIds + */ + +import javax.naming.directory.Attributes; + +public class GetAttrsNonExistentAttrIds extends GetAttrsBase { + + public static void main(String[] args) throws Exception { + new GetAttrsNonExistentAttrIds().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + + /* + * Tests that we can get the attributes of a DNS entry. + * Supply at least one nonexistent attribute name in attrIds + * (should be ignored). + */ + @Override public Attributes getAttributes() throws Exception { + String[] attrIds = new String[getMandatoryAttrs().length + 1]; + attrIds[0] = "SOA"; + System.arraycopy(getMandatoryAttrs(), 0, attrIds, 1, + getMandatoryAttrs().length); + + return context().getAttributes(getKey(), attrIds); + } +} --- /dev/null 2018-07-12 14:53:20.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.dns 2018-07-12 14:53:20.000000000 +0800 @@ -0,0 +1,49 @@ +# +# 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 GetAttrsNotFound.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetAttrsNotFound application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 56 B1 01 00 00 01 00 00 00 00 00 00 08 6E 6F 74 V............not +0010: 66 6F 75 6E 64 07 64 6F 6D 61 69 6E 31 03 63 6F found.domain1.co +0020: 6D 00 00 FF 00 FF m..... + + +# DNS Response + +0000: 56 B1 85 83 00 01 00 00 00 01 00 00 08 6E 6F 74 V............not +0010: 66 6F 75 6E 64 07 64 6F 6D 61 69 6E 31 03 63 6F found.domain1.co +0020: 6D 00 00 FF 00 FF C0 15 00 06 00 01 00 00 8C A0 m............... +0030: 00 26 02 6E 73 C0 15 0A 70 6F 73 74 6D 61 73 74 .&.ns...postmast +0040: 65 72 C0 15 00 00 00 01 00 00 1C 20 00 00 0E 10 er......... .... +0050: 00 06 97 80 00 01 51 80 ......Q. + + --- /dev/null 2018-07-12 14:53:21.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNotFound.java 2018-07-12 14:53:21.000000000 +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 8198882 + * @summary Tests that get attributes of a missing child entry results + * in NameNotFoundException. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetAttrsNotFound + */ + +import javax.naming.NameNotFoundException; +import javax.naming.directory.Attributes; + +public class GetAttrsNotFound extends GetAttrsBase { + { + // set new test data instead of default value + setKey("notfound"); + } + + public static void main(String[] args) throws Exception { + new GetAttrsNotFound().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + + /* + * Tests that get attributes of a missing child entry results + * in NameNotFoundException. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKey()); + } + + @Override public void verifyAttributes(Attributes attrs) { + throw new RuntimeException( + "Failed: getAttributes succeeded unexpectedly"); + } + + @Override public boolean handleException(Exception e) { + if (e instanceof NameNotFoundException) { + System.out.println("Got exception as expected : " + e); + return true; + } + + return super.handleException(e); + } +} --- /dev/null 2018-07-12 14:53:22.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNullAttrIds.dns 2018-07-12 14:53:22.000000000 +0800 @@ -0,0 +1,58 @@ +# +# 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 GetAttrsNullAttrIds.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetAttrsNullAttrIds application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 60 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: 60 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 ......... + + --- /dev/null 2018-07-12 14:53:24.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsNullAttrIds.java 2018-07-12 14:53:23.000000000 +0800 @@ -0,0 +1,57 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry. + * Use getAttributes form that accepts an attrIds parameter + * and supply null for it. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetAttrsNullAttrIds + */ + +import javax.naming.directory.Attributes; + +public class GetAttrsNullAttrIds extends GetAttrsBase { + + public static void main(String[] args) throws Exception { + new GetAttrsNullAttrIds().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + + /* + * Tests that we can get the attributes of a DNS entry. + * Use getAttributes form that accepts an attrIds parameter + * and supply null for it. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKey(), null); + } +} --- /dev/null 2018-07-12 14:53:25.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsSomeAttrIds.dns 2018-07-12 14:53:25.000000000 +0800 @@ -0,0 +1,58 @@ +# +# 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 GetAttrsSomeAttrIds.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetAttrsSomeAttrIds application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 20 34 01 00 00 01 00 00 00 00 00 00 05 68 6F 73 4...........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: 20 34 85 80 00 01 00 06 00 01 00 01 05 68 6F 73 4...........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 ......... + + --- /dev/null 2018-07-12 14:53:27.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetAttrsSomeAttrIds.java 2018-07-12 14:53:26.000000000 +0800 @@ -0,0 +1,59 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry. + * Specify a subset of the attributes to be returned. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetAttrsSomeAttrIds + */ + +import javax.naming.directory.Attributes; + +public class GetAttrsSomeAttrIds extends GetAttrsBase { + { + // set new test data instead of default value + setMandatoryAttrs(new String[] { "A", "MX", "TXT" }); + } + + public static void main(String[] args) throws Exception { + new GetAttrsSomeAttrIds().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + + /* + * Tests that we can get the attributes of a DNS entry. + * Specify a subset of the attributes to be returned. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKey(), getMandatoryAttrs()); + } +} --- /dev/null 2018-07-12 14:53:28.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.dns 2018-07-12 14:53:28.000000000 +0800 @@ -0,0 +1,49 @@ +# +# 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 GetNonstandard.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetNonstandard application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 43 D5 01 00 00 01 00 00 00 00 00 00 05 68 6F 73 C............hos +0010: 74 31 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 t1.domain1.com.. +0020: 1D 00 01 ... + + +# DNS Response + +0000: 43 D5 85 80 00 01 00 01 00 01 00 01 05 68 6F 73 C............hos +0010: 74 31 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 t1.domain1.com.. +0020: 1D 00 01 C0 0C 00 1D 00 01 00 00 8C A0 00 10 00 ................ +0030: 12 16 13 88 97 1A 35 69 68 41 38 00 9B 16 58 C0 ......5ihA8...X. +0040: 12 00 02 00 01 00 00 8C A0 00 05 02 6E 73 C0 12 ............ns.. +0050: C0 4B 00 01 00 01 00 00 8C A0 00 04 7F 00 00 01 .K.............. + + --- /dev/null 2018-07-12 14:53:29.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.java 2018-07-12 14:53:29.000000000 +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. + */ + +/* + * @test + * @bug 8198882 + * @summary Tests that we can get an attribute that has a nonstandard name from + * a DNS entry. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetNonstandard + */ + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import java.util.Arrays; + +public class GetNonstandard extends GetAttrsBase { + { + // set new test data instead of default value + setMandatoryAttrs(new String[] { "29" // LOC + }); + } + + // "40 2 0.373 N 105 17 23.528 W 1638m" + private static final byte[] EXPECTED_VALUE = { (byte) 0, // version + (byte) 18, // size + (byte) 22, // horiz pre + (byte) 19, // vert pre + (byte) -120, // latitude 1 + (byte) -105, // latitude 2 + (byte) 26, // longitude 1 + (byte) 53, // longitude 2 + (byte) 105, // altitude 1 + (byte) 104, // altitude 2 + (byte) 65, (byte) 56, (byte) 0, (byte) -101, (byte) 22, + (byte) 88, }; + + public static void main(String[] args) throws Exception { + new GetNonstandard().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + verifyLoc(retAttrs); + } + + /* + * Tests that we can get an attribute that has a nonstandard name from + * a DNS entry. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKey(), getMandatoryAttrs()); + } + + private void verifyLoc(Attributes retAttrs) throws NamingException { + Attribute loc = retAttrs.get(getMandatoryAttrs()[0]); + byte[] val = (byte[]) loc.get(0); + + DNSTestUtils.debug("Expected: " + Arrays.toString(EXPECTED_VALUE)); + DNSTestUtils.debug("Actual: " + Arrays.toString(val)); + + if (val.length != EXPECTED_VALUE.length) { + throw new RuntimeException( + "Failed: unexpected value length " + val.length + + ", expected " + EXPECTED_VALUE.length); + } + + if (!Arrays.equals(val, EXPECTED_VALUE)) { + throw new RuntimeException("Failed: values not match"); + } + } +} --- /dev/null 2018-07-12 14:53:30.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericIRRs.dns 2018-07-12 14:53:30.000000000 +0800 @@ -0,0 +1,148 @@ +# +# 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 GetNumericIRRs.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetNumericIRRs application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: D6 36 01 00 00 01 00 00 00 00 00 00 05 68 6F 73 .6...........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: D6 36 85 80 00 01 00 06 00 01 00 01 05 68 6F 73 .6...........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: 3F B9 01 00 00 01 00 00 00 00 00 00 07 64 6F 6D ?............dom +0010: 61 69 6E 31 03 63 6F 6D 00 00 FF 00 01 ain1.com..... + + +# DNS Response + +0000: 3F B9 85 80 00 01 00 03 00 00 00 01 07 64 6F 6D ?............dom +0010: 61 69 6E 31 03 63 6F 6D 00 00 FF 00 01 C0 0C 00 ain1.com........ +0020: 06 00 01 00 00 8C A0 00 26 02 6E 73 C0 0C 0A 70 ........&.ns...p +0030: 6F 73 74 6D 61 73 74 65 72 C0 0C 00 00 00 01 00 ostmaster....... +0040: 00 1C 20 00 00 0E 10 00 06 97 80 00 01 51 80 C0 .. ..........Q.. +0050: 0C 00 02 00 01 00 00 8C A0 00 02 C0 29 C0 0C 00 ............)... +0060: 10 00 01 00 00 8C A0 00 0C 0B 54 65 73 74 20 64 ..........Test d +0070: 6F 6D 61 69 6E C0 29 00 01 00 01 00 00 8C A0 00 omain.)......... +0080: 04 7F 00 00 01 ..... + + +# DNS Request + +0000: F2 5D 01 00 00 01 00 00 00 00 00 00 04 69 70 76 .]...........ipv +0010: 36 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 1C 6.domain1.com... +0020: 00 01 .. + + +# DNS Response + +0000: F2 5D 85 80 00 01 00 01 00 01 00 01 04 69 70 76 .]...........ipv +0010: 36 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 1C 6.domain1.com... +0020: 00 01 C0 0C 00 1C 00 01 00 00 8C A0 00 10 00 0A ................ +0030: 00 0B 00 0C 00 0D 00 0E 00 01 00 02 00 03 C0 11 ................ +0040: 00 02 00 01 00 00 8C A0 00 05 02 6E 73 C0 11 C0 ...........ns... +0050: 4A 00 01 00 01 00 00 8C A0 00 04 7F 00 00 01 J.............. + + +# DNS Request + +0000: 4E 2D 01 00 00 01 00 00 00 00 00 00 03 73 75 6E N-...........sun +0010: 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 05 00 .domain1.com.... +0020: 01 . + + +# DNS Response + +0000: 4E 2D 85 80 00 01 00 01 00 01 00 01 03 73 75 6E N-...........sun +0010: 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 05 00 .domain1.com.... +0020: 01 C0 0C 00 05 00 01 00 00 8C A0 00 08 05 68 6F ..............ho +0030: 73 74 31 C0 10 C0 10 00 02 00 01 00 00 8C A0 00 st1............. +0040: 05 02 6E 73 C0 10 C0 41 00 01 00 01 00 00 8C A0 ..ns...A........ +0050: 00 04 7F 00 00 01 ...... + + +# DNS Request + +0000: 9D 9B 01 00 00 01 00 00 00 00 00 00 04 5F 66 74 ............._ft +0010: 70 04 5F 54 63 70 07 64 6F 6D 61 69 6E 31 03 63 p._Tcp.domain1.c +0020: 6F 6D 00 00 21 00 01 om..!.. + + +# DNS Response + +0000: 9D 9B 85 80 00 01 00 01 00 01 00 02 04 5F 66 74 ............._ft +0010: 70 04 5F 54 63 70 07 64 6F 6D 61 69 6E 31 03 63 p._Tcp.domain1.c +0020: 6F 6D 00 00 21 00 01 C0 0C 00 21 00 01 00 00 8C om..!.....!..... +0030: A0 00 19 00 01 00 00 00 15 05 68 6F 73 74 34 07 ..........host4. +0040: 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 C0 3F 00 02 domain1.com..?.. +0050: 00 01 00 00 8C A0 00 05 02 6E 73 C0 3F C0 39 00 .........ns.?.9. +0060: 01 00 01 00 01 51 80 00 04 01 02 04 04 C0 58 00 .....Q........X. +0070: 01 00 01 00 00 8C A0 00 04 7F 00 00 01 ............. + + +# DNS Request + +0000: 77 5B 01 00 00 01 00 00 00 00 00 00 01 31 01 34 w[...........1.4 +0010: 01 32 01 31 07 69 6E 2D 61 64 64 72 04 61 72 70 .2.1.in-addr.arp +0020: 61 00 00 0C 00 01 a..... + + +# DNS Response + +0000: 77 5B 85 80 00 01 00 01 00 01 00 01 01 31 01 34 w[...........1.4 +0010: 01 32 01 31 07 69 6E 2D 61 64 64 72 04 61 72 70 .2.1.in-addr.arp +0020: 61 00 00 0C 00 01 C0 0C 00 0C 00 01 00 00 8C A0 a............... +0030: 00 13 05 68 6F 73 74 31 07 64 6F 6D 61 69 6E 31 ...host1.domain1 +0040: 03 63 6F 6D 00 C0 0E 00 02 00 01 00 00 8C A0 00 .com............ +0050: 05 02 6E 73 C0 38 C0 51 00 01 00 01 00 00 8C A0 ..ns.8.Q........ +0060: 00 04 7F 00 00 01 ...... + + --- /dev/null 2018-07-12 14:53:31.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericIRRs.java 2018-07-12 14:53:31.000000000 +0800 @@ -0,0 +1,59 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry by naming + * specific RRs by their type codes and "IN" for internet class. + * Omit NAPTR for now because bind doesn't support it. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetNumericIRRs + */ + +import javax.naming.directory.Attributes; + +public class GetNumericIRRs extends GetRRsBase { + + public static void main(String[] args) throws Exception { + new GetNumericIRRs().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + testAgainstNonRootUrl(); + switchToRootUrl(); + testAgainstRootUrl(); + } + + /* + * Tests that we can get the attributes of a DNS entry by naming + * specific RRs by their type codes and "IN" for internet class. + * Omit NAPTR for now because bind doesn't support it. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKeys()[getIndex()], + getNumAttrs()[getIndex()]); + } +} --- /dev/null 2018-07-12 14:53:32.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericRRs.dns 2018-07-12 14:53:32.000000000 +0800 @@ -0,0 +1,148 @@ +# +# 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 GetNumericRRs.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetNumericRRs application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 7C 4B 01 00 00 01 00 00 00 00 00 00 05 68 6F 73 .K...........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: 7C 4B 85 80 00 01 00 06 00 01 00 01 05 68 6F 73 .K...........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: 60 6F 01 00 00 01 00 00 00 00 00 00 07 64 6F 6D `o...........dom +0010: 61 69 6E 31 03 63 6F 6D 00 00 FF 00 01 ain1.com..... + + +# DNS Response + +0000: 60 6F 85 80 00 01 00 03 00 00 00 01 07 64 6F 6D `o...........dom +0010: 61 69 6E 31 03 63 6F 6D 00 00 FF 00 01 C0 0C 00 ain1.com........ +0020: 06 00 01 00 00 8C A0 00 26 02 6E 73 C0 0C 0A 70 ........&.ns...p +0030: 6F 73 74 6D 61 73 74 65 72 C0 0C 00 00 00 01 00 ostmaster....... +0040: 00 1C 20 00 00 0E 10 00 06 97 80 00 01 51 80 C0 .. ..........Q.. +0050: 0C 00 02 00 01 00 00 8C A0 00 02 C0 29 C0 0C 00 ............)... +0060: 10 00 01 00 00 8C A0 00 0C 0B 54 65 73 74 20 64 ..........Test d +0070: 6F 6D 61 69 6E C0 29 00 01 00 01 00 00 8C A0 00 omain.)......... +0080: 04 7F 00 00 01 ..... + + +# DNS Request + +0000: 97 B5 01 00 00 01 00 00 00 00 00 00 04 69 70 76 .............ipv +0010: 36 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 1C 6.domain1.com... +0020: 00 01 .. + + +# DNS Response + +0000: 97 B5 85 80 00 01 00 01 00 01 00 01 04 69 70 76 .............ipv +0010: 36 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 1C 6.domain1.com... +0020: 00 01 C0 0C 00 1C 00 01 00 00 8C A0 00 10 00 0A ................ +0030: 00 0B 00 0C 00 0D 00 0E 00 01 00 02 00 03 C0 11 ................ +0040: 00 02 00 01 00 00 8C A0 00 05 02 6E 73 C0 11 C0 ...........ns... +0050: 4A 00 01 00 01 00 00 8C A0 00 04 7F 00 00 01 J.............. + + +# DNS Request + +0000: 61 7E 01 00 00 01 00 00 00 00 00 00 03 73 75 6E a............sun +0010: 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 05 00 .domain1.com.... +0020: 01 . + + +# DNS Response + +0000: 61 7E 85 80 00 01 00 01 00 01 00 01 03 73 75 6E a............sun +0010: 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 05 00 .domain1.com.... +0020: 01 C0 0C 00 05 00 01 00 00 8C A0 00 08 05 68 6F ..............ho +0030: 73 74 31 C0 10 C0 10 00 02 00 01 00 00 8C A0 00 st1............. +0040: 05 02 6E 73 C0 10 C0 41 00 01 00 01 00 00 8C A0 ..ns...A........ +0050: 00 04 7F 00 00 01 ...... + + +# DNS Request + +0000: 7D 9A 01 00 00 01 00 00 00 00 00 00 04 5F 66 74 ............._ft +0010: 70 04 5F 54 63 70 07 64 6F 6D 61 69 6E 31 03 63 p._Tcp.domain1.c +0020: 6F 6D 00 00 21 00 01 om..!.. + + +# DNS Response + +0000: 7D 9A 85 80 00 01 00 01 00 01 00 02 04 5F 66 74 ............._ft +0010: 70 04 5F 54 63 70 07 64 6F 6D 61 69 6E 31 03 63 p._Tcp.domain1.c +0020: 6F 6D 00 00 21 00 01 C0 0C 00 21 00 01 00 00 8C om..!.....!..... +0030: A0 00 19 00 01 00 00 00 15 05 68 6F 73 74 34 07 ..........host4. +0040: 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 C0 3F 00 02 domain1.com..?.. +0050: 00 01 00 00 8C A0 00 05 02 6E 73 C0 3F C0 39 00 .........ns.?.9. +0060: 01 00 01 00 01 51 80 00 04 01 02 04 04 C0 58 00 .....Q........X. +0070: 01 00 01 00 00 8C A0 00 04 7F 00 00 01 ............. + + +# DNS Request + +0000: B2 B9 01 00 00 01 00 00 00 00 00 00 01 31 01 34 .............1.4 +0010: 01 32 01 31 07 69 6E 2D 61 64 64 72 04 61 72 70 .2.1.in-addr.arp +0020: 61 00 00 0C 00 01 a..... + + +# DNS Response + +0000: B2 B9 85 80 00 01 00 01 00 01 00 01 01 31 01 34 .............1.4 +0010: 01 32 01 31 07 69 6E 2D 61 64 64 72 04 61 72 70 .2.1.in-addr.arp +0020: 61 00 00 0C 00 01 C0 0C 00 0C 00 01 00 00 8C A0 a............... +0030: 00 13 05 68 6F 73 74 31 07 64 6F 6D 61 69 6E 31 ...host1.domain1 +0040: 03 63 6F 6D 00 C0 0E 00 02 00 01 00 00 8C A0 00 .com............ +0050: 05 02 6E 73 C0 38 C0 51 00 01 00 01 00 00 8C A0 ..ns.8.Q........ +0060: 00 04 7F 00 00 01 ...... + + --- /dev/null 2018-07-12 14:53:33.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetNumericRRs.java 2018-07-12 14:53:33.000000000 +0800 @@ -0,0 +1,64 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry by naming + * specific RRs by their type codes. Omit NAPTR for now because + * bind doesn't support it. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetNumericRRs + */ + +import javax.naming.directory.Attributes; + +public class GetNumericRRs extends GetRRsBase { + { + // set new test data instead of default value + setNumAttrs(new String[][] { { "1", "15", "13", "16" }, { "2", "6" }, + { "28" }, { "5" }, { "33" }, { "12" }, }); + } + + public static void main(String[] args) throws Exception { + new GetNumericRRs().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + testAgainstNonRootUrl(); + switchToRootUrl(); + testAgainstRootUrl(); + } + + /* + * Tests that we can get the attributes of a DNS entry by naming + * specific RRs by their type codes. Omit NAPTR for now because + * bind doesn't support it. + */ + @Override public Attributes getAttributes() throws Exception { + return context().getAttributes(getKeys()[getIndex()], + getNumAttrs()[getIndex()]); + } +} --- /dev/null 2018-07-12 14:53:34.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetRRs.dns 2018-07-12 14:53:34.000000000 +0800 @@ -0,0 +1,148 @@ +# +# 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 GetRRs.java +# +# NOTE: This hexadecimal dump of DNS protocol messages was generated by +# running the GetRRs application program against a real DNS +# server along with DNSTracer +# +################################################################################ + +# DNS Request + +0000: 91 E0 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: 91 E0 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 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: 07 37 01 00 00 01 00 00 00 00 00 00 07 64 6F 6D .7...........dom +0010: 61 69 6E 31 03 63 6F 6D 00 00 FF 00 01 ain1.com..... + + +# DNS Response + +0000: 07 37 85 80 00 01 00 03 00 00 00 01 07 64 6F 6D .7...........dom +0010: 61 69 6E 31 03 63 6F 6D 00 00 FF 00 01 C0 0C 00 ain1.com........ +0020: 06 00 01 00 00 8C A0 00 26 02 6E 73 C0 0C 0A 70 ........&.ns...p +0030: 6F 73 74 6D 61 73 74 65 72 C0 0C 00 00 00 01 00 ostmaster....... +0040: 00 1C 20 00 00 0E 10 00 06 97 80 00 01 51 80 C0 .. ..........Q.. +0050: 0C 00 02 00 01 00 00 8C A0 00 02 C0 29 C0 0C 00 ............)... +0060: 10 00 01 00 00 8C A0 00 0C 0B 54 65 73 74 20 64 ..........Test d +0070: 6F 6D 61 69 6E C0 29 00 01 00 01 00 00 8C A0 00 omain.)......... +0080: 04 7F 00 00 01 ..... + + +# DNS Request + +0000: FF 0E 01 00 00 01 00 00 00 00 00 00 04 69 70 76 .............ipv +0010: 36 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 1C 6.domain1.com... +0020: 00 01 .. + + +# DNS Response + +0000: FF 0E 85 80 00 01 00 01 00 01 00 01 04 69 70 76 .............ipv +0010: 36 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 1C 6.domain1.com... +0020: 00 01 C0 0C 00 1C 00 01 00 00 8C A0 00 10 00 0A ................ +0030: 00 0B 00 0C 00 0D 00 0E 00 01 00 02 00 03 C0 11 ................ +0040: 00 02 00 01 00 00 8C A0 00 05 02 6E 73 C0 11 C0 ...........ns... +0050: 4A 00 01 00 01 00 00 8C A0 00 04 7F 00 00 01 J.............. + + +# DNS Request + +0000: 41 94 01 00 00 01 00 00 00 00 00 00 03 73 75 6E A............sun +0010: 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 05 00 .domain1.com.... +0020: 01 . + + +# DNS Response + +0000: 41 94 85 80 00 01 00 01 00 01 00 01 03 73 75 6E A............sun +0010: 07 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 00 05 00 .domain1.com.... +0020: 01 C0 0C 00 05 00 01 00 00 8C A0 00 08 05 68 6F ..............ho +0030: 73 74 31 C0 10 C0 10 00 02 00 01 00 00 8C A0 00 st1............. +0040: 05 02 6E 73 C0 10 C0 41 00 01 00 01 00 00 8C A0 ..ns...A........ +0050: 00 04 7F 00 00 01 ...... + + +# DNS Request + +0000: 8B D6 01 00 00 01 00 00 00 00 00 00 04 5F 66 74 ............._ft +0010: 70 04 5F 54 63 70 07 64 6F 6D 61 69 6E 31 03 63 p._Tcp.domain1.c +0020: 6F 6D 00 00 21 00 01 om..!.. + + +# DNS Response + +0000: 8B D6 85 80 00 01 00 01 00 01 00 02 04 5F 66 74 ............._ft +0010: 70 04 5F 54 63 70 07 64 6F 6D 61 69 6E 31 03 63 p._Tcp.domain1.c +0020: 6F 6D 00 00 21 00 01 C0 0C 00 21 00 01 00 00 8C om..!.....!..... +0030: A0 00 19 00 01 00 00 00 15 05 68 6F 73 74 34 07 ..........host4. +0040: 64 6F 6D 61 69 6E 31 03 63 6F 6D 00 C0 3F 00 02 domain1.com..?.. +0050: 00 01 00 00 8C A0 00 05 02 6E 73 C0 3F C0 39 00 .........ns.?.9. +0060: 01 00 01 00 01 51 80 00 04 01 02 04 04 C0 58 00 .....Q........X. +0070: 01 00 01 00 00 8C A0 00 04 7F 00 00 01 ............. + + +# DNS Request + +0000: D9 CF 01 00 00 01 00 00 00 00 00 00 01 31 01 34 .............1.4 +0010: 01 32 01 31 07 69 6E 2D 61 64 64 72 04 61 72 70 .2.1.in-addr.arp +0020: 61 00 00 0C 00 01 a..... + + +# DNS Response + +0000: D9 CF 85 80 00 01 00 01 00 01 00 01 01 31 01 34 .............1.4 +0010: 01 32 01 31 07 69 6E 2D 61 64 64 72 04 61 72 70 .2.1.in-addr.arp +0020: 61 00 00 0C 00 01 C0 0C 00 0C 00 01 00 00 8C A0 a............... +0030: 00 13 05 68 6F 73 74 31 07 64 6F 6D 61 69 6E 31 ...host1.domain1 +0040: 03 63 6F 6D 00 C0 0E 00 02 00 01 00 00 8C A0 00 .com............ +0050: 05 02 6E 73 C0 38 C0 51 00 01 00 01 00 00 8C A0 ..ns.8.Q........ +0060: 00 04 7F 00 00 01 ...... + + --- /dev/null 2018-07-12 14:53:35.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetRRs.java 2018-07-12 14:53:35.000000000 +0800 @@ -0,0 +1,58 @@ +/* + * 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 8198882 + * @summary Tests that we can get the attributes of a DNS entry by naming + * specific RRs by name. Omit NAPTR for now because bind doesn't + * support it. + * @modules java.base/sun.security.util + * @library ../lib/ + * @run main GetRRs + */ + +import javax.naming.directory.Attributes; + +public class GetRRs extends GetRRsBase { + public static void main(String[] args) throws Exception { + new GetRRs().run(args); + } + + @Override public void runTest() throws Exception { + initContext(); + testAgainstNonRootUrl(); + switchToRootUrl(); + testAgainstRootUrl(); + } + + /* + * Tests that we can get the attributes of a DNS entry by naming + * specific RRs by name. Omit NAPTR for now because bind doesn't + * support it. + */ + @Override public Attributes getAttributes() throws Exception { + return context() + .getAttributes(getKeys()[getIndex()], getAttrs()[getIndex()]); + } +} --- /dev/null 2018-07-12 14:53:37.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/AttributeTests/GetRRsBase.java 2018-07-12 14:53:36.000000000 +0800 @@ -0,0 +1,102 @@ +/* + * 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 javax.naming.directory.InitialDirContext; + +public abstract class GetRRsBase extends GetAttrsBase { + private String[] keys; + private String[][] numAttrs; + private String[][] attrs; + + { + // set default test data + setKeys(new String[] { "host1", "", "ipv6", "sun", "_ftp._Tcp", + "1.4.2.1.in-addr.arpa", }); + setNumAttrs(new String[][] { { "IN 1", "IN 15", "IN 13", "IN 16" }, + { "IN 2", "IN 6" }, { "IN 28" }, { "IN 5" }, { "IN 33" }, + { "IN 12" }, }); + setAttrs( + new String[][] { { "A", "MX", "HINFO", "TXT" }, { "NS", "SOA" }, + { "AAAA" }, { "CNAME" }, { "SRV" }, { "PTR" }, }); + } + + private static final int ROOT_LIMIT = 5; // point at which to use root ctx + + private int index; + + public void testAgainstNonRootUrl() throws Exception { + for (index = 0; index < ROOT_LIMIT; index++) { + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + } + + public void switchToRootUrl() throws NamingException { + DNSTestUtils.cleanup(context()); + env().put(Context.PROVIDER_URL, DNSTestUtils.getRootUrl(env())); + setContext(new InitialDirContext(env())); + } + + public void testAgainstRootUrl() throws Exception { + for (index = ROOT_LIMIT; index < keys.length; index++) { + Attributes retAttrs = getAttributes(); + verifyAttributes(retAttrs); + } + } + + @Override public void verifyAttributes(Attributes retAttrs) + throws Exception { + DNSTestUtils.verifySchema(retAttrs, attrs[index], new String[] {}); + } + + public int getIndex() { + return index; + } + + public String[] getKeys() { + return keys; + } + + public void setKeys(String[] keys) { + this.keys = keys; + } + + public String[][] getNumAttrs() { + return numAttrs; + } + + public void setNumAttrs(String[][] numAttrs) { + this.numAttrs = numAttrs; + } + + public String[][] getAttrs() { + return attrs; + } + + public void setAttrs(String[][] attrs) { + this.attrs = attrs; + } +} --- /dev/null 2018-07-12 14:53:37.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/lib/DNSTestBase.java 2018-07-12 14:53:37.000000000 +0800 @@ -0,0 +1,73 @@ +/* + * 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.directory.DirContext; +import java.util.Hashtable; + +public abstract class DNSTestBase extends TestBase { + private Hashtable env; + private DirContext ctx; + private boolean localServer; + + { + // set default + setLocalServer(true); + } + + @Override public void initTest(String[] args) { + env = DNSTestUtils + .initEnv(localServer, this.getClass().getName(), args); + } + + @Override public void cleanupTest() { + DNSTestUtils.cleanup(ctx); + Server server = (Server) env.get(DNSTestUtils.TEST_DNS_SERVER_THREAD); + if (server != null) { + server.stopServer(); + } + } + + public Hashtable env() { + if (env == null) { + throw new RuntimeException("Test had not been initialized"); + } + + return env; + } + + public DirContext context() { + if (ctx == null) { + throw new RuntimeException("Context had not been initialized"); + } + + return ctx; + } + + public void setContext(DirContext context) { + ctx = context; + } + + public void setLocalServer(boolean isRequired) { + this.localServer = isRequired; + } +} --- /dev/null 2018-07-12 14:53:39.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/lib/Server.java 2018-07-12 14:53:38.000000000 +0800 @@ -0,0 +1,27 @@ +/* + * 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. + */ + +public interface Server { + void stopServer(); + int getPort(); +} --- /dev/null 2018-07-12 14:53:40.000000000 +0800 +++ new/test/jdk/com/sun/jndi/dns/lib/TestBase.java 2018-07-12 14:53:39.000000000 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + */ + +public abstract class TestBase { + + public void run(String[] args) throws Exception { + initRes(); + initTest(args); + setupTest(); + launch(); + } + + public void initRes() throws Exception { + } + + public void initTest(String[] args) { + } + + public void setupTest() { + } + + public void launch() throws Exception { + try { + runTest(); + } catch (Exception e) { + if (!handleException(e)) { + throw e; + } + } finally { + cleanupTest(); + } + } + + public abstract void runTest() throws Exception; + + public boolean handleException(Exception e) { + return false; + } + + public abstract void cleanupTest(); +}