Path: blob/master/test/jdk/javax/security/auth/kerberos/DelegationPermissionCollection.java
41152 views
/*1* Copyright (c) 2015, 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 805617926* @summary Unit test for DelegationPermissionCollection subclass27*/2829import java.security.Permission;30import java.security.PermissionCollection;31import java.security.SecurityPermission;32import java.util.Enumeration;33import javax.security.auth.kerberos.DelegationPermission;3435public class DelegationPermissionCollection {3637private static final String FOO = "\"host/[email protected]\"";38private static final String BAR = "\"host/[email protected]\"";39private static final String TGT = "\"krbtgt/[email protected]\"";4041public static void main(String[] args) throws Exception {4243int testFail = 0;4445DelegationPermission perm = new DelegationPermission(FOO + " " + TGT);46PermissionCollection perms = perm.newPermissionCollection();4748// test 149System.out.println50("test 1: add throws IllegalArgException for wrong perm type");51try {52perms.add(new SecurityPermission("createAccessControlContext"));53System.err.println("Expected IllegalArgumentException");54testFail++;55} catch (IllegalArgumentException iae) {}5657// test 258System.out.println("test 2: implies returns false for wrong perm type");59if (perms.implies(new SecurityPermission("getPolicy"))) {60System.err.println("Expected false, returned true");61testFail++;62}6364// test 365System.out.println("test 3: implies returns true for match on name");66perms.add(new DelegationPermission(FOO + " " + TGT));67if (!perms.implies(new DelegationPermission(FOO + " " + TGT))) {68System.err.println("Expected true, returned false");69testFail++;70}7172// test 473System.out.println74("test 4: implies returns false for non-match on name");75if (perms.implies(new DelegationPermission(BAR + " " + TGT))) {76System.err.println("Expected false, returned true");77testFail++;78}7980// test 581System.out.println("test 5: elements returns correct number of perms");82int numPerms = 0;83Enumeration<Permission> e = perms.elements();84while (e.hasMoreElements()) {85numPerms++;86System.out.println(e.nextElement());87}88if (numPerms != 1) {89System.err.println("Expected 1, got " + numPerms);90testFail++;91}9293if (testFail > 0) {94throw new Exception(testFail + " test(s) failed");95}96}97}9899100