jdk/test/sun/security/provider/PolicyFile/CanonPath.java
author mullan
Mon, 16 May 2016 13:53:46 -0400
changeset 38324 1ecea77815a8
parent 5506 202f599c92aa
child 41377 271ee055cb31
permissions -rw-r--r--
8150468: ClassCircularityError on error in security policy file Reviewed-by: mchung, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6203047
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Inconsistency in FilePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class CanonPath {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private static boolean windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static final String WIN_FOOBAR = "\\foo\\bar\\";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static final String UNIX_FOOBAR = "/foo/bar/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static final String WIN_FOO = "\\foo.txt";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final String UNIX_FOO = "/foo.txt";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final String WIN_BAR = "bar\\bar.txt";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final String UNIX_BAR = "bar/bar.txt";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static final String WIN_SLASH = "\\";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static final String UNIX_SLASH = "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static void printCanonPath(String label, String path)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        File f = new File(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        System.out.println(label + " path = " + f.getCanonicalPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (System.getProperty("os.name").startsWith("Windows")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            windows = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            System.out.println("Testing on Windows");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            System.out.println("Testing on Unix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        System.out.println("\\\\foo\\\\bar\\\\- versus /foo/bar/-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        FilePermission w = new FilePermission(WIN_FOOBAR + "-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        FilePermission u = new FilePermission(UNIX_FOOBAR + "-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        printCanonPath("WIN_FOOBAR", WIN_FOOBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        printCanonPath("UNIX_FOOBAR", UNIX_FOOBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                throw new Exception("FOOBAR test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                throw new Exception("FOOBAR test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        System.out.println("\\\\foo.txt versus /foo.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        w = new FilePermission(WIN_FOO, "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        u = new FilePermission(UNIX_FOO, "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        printCanonPath("WIN_FOO", WIN_FOO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        printCanonPath("UNIX_FOO", UNIX_FOO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                throw new Exception("FOO test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                throw new Exception("FOO test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        System.out.println("bar\\\\bar.txt versus bar/bar.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        w = new FilePermission(WIN_BAR, "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        u = new FilePermission(UNIX_BAR, "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        printCanonPath("WIN_BAR", WIN_BAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        printCanonPath("UNIX_BAR", UNIX_BAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                throw new Exception("BAR test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                throw new Exception("BAR test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        System.out.println("\\\\ versus /");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        w = new FilePermission(WIN_SLASH, "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        u = new FilePermission(UNIX_SLASH, "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        printCanonPath("WIN_SLASH", WIN_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        printCanonPath("UNIX_SLASH", UNIX_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                throw new Exception("SLASH test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                throw new Exception("SLASH test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        System.out.println("\\\\- versus /-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        w = new FilePermission(WIN_SLASH + "-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        u = new FilePermission(UNIX_SLASH + "-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        printCanonPath("WIN_SLASH", WIN_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        printCanonPath("UNIX_SLASH", UNIX_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                throw new Exception("SLASH/- test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            // XXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            // on unix, /- implies everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                throw new Exception("SLASH/- test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        System.out.println("- versus -");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        w = new FilePermission("-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        u = new FilePermission("-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        printCanonPath("WIN_DASH", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        printCanonPath("UNIX_DASH", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                throw new Exception("- test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                throw new Exception("- test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        System.out.println("- versus *");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        w = new FilePermission("-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        u = new FilePermission("*", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        printCanonPath("WIN_DASH", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        printCanonPath("UNIX_STAR", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // XXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // - implies *, but not the other way around
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (!w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                throw new Exception("- test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            // XXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // - implies *, but not the other way around
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (!w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                throw new Exception("- test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        System.out.println("\\\\* versus /*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        w = new FilePermission(WIN_SLASH + "*", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        u = new FilePermission(UNIX_SLASH + "*", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        printCanonPath("WIN_SLASH", WIN_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        printCanonPath("UNIX_SLASH", UNIX_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (!w.implies(u) || !u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new Exception("SLASH/* test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                throw new Exception("SLASH/* test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        System.out.println("\\\\foo\\\\bar\\\\- versus /foo/bar/foobar/w.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        w = new FilePermission(WIN_FOOBAR + "-", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        u = new FilePermission("/foo/bar/foobar/w.txt", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        printCanonPath("FOOBAR", WIN_FOOBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        printCanonPath("W.TXT", "/foo/bar/foobar/w.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (!w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                throw new Exception("w.txt (-) test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                throw new Exception("w.txt (-) test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        System.out.println("\\\\foo\\\\bar\\\\* versus /foo/bar/w.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        w = new FilePermission(WIN_FOOBAR + "*", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        u = new FilePermission("/foo/bar/w.txt", "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        printCanonPath("FOOBAR", WIN_FOOBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        printCanonPath("W.TXT", "/foo/bar/w.txt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (!w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                throw new Exception("w.txt (*) test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (w.implies(u) || u.implies(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                throw new Exception("w.txt (*) test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // make sure "/" does not imply "/-" nor "/*"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        System.out.println("/ versus /- and /*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        File file = new File(UNIX_SLASH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        FilePermission recursive = new FilePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                (file.getCanonicalPath() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                File.separatorChar +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                "-",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        FilePermission wild = new FilePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                (file.getCanonicalPath() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                File.separatorChar +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                "*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        FilePermission standard = new FilePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                (file.getCanonicalPath(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (standard.implies(recursive) || standard.implies(wild)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw new Exception("standard vs directory test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}