Repository: shapesecurity/salvation (java)

Issue:
Add method telling if policy is enforceable
It is useful to know if resulting policy is "enforceable" or "report" policy.
For example, `form-action *; ` is a redundant policy so it does not contain any enforceable directives. 

Pull request:
fixes #133
- add policy method to tell if it is effective policy
- tests
- remove unused imports

Patch:
diff --git a/src/main/java/com/shapesecurity/salvation/data/Policy.java b/src/main/java/com/shapesecurity/salvation/data/Policy.java
index 37d8473..e249f82 100644
--- a/src/main/java/com/shapesecurity/salvation/data/Policy.java
+++ b/src/main/java/com/shapesecurity/salvation/data/Policy.java
@@ -530,4 +530,14 @@ public class Policy implements Show {
         }
         return frameAncestorsDirective.matchesSource(this.origin, source);
     }
+
+    public boolean hasSomeEffect() {
+        for (Map.Entry<Class<?>, Directive<? extends DirectiveValue>> entry : this.directives.entrySet()) {
+            Directive<? extends DirectiveValue> directive = entry.getValue();
+            if (!(directive instanceof ReportToDirective) && !(directive instanceof ReportUriDirective)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
diff --git a/src/main/java/com/shapesecurity/salvation/directives/ReportToDirective.java b/src/main/java/com/shapesecurity/salvation/directives/ReportToDirective.java
index 2134efd..266a9d6 100644
--- a/src/main/java/com/shapesecurity/salvation/directives/ReportToDirective.java
+++ b/src/main/java/com/shapesecurity/salvation/directives/ReportToDirective.java
@@ -1,6 +1,5 @@
 package com.shapesecurity.salvation.directives;
 
-import com.shapesecurity.salvation.data.URI;
 import com.shapesecurity.salvation.directiveValues.ReportToValue;
 
 import javax.annotation.Nonnull;


Test patch:
diff --git a/src/test/java/com/shapesecurity/salvation/LocationTest.java b/src/test/java/com/shapesecurity/salvation/LocationTest.java
index 95772bf..f4c88c4 100644
--- a/src/test/java/com/shapesecurity/salvation/LocationTest.java
+++ b/src/test/java/com/shapesecurity/salvation/LocationTest.java
@@ -1,7 +1,6 @@
 package com.shapesecurity.salvation;
 
 import com.shapesecurity.salvation.data.Notice;
-import com.shapesecurity.salvation.data.Policy;
 import com.shapesecurity.salvation.data.URI;
 import com.shapesecurity.salvation.tokens.Token;
 import org.junit.Test;
diff --git a/src/test/java/com/shapesecurity/salvation/PolicyQueryingTest.java b/src/test/java/com/shapesecurity/salvation/PolicyQueryingTest.java
index 37cb1bb..f705474 100644
--- a/src/test/java/com/shapesecurity/salvation/PolicyQueryingTest.java
+++ b/src/test/java/com/shapesecurity/salvation/PolicyQueryingTest.java
@@ -470,4 +470,12 @@ public class PolicyQueryingTest extends CSPTest {
         assertFalse(p.allowsScriptFromSource(new GUID("custom.scheme:")));
     }
 
+    @Test public void testHasSomeEffect() {
+        Policy p = Parser.parse("", "http://example.com");
+        assertFalse(p.hasSomeEffect());
+        p = Parser.parse("script-src a; upgrade-insecure-requests; report-to a", "http://example.com");
+        assertTrue(p.hasSomeEffect());
+        p = Parser.parse("report-to a", "http://example.com");
+        assertFalse(p.hasSomeEffect());
+    }
 }