Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/util/FilePermCompat/Flag.java
41152 views
1
/*
2
* Copyright (c) 2016, 2019, 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 8164705 8209901
27
* @library /test/lib
28
* @summary check jdk.filepermission.canonicalize
29
*/
30
31
import jdk.test.lib.process.Proc;
32
import java.io.File;
33
import java.io.FilePermission;
34
import java.lang.*;
35
import java.nio.file.Path;
36
37
public class Flag {
38
public static void main(String[] args) throws Exception {
39
40
if (args.length == 0) {
41
String policy = Path.of(
42
System.getProperty("test.src"), "flag.policy").toString();
43
44
// effectively true
45
Proc.create("Flag")
46
.prop("java.security.manager", "")
47
.prop("java.security.policy", policy)
48
.prop("jdk.io.permissionsUseCanonicalPath", "true")
49
.args("run", "true", "true")
50
.start()
51
.waitFor(0);
52
Proc.create("Flag")
53
.prop("java.security.manager", "")
54
.prop("java.security.policy", policy)
55
.secprop("jdk.io.permissionsUseCanonicalPath", "true")
56
.args("run", "true", "true")
57
.start()
58
.waitFor(0);
59
Proc.create("Flag")
60
.prop("java.security.manager", "")
61
.prop("java.security.policy", policy)
62
.secprop("jdk.io.permissionsUseCanonicalPath", "false")
63
.prop("jdk.io.permissionsUseCanonicalPath", "true")
64
.args("run", "true", "true")
65
.start()
66
.waitFor(0);
67
68
// effectively false
69
Proc.create("Flag")
70
.prop("java.security.manager", "")
71
.prop("java.security.policy", policy)
72
.prop("jdk.io.permissionsUseCanonicalPath", "false")
73
.args("run", "false", "true")
74
.start()
75
.waitFor(0);
76
Proc.create("Flag")
77
.prop("java.security.manager", "")
78
.prop("java.security.policy", policy)
79
.secprop("jdk.io.permissionsUseCanonicalPath", "false")
80
.args("run", "false", "true")
81
.start()
82
.waitFor(0);
83
Proc.create("Flag")
84
.prop("java.security.manager", "")
85
.prop("java.security.policy", policy)
86
.secprop("jdk.io.permissionsUseCanonicalPath", "true")
87
.prop("jdk.io.permissionsUseCanonicalPath", "false")
88
.args("run", "false", "true")
89
.start()
90
.waitFor(0);
91
Proc.create("Flag")
92
.prop("java.security.manager", "")
93
.prop("java.security.policy", policy)
94
.args("run", "false", "true")
95
.start()
96
.waitFor(0);
97
} else {
98
run(args);
99
}
100
}
101
102
static void run(String[] args) throws Exception {
103
104
boolean test1;
105
boolean test2;
106
107
String here = System.getProperty("user.dir");
108
File abs = new File(here, "x");
109
FilePermission fp1 = new FilePermission("x", "read");
110
FilePermission fp2 = new FilePermission(abs.toString(), "read");
111
test1 = fp1.equals(fp2);
112
113
try {
114
System.getSecurityManager().checkPermission(fp2);
115
test2 = true;
116
} catch (SecurityException se) {
117
test2 = false;
118
}
119
120
if (test1 != Boolean.parseBoolean(args[1]) ||
121
test2 != Boolean.parseBoolean(args[2])) {
122
throw new Exception("Test failed: " + test1 + " " + test2);
123
}
124
}
125
}
126
127