Exemplo n.º 1
0
 def testDirective_combine_regular(self):
     direct1 = Directive("default-src", [DirectiveTest.sampleSrcExpr1a])
     direct2 = Directive("default-src", [DirectiveTest.sampleSrcExpr2])
     expected = Directive("default-src", [DirectiveTest.sampleSrcExpr1a, DirectiveTest.sampleSrcExpr2])
     assert direct1.combinedDirective(direct2) == expected
     assert direct2.combinedDirective(direct1) == expected
     assert direct1.combinedDirective(direct1) == direct1
     assert direct2.combinedDirective(direct2) == direct2
Exemplo n.º 2
0
 def testDirective_combine_removeDuplicates(self):
     direct1 = Directive(
         "img-src",
         [DirectiveTest.sampleSrcExpr1a,
          SelfSourceExpression.SELF()])
     direct2 = Directive("img-src", [DirectiveTest.sampleSrcExpr1b])
     assert direct1.combinedDirective(direct2) == direct1
     assert direct2.combinedDirective(direct1) == direct1
Exemplo n.º 3
0
 def testDirective_combine_notRegularURI(self):
     direct = Directive("style-src", [SelfSourceExpression.SELF()])
     assert direct.combinedDirective(
         Directive.INVALID()) == Directive.INVALID()
     assert Directive.INVALID().combinedDirective(
         direct) == Directive.INVALID()
     assert direct.combinedDirective(
         Directive.EVAL_SCRIPT_BASE_RESTRICTION()) == Directive.INVALID()
     assert Directive.EVAL_SCRIPT_BASE_RESTRICTION().combinedDirective(
         direct) == Directive.INVALID()
Exemplo n.º 4
0
 def testDirective_combine_regular(self):
     direct1 = Directive("default-src", [DirectiveTest.sampleSrcExpr1a])
     direct2 = Directive("default-src", [DirectiveTest.sampleSrcExpr2])
     expected = Directive(
         "default-src",
         [DirectiveTest.sampleSrcExpr1a, DirectiveTest.sampleSrcExpr2])
     assert direct1.combinedDirective(direct2) == expected
     assert direct2.combinedDirective(direct1) == expected
     assert direct1.combinedDirective(direct1) == direct1
     assert direct2.combinedDirective(direct2) == direct2
Exemplo n.º 5
0
 def testDirective_combine_removeDuplicates(self):
     direct1 = Directive("img-src", [DirectiveTest.sampleSrcExpr1a, SelfSourceExpression.SELF()])
     direct2 = Directive("img-src", [DirectiveTest.sampleSrcExpr1b])
     assert direct1.combinedDirective(direct2) == direct1
     assert direct2.combinedDirective(direct1) == direct1
Exemplo n.º 6
0
 def testDirective_combine_notRegularURI(self):
     direct = Directive("style-src", [SelfSourceExpression.SELF()])
     assert direct.combinedDirective(Directive.INVALID()) == Directive.INVALID()
     assert Directive.INVALID().combinedDirective(direct) == Directive.INVALID()
     assert direct.combinedDirective(Directive.EVAL_SCRIPT_BASE_RESTRICTION()) == Directive.INVALID()
     assert Directive.EVAL_SCRIPT_BASE_RESTRICTION().combinedDirective(direct) == Directive.INVALID()
Exemplo n.º 7
0
 def testDirective_combine_differentType(self):
     direct1 = Directive("default-src", [DirectiveTest.sampleSrcExpr1a])
     direct2 = Directive("script-src", [DirectiveTest.sampleSrcExpr2])
     assert direct1.combinedDirective(direct2) == Directive.INVALID()
     assert direct2.combinedDirective(direct1) == Directive.INVALID()
Exemplo n.º 8
0
 def testDirective_combine_differentType(self):
     direct1 = Directive("default-src", [DirectiveTest.sampleSrcExpr1a])
     direct2 = Directive("script-src", [DirectiveTest.sampleSrcExpr2])
     assert direct1.combinedDirective(direct2) == Directive.INVALID()
     assert direct2.combinedDirective(direct1) == Directive.INVALID()