Path: blob/master/test/jdk/sun/security/krb5/auto/DnsCanonicalizeHostname.java
41152 views
/*1* Copyright (c) 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.Asserts;24import sun.security.krb5.PrincipalName;2526import java.nio.file.Files;27import java.nio.file.Path;28import java.util.List;2930/*31* @test32* @bug 821082133* @summary Support dns_canonicalize_hostname in krb5.conf34* @library /test/lib35* @compile -XDignore.symbol.file DnsCanonicalizeHostname.java36* @run main jdk.test.lib.FileInstaller dns_canonicalize_hostname.hosts hosts37* @run main/othervm -Djdk.net.hosts.file=hosts DnsCanonicalizeHostname none38* @run main/othervm -Djdk.net.hosts.file=hosts DnsCanonicalizeHostname true39* @run main/othervm -Djdk.net.hosts.file=hosts DnsCanonicalizeHostname false40*/41public class DnsCanonicalizeHostname {4243// In dns_canonicalize_hostname.hosts, all "dummy.example.com", "dummy",44// and "bogus" are resolved to 127.0.0.1. Since "dummy.example.com" is on45// the first line, it is returned at the reverse lookup.4647public static void main(String[] args) throws Exception {4849Files.write(Path.of("krb5.conf"), List.of(50"[libdefaults]",51"default_realm = R",52args[0].equals("none")53? "# empty line"54: "dns_canonicalize_hostname = " + args[0],55"",56"[realms]",57"R = {",58" kdc = 127.0.0.1",59"}"60));61System.setProperty("java.security.krb5.conf", "krb5.conf");6263String n1 = new PrincipalName("host/dummy", PrincipalName.KRB_NT_SRV_HST)64.getNameStrings()[1];65String n2 = new PrincipalName("host/bogus", PrincipalName.KRB_NT_SRV_HST)66.getNameStrings()[1];6768switch (args[0]) {69case "none":70case "true":71Asserts.assertEQ(n1, "dummy.example.com");72Asserts.assertEQ(n2, "bogus");73break;74case "false":75Asserts.assertEQ(n1, "dummy");76Asserts.assertEQ(n2, "bogus");77break;78}79}80}818283