test/jdk/sun/security/util/FilePermCompat/Flag.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43803 jdk/test/sun/security/util/FilePermCompat/Flag.java@e1881d258206
child 58612 32aff2b7585b
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41377
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
     1
/*
43803
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
     2
 * Copyright (c) 2016, 2017, 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
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    26
 * @bug 8164705
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    27
 * @summary check jdk.filepermission.canonicalize
43803
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    28
 * @run main/othervm/policy=flag.policy
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    29
  *     -Djdk.io.permissionsUseCanonicalPath=true Flag true true
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    30
 * @run main/othervm/policy=flag.policy
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    31
  *     -Djdk.io.permissionsUseCanonicalPath=false Flag false true
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    32
 * @run main/othervm/policy=flag.policy Flag false true
41377
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    33
 */
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    34
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    35
import java.io.File;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    36
import java.io.FilePermission;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    37
import java.lang.*;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    38
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    39
public class Flag {
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    41
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    42
        boolean test1;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    43
        boolean test2;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    44
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    45
        String here = System.getProperty("user.dir");
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    46
        File abs = new File(here, "x");
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    47
        FilePermission fp1 = new FilePermission("x", "read");
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    48
        FilePermission fp2 = new FilePermission(abs.toString(), "read");
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    49
        test1 = fp1.equals(fp2);
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    50
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    51
        try {
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    52
            System.getSecurityManager().checkPermission(fp2);
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    53
            test2 = true;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    54
        } catch (SecurityException se) {
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    55
            test2 = false;
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    56
        }
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    57
43803
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    58
        if (test1 != Boolean.parseBoolean(args[0]) ||
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    59
                test2 != Boolean.parseBoolean(args[1])) {
e1881d258206 8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents: 41377
diff changeset
    60
            throw new Exception("Test failed: " + test1 + " " + test2);
41377
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    61
        }
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    62
    }
271ee055cb31 8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
diff changeset
    63
}