Path: blob/master/test/jdk/com/sun/jndi/dns/ConfigTests/RecursiveTest.java
41155 views
/*1* Copyright (c) 2000, 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 javax.naming.NamingException;24import javax.naming.directory.Attributes;25import javax.naming.directory.InitialDirContext;26import java.util.Hashtable;2728/*29* @test30* @bug 820015131* @summary Tests that we can get the attributes of DNS entries of32* nonrecursive data. And recursive data by default or when33* com.sun.jndi.dns.recursion is set to true, but not when34* com.sun.jndi.dns.recursion is set to false.35* @library ../lib/36* @modules java.base/sun.security.util37* @run main RecursiveTest -Dtestname=RecursiveDefault38* @run main RecursiveTest -Dtestname=RecursiveFalse39* @run main RecursiveTest -Dtestname=RecursiveTrue40*/4142public class RecursiveTest extends AuthRecursiveBase {4344public static void main(String[] args) throws Exception {45new RecursiveTest().run(args);46}4748/*49* Tests that we can get the attributes of DNS entries of50* nonrecursive data. And recursive data by default or when51* com.sun.jndi.dns.recursion is set to true, but not when52* com.sun.jndi.dns.recursion is set to false.53*/54@Override55public void runTest() throws Exception {56String flag = parseFlagFromTestName();5758if (flag.equalsIgnoreCase("default")) {59setContext(new InitialDirContext());60} else {61Hashtable<Object, Object> env = new Hashtable<>();62DNSTestUtils.debug("set com.sun.jndi.dns.recursion to " + flag);63// com.sun.jndi.dns.recursion is set to true or false64env.put("com.sun.jndi.dns.recursion", flag);65setContext(new InitialDirContext(env));66}6768retrieveAndVerifyNonRecursiveData();69retrieveRecursiveData(70flag.equalsIgnoreCase("default") || Boolean.parseBoolean(flag));71}7273private void retrieveAndVerifyNonRecursiveData() throws NamingException {74// Ensure that nonrecursive data retrieval is OK75retrieveAndVerifyData(getFqdnUrl());76}7778/*79* If isRecur == true, ensure that recursive data retrieval is OK.80* If isRecur == false, ensure that recursive data retrieval fails.81*/82private void retrieveRecursiveData(boolean isRecur) throws NamingException {83Attributes retAttrs = context().getAttributes(getForeignFqdnUrl());84if (isRecur) {85DNSTestUtils.verifySchema(retAttrs, new String[] { "CNAME" },86new String[] {});87} else {88DNSTestUtils.debug(retAttrs);89if (retAttrs.size() > 0) {90throw new RuntimeException("Expecting recursive data not found "91+ getForeignFqdnUrl());92}93}94}95}969798