blob: ae1d5688b9932f3e4f4eb075c4d42fc35705685a [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4364848
27 * @bug 4364851
28 * @summary PrivateCredentialPermission doesn't ignore principal order
29 * PrivateCredentialPermission incorrectly ignores case
30 */
31
32import javax.security.auth.*;
33
34public class Equals {
35
36 public static void main(String[] args) {
37
38 // test regular equals and implies
39 PrivateCredentialPermission pcp1 = new PrivateCredentialPermission
40 ("a b \"pcp1\" c \"pcp2\"", "read");
41 PrivateCredentialPermission pcp2 = new PrivateCredentialPermission
42 ("a b \"pcp1\" c \"pcp2\"", "read");
43 if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))
44 throw new SecurityException("Equals test failed: #1");
45 if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))
46 throw new SecurityException("Equals test failed: #2");
47
48 // reverse principals
49 pcp1 = new PrivateCredentialPermission
50 ("a c \"pcp2\" b \"pcp1\"", "read");
51 pcp2 = new PrivateCredentialPermission
52 ("a b \"pcp1\" c \"pcp2\"", "read");
53 if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))
54 throw new SecurityException("Equals test failed: #3");
55 if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))
56 throw new SecurityException("Equals test failed: #4");
57
58 // test equals/implies failure
59 pcp1 = new PrivateCredentialPermission
60 ("a b \"pcp1\"", "read");
61 if (pcp1.equals(pcp2) || pcp2.equals(pcp1))
62 throw new SecurityException("Equals test failed: #5");
63 if (!pcp1.implies(pcp2) || pcp2.implies(pcp1))
64 throw new SecurityException("Equals test failed: #6");
65
66 // test wildcards
67 pcp1 = new PrivateCredentialPermission
68 ("* b \"pcp1\" c \"pcp2\"", "read");
69 if (pcp1.equals(pcp2) || pcp2.equals(pcp1))
70 throw new SecurityException("Equals test failed: #7");
71 if (!pcp1.implies(pcp2) || pcp2.implies(pcp1))
72 throw new SecurityException("Equals test failed: #8");
73
74 pcp1 = new PrivateCredentialPermission
75 ("a c \"pcp2\" b \"*\"", "read");
76 if (pcp1.equals(pcp2) || pcp2.equals(pcp1))
77 throw new SecurityException("Equals test failed: #9");
78 if (!pcp1.implies(pcp2) || pcp2.implies(pcp1))
79 throw new SecurityException("Equals test failed: #10");
80
81 pcp2 = new PrivateCredentialPermission
82 ("a b \"*\" c \"pcp2\"", "read");
83 if (!pcp1.equals(pcp2) || !pcp2.equals(pcp1))
84 throw new SecurityException("Equals test failed: #11");
85 if (!pcp1.implies(pcp2) || !pcp2.implies(pcp1))
86 throw new SecurityException("Equals test failed: #12");
87
88 System.out.println("Equals test passed");
89 }
90}