author | weijun |
Mon, 22 Apr 2019 13:01:57 +0800 | |
changeset 58612 | 32aff2b7585b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
1 |
/* |
58612 | 2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
4 |
* |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
8 |
* |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
14 |
* |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
18 |
* |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
21 |
* questions. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
22 |
*/ |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
23 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
24 |
/* |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
25 |
* @test |
58612 | 26 |
* @bug 8164705 8209901 |
27 |
* @library /test/jdk/java/security/testlibrary |
|
28 |
* @modules java.base/jdk.internal.misc |
|
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
29 |
* @summary check jdk.filepermission.canonicalize |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
30 |
*/ |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
31 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
32 |
import java.io.File; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
33 |
import java.io.FilePermission; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
34 |
import java.lang.*; |
58612 | 35 |
import java.nio.file.Path; |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
36 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
37 |
public class Flag { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
39 |
|
58612 | 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 |
||
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
104 |
boolean test1; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
105 |
boolean test2; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
106 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
107 |
String here = System.getProperty("user.dir"); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
108 |
File abs = new File(here, "x"); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
109 |
FilePermission fp1 = new FilePermission("x", "read"); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
110 |
FilePermission fp2 = new FilePermission(abs.toString(), "read"); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
111 |
test1 = fp1.equals(fp2); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
112 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
113 |
try { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
114 |
System.getSecurityManager().checkPermission(fp2); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
115 |
test2 = true; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
116 |
} catch (SecurityException se) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
117 |
test2 = false; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
118 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
119 |
|
58612 | 120 |
if (test1 != Boolean.parseBoolean(args[1]) || |
121 |
test2 != Boolean.parseBoolean(args[2])) { |
|
43803
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
41377
diff
changeset
|
122 |
throw new Exception("Test failed: " + test1 + " " + test2); |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
123 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
124 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff
changeset
|
125 |
} |