jdk/test/java/net/URLPermission/URLPermissionTest.java
changeset 22105 09df5383d1df
parent 21621 3101c2e7e705
child 39132 e9499c06e138
equal deleted inserted replaced
22104:ff3bfe024b5f 22105:09df5383d1df
    24 import java.net.URLPermission;
    24 import java.net.URLPermission;
    25 import java.io.*;
    25 import java.io.*;
    26 
    26 
    27 /**
    27 /**
    28  * @test
    28  * @test
    29  * @bug 8010464 8027570 8027687
    29  * @bug 8010464 8027570 8027687 8029354
    30  */
    30  */
    31 
    31 
    32 public class URLPermissionTest {
    32 public class URLPermissionTest {
    33 
    33 
    34     // super class for all test types
    34     // super class for all test types
    35     abstract static class Test {
    35     abstract static class Test {
    36         boolean expected;
    36         boolean expected;
    37         abstract boolean execute();
    37         abstract boolean execute();
    38     };
    38     };
    39 
    39 
       
    40     // Instantiation: should succeed
       
    41     static class CreateTest extends Test {
       
    42         String arg;
       
    43         CreateTest(String arg) {
       
    44             this.arg = arg;
       
    45         }
       
    46 
       
    47         @Override
       
    48         boolean execute() {
       
    49             try {
       
    50                 URLPermission p = new URLPermission(arg);
       
    51                 return true;
       
    52             } catch (Exception e) {
       
    53                 return false;
       
    54             }
       
    55         }
       
    56     };
       
    57 
       
    58     static CreateTest createtest(String arg) {
       
    59         return new CreateTest(arg);
       
    60     }
       
    61 
    40     // Should throw an IAE on construction
    62     // Should throw an IAE on construction
       
    63 
    41     static class ExTest extends Test {
    64     static class ExTest extends Test {
    42         String arg;
    65         String arg;
    43         ExTest(String arg) {
    66         ExTest(String arg) {
    44             this.arg = arg;
    67             this.arg = arg;
    45         }
    68         }
   260         imtest("https://www.foo.com/a/b", "https://www.foo.com:80/a/b", false),
   283         imtest("https://www.foo.com/a/b", "https://www.foo.com:80/a/b", false),
   261         imtest("https://www.foo.com:70-90/a/b", "https://www.foo.com/a/b", false),
   284         imtest("https://www.foo.com:70-90/a/b", "https://www.foo.com/a/b", false),
   262         imtest("https://www.foo.com/a/b", "https://www.foo.com:443/a/b", true),
   285         imtest("https://www.foo.com/a/b", "https://www.foo.com:443/a/b", true),
   263         imtest("https://www.foo.com:200-500/a/b", "https://www.foo.com/a/b", true),
   286         imtest("https://www.foo.com:200-500/a/b", "https://www.foo.com/a/b", true),
   264         imtest("http://www.foo.com:*/a/b", "http://www.foo.com:1-12345/a/b", true),
   287         imtest("http://www.foo.com:*/a/b", "http://www.foo.com:1-12345/a/b", true),
       
   288         imtest("http://host/a/b", "http://HOST/a/b", true),
   265 
   289 
   266         // misc
   290         // misc
   267         imtest("https:*", "http://www.foo.com", false),
   291         imtest("https:*", "http://www.foo.com", false),
   268         imtest("https:*", "http:*", false)
   292         imtest("https:*", "http:*", false)
   269     };
   293     };
   295         eqtest("http://*.foo.com", "http://*.foo.com", true),
   319         eqtest("http://*.foo.com", "http://*.foo.com", true),
   296         eqtest("http://www.foo.com/a/b", "http://www.foo.com:80/a/b", true),
   320         eqtest("http://www.foo.com/a/b", "http://www.foo.com:80/a/b", true),
   297         eqtest("http://www.foo.com/a/b", "http://www.foo.com:82/a/b", false),
   321         eqtest("http://www.foo.com/a/b", "http://www.foo.com:82/a/b", false),
   298         eqtest("https://www.foo.com/a/b", "https://www.foo.com:443/a/b", true),
   322         eqtest("https://www.foo.com/a/b", "https://www.foo.com:443/a/b", true),
   299         eqtest("https://www.foo.com/a/b", "https://www.foo.com:444/a/b", false),
   323         eqtest("https://www.foo.com/a/b", "https://www.foo.com:444/a/b", false),
       
   324         eqtest("http://michael@foo.com/bar","http://michael@foo.com/bar", true),
       
   325         eqtest("http://Michael@foo.com/bar","http://michael@goo.com/bar",false),
       
   326         eqtest("http://michael@foo.com/bar","http://george@foo.com/bar", true),
       
   327         eqtest("http://@foo.com/bar","http://foo.com/bar", true)
       
   328     };
       
   329 
       
   330     static Test[] createTests = {
       
   331         createtest("http://user@foo.com/a/b/c"),
       
   332         createtest("http://user:pass@foo.com/a/b/c"),
       
   333         createtest("http://user:@foo.com/a/b/c")
   300     };
   334     };
   301 
   335 
   302     static boolean failed = false;
   336     static boolean failed = false;
   303 
   337 
   304     public static void main(String args[]) throws Exception {
   338     public static void main(String args[]) throws Exception {
   381             if (!result) {
   415             if (!result) {
   382                 System.out.println ("test failed: " + test.arg);
   416                 System.out.println ("test failed: " + test.arg);
   383                 failed = true;
   417                 failed = true;
   384             } else {
   418             } else {
   385                 System.out.println ("exception test " + i + " OK");
   419                 System.out.println ("exception test " + i + " OK");
       
   420             }
       
   421         }
       
   422 
       
   423         for (int i=0; i<createTests.length; i++) {
       
   424             CreateTest test = (CreateTest)createTests[i];
       
   425             boolean result = test.execute();
       
   426             if (!result) {
       
   427                 System.out.println ("test failed: " + test.arg);
       
   428                 failed = true;
       
   429             } else {
       
   430                 System.out.println ("create test " + i + " OK");
   386             }
   431             }
   387         }
   432         }
   388 
   433 
   389         for (int i=0; i<actionImplies.length ; i++) {
   434         for (int i=0; i<actionImplies.length ; i++) {
   390             ActionImpliesTest test = (ActionImpliesTest)actionImplies[i];
   435             ActionImpliesTest test = (ActionImpliesTest)actionImplies[i];