Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/FilePermission/MergeName.java
41149 views
1
/*
2
* Copyright (c) 2016, 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
import jdk.test.lib.process.ProcessTools;
25
26
import java.io.File;
27
import java.io.FilePermission;
28
import java.nio.file.Files;
29
import java.nio.file.Paths;
30
import java.util.ArrayList;
31
import java.util.List;
32
import java.util.stream.Collectors;
33
import java.util.stream.IntStream;
34
35
/**
36
* @test
37
* @bug 8170364
38
* @summary FilePermission path modified during merge
39
* @library /test/lib
40
* @build jdk.test.lib.Utils
41
* jdk.test.lib.Asserts
42
* jdk.test.lib.JDKToolFinder
43
* jdk.test.lib.JDKToolLauncher
44
* jdk.test.lib.Platform
45
* jdk.test.lib.process.*
46
* @run main MergeName
47
*/
48
49
public class MergeName {
50
51
public static final String[] ALL_ACTIONS
52
= {"read", "write", "execute", "delete"};
53
54
public static void main(String[] args) throws Exception {
55
if (args.length == 0) {
56
test("p1", "read", "write", "delete", "execute");
57
test("p2", "read,write", "delete,execute");
58
test("p3", "read,write,delete", "execute");
59
test("p4", "read,write,delete,execute");
60
} else {
61
SecurityManager sm = System.getSecurityManager();
62
for (String arg : args) {
63
// Use bits to create powerset of ALL_ACTIONS
64
IntStream.range(1, 16)
65
.mapToObj(n -> IntStream.range(0, 4)
66
.filter(x -> (n & (1 << x)) != 0)
67
.mapToObj(x -> ALL_ACTIONS[x])
68
.collect(Collectors.joining(",")))
69
.forEach(a -> sm.checkPermission(
70
new FilePermission(arg, a)));
71
}
72
}
73
}
74
75
private static void test(String file, String... actions) throws Exception {
76
List<String> content = new ArrayList<>();
77
content.add("grant {");
78
for (String action : actions) {
79
content.add(" permission java.io.FilePermission " +
80
"\"x\", \"" +action + "\";");
81
}
82
content.add("};");
83
Files.write(Paths.get(file), content);
84
ProcessTools.executeTestJvm("-Djava.security.manager",
85
"-Djava.security.policy=" + file,
86
"MergeName",
87
"x",
88
new File(System.getProperty("user.dir"), "x").getPath())
89
.shouldHaveExitValue(0);
90
}
91
}
92
93