Path: blob/master/test/jdk/java/io/FilePermission/FilePermissionCollectionMerge.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*/2223/**24*25* @test26* @bug 816812727* @summary FilePermissionCollection merges incorrectly28* @modules java.base/sun.security.util29* @library /test/lib30* @build jdk.test.lib.Asserts31* @run main FilePermissionCollectionMerge32*/3334import sun.security.util.FilePermCompat;35import java.io.FilePermission;36import java.security.Permissions;37import jdk.test.lib.Asserts;3839public class FilePermissionCollectionMerge {4041public static void main(String[] args) throws Exception {42test("x");43test("x/*");44test("x/-");45test("*");46test("-");47test("/x");48test("/x/*");49test("/x/-");50}5152static void test(String arg) {5354FilePermission fp1 = new FilePermission(arg, "read");55FilePermission fp2 = (FilePermission)56FilePermCompat.newPermUsingAltPath(fp1);57FilePermission fp3 = (FilePermission)58FilePermCompat.newPermPlusAltPath(fp1);5960// All 3 are different61Asserts.assertNE(fp1, fp2);62Asserts.assertNE(fp1.hashCode(), fp2.hashCode());6364Asserts.assertNE(fp1, fp3);65Asserts.assertNE(fp1.hashCode(), fp3.hashCode());6667Asserts.assertNE(fp2, fp3);68Asserts.assertNE(fp2.hashCode(), fp3.hashCode());6970// The plus one implies the other 271Asserts.assertTrue(fp3.implies(fp1));72Asserts.assertTrue(fp3.implies(fp2));7374// The using one different from original75Asserts.assertFalse(fp2.implies(fp1));76Asserts.assertFalse(fp1.implies(fp2));7778// FilePermssionCollection::implies always works79testMerge(fp1);80testMerge(fp2);81testMerge(fp3);82testMerge(fp1, fp2);83testMerge(fp1, fp3);84testMerge(fp2, fp1);85testMerge(fp2, fp3);86testMerge(fp3, fp1);87testMerge(fp3, fp2);88testMerge(fp1, fp2, fp3);89testMerge(fp2, fp3, fp1);90testMerge(fp3, fp1, fp2);91}9293// Add all into a collection, and check if it implies the last one.94static void testMerge(FilePermission... fps) {95java.security.Permissions perms = new Permissions();96FilePermission last = null;97for (FilePermission fp : fps) {98perms.add(fp);99last = fp;100}101Asserts.assertTrue(perms.implies(last));102}103}104105106