changeset 39137:6cf0e983a1e1

8071660: URLPermission not handling empty method lists correctly Reviewed-by: chegar, dfuchs, prappo, rriggs
author vtewari
date Wed, 22 Jun 2016 09:01:34 +0100
parents 0dbb98c91291
children 1e1d98dbb44b
files jdk/src/java.base/share/classes/java/net/URLPermission.java jdk/test/java/net/URLPermission/URLPermissionTest.java
diffstat 2 files changed, 37 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/java/net/URLPermission.java	Wed Jun 22 16:12:39 2016 +0900
+++ b/jdk/src/java.base/share/classes/java/net/URLPermission.java	Wed Jun 22 09:01:34 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -265,8 +265,14 @@
 
         URLPermission that = (URLPermission)p;
 
-        if (!this.methods.get(0).equals("*") &&
-                Collections.indexOfSubList(this.methods, that.methods) == -1) {
+        if (this.methods.isEmpty() && !that.methods.isEmpty()) {
+            return false;
+        }
+
+        if (!this.methods.isEmpty() &&
+            !this.methods.get(0).equals("*") &&
+            Collections.indexOfSubList(this.methods,
+                                       that.methods) == -1) {
             return false;
         }
 
--- a/jdk/test/java/net/URLPermission/URLPermissionTest.java	Wed Jun 22 16:12:39 2016 +0900
+++ b/jdk/test/java/net/URLPermission/URLPermissionTest.java	Wed Jun 22 09:01:34 2016 +0100
@@ -26,7 +26,7 @@
 
 /**
  * @test
- * @bug 8010464 8027570 8027687 8029354 8114860
+ * @bug 8010464 8027570 8027687 8029354 8114860 8071660
  */
 
 public class URLPermissionTest {
@@ -110,6 +110,8 @@
 
     static class ActionImpliesTest extends Test {
         String arg1, arg2;
+        String url1 = "http://www.foo.com/-";
+        String url2 = "http://www.foo.com/a/b";
 
         ActionImpliesTest(String arg1, String arg2, boolean expected) {
             this.arg1 = arg1;
@@ -117,10 +119,17 @@
             this.expected = expected;
         }
 
+        ActionImpliesTest(String ur11, String url2, String arg1, String arg2,
+            boolean expected) {
+            this.url1 = ur11;
+            this.url2 = url2;
+            this.arg1 = arg1;
+            this.arg2 = arg2;
+            this.expected = expected;
+        }
+
         @Override
           boolean execute() {
-            String url1 = "http://www.foo.com/-";
-            String url2 = "http://www.foo.com/a/b";
             URLPermission p1 = new URLPermission(url1, arg1);
             URLPermission p2 = new URLPermission(url2, arg2);
             boolean result = p1.implies(p2);
@@ -155,6 +164,11 @@
         return new ActionImpliesTest(arg1, arg2, expected);
     }
 
+    static ActionImpliesTest actest(String url1, String url2, String arg1,
+        String arg2, boolean expected) {
+        return new ActionImpliesTest(url1, url2, arg1, arg2, expected);
+    }
+
     static class HashCodeTest extends Test {
         String arg1, arg2;
         int hash;
@@ -314,6 +328,9 @@
         imtest("https:*", "http:*", false)
     };
 
+    static final String FOO_URL = "http://www.foo.com/";
+    static final String BAR_URL = "http://www.bar.com/";
+
     static Test[] actionImplies = {
         actest("GET", "GET", true),
         actest("GET", "POST", false),
@@ -327,7 +344,14 @@
         actest("GET:X-Foo,X-Bar", "GET:x-bar,x-foo", true),
         actest("GET:X-Bar,X-Foo,X-Bar,Y-Foo", "GET:x-bar,x-foo", true),
         actest("GET:*", "GET:x-bar,x-foo", true),
-        actest("*:*", "GET:x-bar,x-foo", true)
+        actest("*:*", "GET:x-bar,x-foo", true),
+        actest("", "GET:x-bar,x-foo", false),
+        actest("GET:x-bar,x-foo", "", true),
+        actest("", "", true),
+        actest("GET,DELETE", "GET,DELETE:x-foo", false),
+        actest(FOO_URL, BAR_URL, "", "GET:x-bar,x-foo", false),
+        actest(FOO_URL, BAR_URL, "GET:x-bar,x-foo", "", false),
+        actest(FOO_URL, BAR_URL, "", "", false)
     };
 
     static Test[] actionsStringTest = {