Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sql/permissionTests/SyncFactoryPermissionsTests.java
41149 views
1
/*
2
* Copyright (c) 2014, 2021, 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
import java.security.AccessControlException;
24
import java.security.Policy;
25
import java.util.logging.Level;
26
import java.util.logging.Logger;
27
import javax.naming.Context;
28
import javax.sql.rowset.spi.SyncFactory;
29
import javax.sql.rowset.spi.SyncFactoryException;
30
import org.testng.annotations.AfterClass;
31
import org.testng.annotations.BeforeClass;
32
import org.testng.annotations.Test;
33
import util.BaseTest;
34
import util.StubContext;
35
import util.TestPolicy;
36
/*
37
* @test
38
* @library /java/sql/testng
39
* @library /javax/sql/testng
40
* @run testng/othervm -Djava.security.manager=allow SyncFactoryPermissionsTests
41
* @summary Tests SyncFactory permissions.
42
*/
43
public class SyncFactoryPermissionsTests extends BaseTest {
44
45
Context ctx;
46
private static Policy policy;
47
private static SecurityManager sm;
48
private final Logger alogger = Logger.getLogger(this.getClass().getName());
49
50
/*
51
* Install a SeeurityManager along with a base Policy to allow testNG to run
52
*/
53
@BeforeClass
54
public static void setUpClass() throws Exception {
55
setPolicy(new TestPolicy());
56
System.setSecurityManager(new SecurityManager());
57
}
58
59
/*
60
* Install the original Policy and SecurityManager
61
*/
62
@AfterClass
63
public static void tearDownClass() throws Exception {
64
System.setSecurityManager(sm);
65
setPolicy(policy);
66
}
67
68
/*
69
* Initialize a Context to be used in our tests.
70
* Save off the original Policy and SecurityManager
71
*/
72
public SyncFactoryPermissionsTests() {
73
policy = Policy.getPolicy();
74
sm = System.getSecurityManager();
75
ctx = new StubContext();
76
}
77
78
/*
79
* Validate that AccessControlException is thrown if
80
* SQLPermission("setSyncFactory") has not been granted
81
*/
82
@Test(expectedExceptions = AccessControlException.class)
83
public void test() throws Exception {
84
setPolicy(new TestPolicy());
85
SyncFactory.setJNDIContext(ctx);
86
}
87
88
/*
89
* Validate that a SyncFactoryException is thrown if the Logger is null
90
*/
91
@Test(expectedExceptions = SyncFactoryException.class)
92
public void test00() throws SyncFactoryException {
93
Logger l = SyncFactory.getLogger();
94
}
95
96
/*
97
* Validate that setJNDIContext succeeds if SQLPermission("setSyncFactory")
98
* has been granted
99
*/
100
@Test
101
public void test01() throws Exception {
102
setPolicy(new TestPolicy("setSyncFactory"));
103
SyncFactory.setJNDIContext(ctx);
104
}
105
106
/*
107
* Validate that setJNDIContext succeeds if AllPermissions has been granted
108
*/
109
@Test
110
public void test02() throws Exception {
111
setPolicy(new TestPolicy("all"));
112
SyncFactory.setJNDIContext(ctx);
113
}
114
115
/*
116
* Validate that AccessControlException is thrown if
117
* SQLPermission("setSyncFactory") has not been granted
118
*/
119
@Test(expectedExceptions = AccessControlException.class)
120
public void test03() throws Exception {
121
setPolicy(new TestPolicy());
122
SyncFactory.setLogger(alogger);
123
}
124
125
/*
126
* Validate that setLogger succeeds if SQLPermission("setSyncFactory")
127
* has been granted
128
*/
129
@Test
130
public void test04() throws Exception {
131
setPolicy(new TestPolicy("setSyncFactory"));
132
SyncFactory.setLogger(alogger);
133
}
134
135
/*
136
* Validate that setLogger succeeds if AllPermissions has been granted
137
*/
138
@Test
139
public void test05() throws Exception {
140
setPolicy(new TestPolicy("all"));
141
SyncFactory.setLogger(alogger);
142
}
143
144
/*
145
* Validate that AccessControlException is thrown if
146
* SQLPermission("setSyncFactory") has not been granted
147
*/
148
@Test(expectedExceptions = AccessControlException.class)
149
public void test06() throws Exception {
150
setPolicy(new TestPolicy());
151
SyncFactory.setLogger(alogger, Level.INFO);
152
}
153
154
/*
155
* Validate that AccessControlException is thrown if
156
* SQLPermission("setSyncFactory") and LoggingPermission("control", null)
157
* have not been granted
158
*/
159
@Test(expectedExceptions = AccessControlException.class)
160
public void test07() throws Exception {
161
setPolicy(new TestPolicy("setSyncFactory"));
162
SyncFactory.setLogger(alogger, Level.INFO);
163
}
164
165
/*
166
* Validate that setLogger succeeds if SQLPermission("setSyncFactory")
167
* has been granted
168
*/
169
@Test
170
public void test08() throws Exception {
171
setPolicy(new TestPolicy("setSyncFactoryLogger"));
172
SyncFactory.setLogger(alogger, Level.INFO);
173
}
174
175
/*
176
* Validate that setLogger succeeds if AllPermissions has been granted
177
*/
178
@Test
179
public void test09() throws Exception {
180
setPolicy(new TestPolicy("all"));
181
SyncFactory.setLogger(alogger, Level.INFO);
182
}
183
}
184
185