Path: blob/master/test/jdk/javax/security/auth/PrivateCredentialPermission/CanonError.java
41153 views
/*1* Copyright (c) 2000, 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 436483326* @summary PrivateCredentialPermission incorrectly canonicalizes27* spaces in names28*/2930import javax.security.auth.*;3132public class CanonError {3334public static void main(String[] args) {3536// test regular equals and implies37PrivateCredentialPermission pcp1 = new PrivateCredentialPermission38("a b \"pcp1\"", "read");39PrivateCredentialPermission pcp2 = new PrivateCredentialPermission40("a b \"pcp1\"", "read");41if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))42throw new SecurityException("CanonError test failed: #1");43if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))44throw new SecurityException("CanonError test failed: #2");4546// test equals/implies failure47PrivateCredentialPermission pcp3 = new PrivateCredentialPermission48("a b \"pcp3\"", "read");49if (pcp1.equals(pcp3) || pcp3.equals(pcp1))50throw new SecurityException("CanonError test failed: #3");51if (pcp1.implies(pcp3) || pcp3.implies(pcp1))52throw new SecurityException("CanonError test failed: #4");5354// test spaces in name55PrivateCredentialPermission pcp_4 = new PrivateCredentialPermission56("a b \"pcp 4\"", "read");57PrivateCredentialPermission pcp__4 = new PrivateCredentialPermission58("a b \"pcp 4\"", "read");59if (pcp_4.equals(pcp__4) || pcp__4.equals(pcp_4))60throw new SecurityException("CanonError test failed: #5");61if (pcp_4.implies(pcp__4) || pcp__4.implies(pcp_4))62throw new SecurityException("CanonError test failed: #6");6364String credClass = pcp__4.getCredentialClass();65System.out.println("credentialClass = " + credClass);66String[][] principals = pcp__4.getPrincipals();67if (!principals[0][1].equals("pcp 4"))68throw new SecurityException("CanonError test failed: #7");69for (int i = 0; i < principals.length; i++) {70for (int j = 0; j < 2; j++) {71System.out.println("principals[" + i + "][" + j + "] = " +72principals[i][j]);73}74}7576credClass = pcp_4.getCredentialClass();77System.out.println("credentialClass = " + credClass);78principals = pcp_4.getPrincipals();79if (!principals[0][1].equals("pcp 4"))80throw new SecurityException("CanonError test failed: #8");81for (int i = 0; i < principals.length; i++) {82for (int j = 0; j < 2; j++) {83System.out.println("principals[" + i + "][" + j + "] = " +84principals[i][j]);85}86}8788System.out.println("CanonError test passed");89}90}919293