Path: blob/master/test/jdk/sun/security/krb5/config/native/TestDynamicStore.java
41161 views
/*1* Copyright (c) 2021, 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*/2223/*24* @test25* @bug 825786026* @summary SCDynamicStoreConfig works27* @modules java.security.jgss/sun.security.krb528* @library /test/lib29* @run main/manual/native TestDynamicStore30* @requires (os.family == "mac")31*/3233import jdk.test.lib.Asserts;34import sun.security.krb5.Config;3536public class TestDynamicStore {3738native static int actionInternal(char what, char whom);3940// what: 'a' for add, 'r' for remove41// whom: 'a' for all, 'r' for realm, 'm' for mapping42static int action(char what, char whom) throws Exception {43int out = actionInternal(what, whom);44System.out.println("Run " + what + whom + " " + out);45Thread.sleep(1000); // wait for callback called46return out;47}4849public static void main(String[] args) throws Exception {5051System.loadLibrary("TestDynamicStore");5253Config cfg = Config.getInstance();54if (cfg.exists("libdefaults") || cfg.exists("realms")) {55System.out.println("Already have krb5 config. Will not touch");56return;57}5859try {60System.out.println("Fill in dynamic store");61action('a', 'a');62Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM"));63Asserts.assertTrue(Config.getInstance().exists("domain_realm"));6465System.out.println("Remove mapping");66action('r', 'm');67Asserts.assertTrue(!Config.getInstance().exists("domain_realm"));6869System.out.println("Re-add mapping");70action('a', 'm');71Asserts.assertTrue(Config.getInstance().exists("domain_realm"));7273System.out.println("Remove realm info");74action('r', 'r');75// Realm info is not watched, so no change detected76Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM"));7778System.out.println("Remove mapping");79action('r', 'm');80// But mapping is watched, so realm info is not re-read81Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("B.COM"));82} finally {83System.out.println("Remove everything");84action('r', 'a');85Asserts.assertTrue(!Config.getInstance().exists("libdefault"));86}87}88}899091