Path: blob/master/test/jdk/sun/net/InetAddress/nameservice/dns/CNameTest.java
41161 views
/*1* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import jdk.test.lib.process.ProcessTools;2425import java.nio.file.Files;26import java.nio.file.Path;27import java.nio.file.Paths;28import java.nio.file.StandardOpenOption;2930/**31* @test32* @bug 476331533* @modules java.naming34* @library /test/lib35* @build CanonicalName Lookup jdk.test.lib.process.*36* @run main/othervm/timeout=120 CNameTest37* @summary Test DNS provider's handling of CNAME records38*/39public class CNameTest {40private static final String HOST = "www.w3c.org";41private static final String POLICY = "grant {" + System.lineSeparator() +42" permission java.net .SocketPermission \"${HOST}\", \"resolve\";" +43System.lineSeparator() + "};";4445public static void main(String[] args) throws Exception {46// Prerequisite check47int rc = ProcessTools.executeTestJava("CanonicalName", HOST)48.outputTo(System.out)49.errorTo(System.out)50.getExitValue();51if (rc != 0) {52System.out.println("DNS not configured or host doesn't" +53" resolve to CNAME record");54return;55}5657// Tests - with & without security manager58Path policy = Paths.get(".", "java.policy");59Files.write(policy, POLICY.getBytes(), StandardOpenOption.CREATE_NEW);60String[] opts = new String[]{61"-Dsun.net.spi.nameservice.provider.1=dns,sun",62"-Djava.security.manager -Djava.security.policy=" + policy63};64for (String opt : opts) {65ProcessTools.executeTestJava(opt, "Lookup", HOST)66.outputTo(System.out)67.errorTo(System.err)68.shouldHaveExitValue(0);69}70}71}72737475