Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/smartcardio/TestCardPermission.java
41144 views
1
/*
2
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 6293767 6469513 8255546
27
* @summary Test for the CardPermission class
28
* @author Andreas Sterbenz
29
* @run testng TestCardPermission
30
*/
31
32
import org.testng.annotations.DataProvider;
33
import org.testng.annotations.Test;
34
35
import javax.smartcardio.*;
36
import java.security.Permission;
37
38
import static org.testng.Assert.*;
39
40
public class TestCardPermission {
41
42
@DataProvider(name = "actions")
43
Object[][] getActions() {
44
return new Object[][]{
45
{"*"},
46
{"connect"},
47
{"reset"},
48
{"exclusive"},
49
{"transmitControl"},
50
{"getBasicChannel"},
51
{"openLogicalChannel"},
52
{"connect,reset"}
53
};
54
}
55
56
@DataProvider(name = "actionsCanon")
57
Object[][] getActionsCanon() {
58
return new Object[][]{
59
{"Reset,coNnect", "connect,reset"},
60
{"exclusive,*,connect", "*"},
61
{"connect,reset,exclusive,transmitControl,getBasicChannel,openLogicalChannel", "*"},
62
{null, null}
63
};
64
}
65
66
@DataProvider(name = "invalidActions")
67
Object[][] getInvalidActions() {
68
return new Object[][]{
69
{""},
70
{"foo"},
71
{"connect, reset"},
72
{"connect,,reset"},
73
{"connect,"},
74
{",connect"}
75
};
76
}
77
78
@Test(dataProvider = "actions")
79
public void testActions(String actions) throws Exception {
80
testActions(actions, actions);
81
}
82
83
@Test(dataProvider = "actionsCanon")
84
public void testActionsCanon(String actions, String canon) throws Exception {
85
testActions(actions, canon);
86
}
87
88
@Test(dataProvider = "invalidActions")
89
public void testInvalidActions(String actions) {
90
assertThrows(IllegalArgumentException.class, () -> new CardPermission("*", actions));
91
}
92
93
// Should return false since p2 is not a CardPermission instance
94
@Test
95
public void testImpliesNotCardPermissionInstance() {
96
String actions = "connect";
97
CardPermission p1 = new CardPermission("*", actions);
98
Permission p2 = new Permission(actions) {
99
@Override public boolean implies(Permission permission) { return false; }
100
@Override public boolean equals(Object obj) { return false; }
101
@Override public int hashCode() { return 0; }
102
@Override public String getActions() { return null; }
103
};
104
assertFalse(p1.implies(p2));
105
}
106
107
// Should return false since p2 actions are not a subset of p1
108
@Test
109
public void testImpliesNotSubsetCardPermission() {
110
CardPermission p1 = new CardPermission("*", "connect,reset");
111
CardPermission p2 = new CardPermission("*", "transmitControl");
112
assertFalse(p1.implies(p2));
113
}
114
115
// Should return true since p1 name is * and p2 actions are a subset of p1
116
@Test
117
public void testImpliesNameEqualsAll() {
118
CardPermission p1 = new CardPermission("*", "connect,reset");
119
CardPermission p2 = new CardPermission("None", "reset");
120
assertTrue(p1.implies(p2));
121
}
122
123
// Should return true since p1 and p2 names are equal
124
@Test
125
public void testImpliesBothSameNameNotAll() {
126
CardPermission p1 = new CardPermission("None", "connect,reset");
127
CardPermission p2 = new CardPermission("None", "reset");
128
assertTrue(p1.implies(p2));
129
}
130
131
// Should return false since p1 and p2 names are not equal
132
@Test
133
public void testImpliesNameNotSameNotAll() {
134
CardPermission p1 = new CardPermission("None", "connect,reset");
135
CardPermission p2 = new CardPermission("Other", "reset");
136
assertFalse(p1.implies(p2));
137
}
138
139
private void testActions(String actions, String canon) throws Exception {
140
CardPermission p = new CardPermission("*", actions);
141
System.out.println(p);
142
String a = p.getActions();
143
if (canon != null && !canon.equals(a)) {
144
throw new Exception("Canonical actions mismatch: " + canon + " != " + a);
145
}
146
}
147
}
148
149