Path: blob/master/test/jdk/java/io/FilePermission/MergeName.java
41149 views
/*1* Copyright (c) 2016, 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*/2223import jdk.test.lib.process.ProcessTools;2425import java.io.File;26import java.io.FilePermission;27import java.nio.file.Files;28import java.nio.file.Paths;29import java.util.ArrayList;30import java.util.List;31import java.util.stream.Collectors;32import java.util.stream.IntStream;3334/**35* @test36* @bug 817036437* @summary FilePermission path modified during merge38* @library /test/lib39* @build jdk.test.lib.Utils40* jdk.test.lib.Asserts41* jdk.test.lib.JDKToolFinder42* jdk.test.lib.JDKToolLauncher43* jdk.test.lib.Platform44* jdk.test.lib.process.*45* @run main MergeName46*/4748public class MergeName {4950public static final String[] ALL_ACTIONS51= {"read", "write", "execute", "delete"};5253public static void main(String[] args) throws Exception {54if (args.length == 0) {55test("p1", "read", "write", "delete", "execute");56test("p2", "read,write", "delete,execute");57test("p3", "read,write,delete", "execute");58test("p4", "read,write,delete,execute");59} else {60SecurityManager sm = System.getSecurityManager();61for (String arg : args) {62// Use bits to create powerset of ALL_ACTIONS63IntStream.range(1, 16)64.mapToObj(n -> IntStream.range(0, 4)65.filter(x -> (n & (1 << x)) != 0)66.mapToObj(x -> ALL_ACTIONS[x])67.collect(Collectors.joining(",")))68.forEach(a -> sm.checkPermission(69new FilePermission(arg, a)));70}71}72}7374private static void test(String file, String... actions) throws Exception {75List<String> content = new ArrayList<>();76content.add("grant {");77for (String action : actions) {78content.add(" permission java.io.FilePermission " +79"\"x\", \"" +action + "\";");80}81content.add("};");82Files.write(Paths.get(file), content);83ProcessTools.executeTestJvm("-Djava.security.manager",84"-Djava.security.policy=" + file,85"MergeName",86"x",87new File(System.getProperty("user.dir"), "x").getPath())88.shouldHaveExitValue(0);89}90}919293