Path: blob/master/test/jdk/sun/security/util/FilePermCompat/Flag.java
41152 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8164705 820990126* @library /test/lib27* @summary check jdk.filepermission.canonicalize28*/2930import jdk.test.lib.process.Proc;31import java.io.File;32import java.io.FilePermission;33import java.lang.*;34import java.nio.file.Path;3536public class Flag {37public static void main(String[] args) throws Exception {3839if (args.length == 0) {40String policy = Path.of(41System.getProperty("test.src"), "flag.policy").toString();4243// effectively true44Proc.create("Flag")45.prop("java.security.manager", "")46.prop("java.security.policy", policy)47.prop("jdk.io.permissionsUseCanonicalPath", "true")48.args("run", "true", "true")49.start()50.waitFor(0);51Proc.create("Flag")52.prop("java.security.manager", "")53.prop("java.security.policy", policy)54.secprop("jdk.io.permissionsUseCanonicalPath", "true")55.args("run", "true", "true")56.start()57.waitFor(0);58Proc.create("Flag")59.prop("java.security.manager", "")60.prop("java.security.policy", policy)61.secprop("jdk.io.permissionsUseCanonicalPath", "false")62.prop("jdk.io.permissionsUseCanonicalPath", "true")63.args("run", "true", "true")64.start()65.waitFor(0);6667// effectively false68Proc.create("Flag")69.prop("java.security.manager", "")70.prop("java.security.policy", policy)71.prop("jdk.io.permissionsUseCanonicalPath", "false")72.args("run", "false", "true")73.start()74.waitFor(0);75Proc.create("Flag")76.prop("java.security.manager", "")77.prop("java.security.policy", policy)78.secprop("jdk.io.permissionsUseCanonicalPath", "false")79.args("run", "false", "true")80.start()81.waitFor(0);82Proc.create("Flag")83.prop("java.security.manager", "")84.prop("java.security.policy", policy)85.secprop("jdk.io.permissionsUseCanonicalPath", "true")86.prop("jdk.io.permissionsUseCanonicalPath", "false")87.args("run", "false", "true")88.start()89.waitFor(0);90Proc.create("Flag")91.prop("java.security.manager", "")92.prop("java.security.policy", policy)93.args("run", "false", "true")94.start()95.waitFor(0);96} else {97run(args);98}99}100101static void run(String[] args) throws Exception {102103boolean test1;104boolean test2;105106String here = System.getProperty("user.dir");107File abs = new File(here, "x");108FilePermission fp1 = new FilePermission("x", "read");109FilePermission fp2 = new FilePermission(abs.toString(), "read");110test1 = fp1.equals(fp2);111112try {113System.getSecurityManager().checkPermission(fp2);114test2 = true;115} catch (SecurityException se) {116test2 = false;117}118119if (test1 != Boolean.parseBoolean(args[1]) ||120test2 != Boolean.parseBoolean(args[2])) {121throw new Exception("Test failed: " + test1 + " " + test2);122}123}124}125126127