コード例 #1
0
ファイル: ParserTest.java プロジェクト: ikarienator/salvation
 @Test
 public void testDuplicates() throws ParseException, TokeniserException {
   Policy p;
   p = parse("img-src a ;;; img-src b");
   assertNotNull("policy should not be null", p);
   assertEquals("", 1, p.getDirectives().size());
   Directive<?> firstDirective = p.getDirectives().iterator().next();
   ImgSrcDirective imgSrcDirective = p.getDirectiveByType(ImgSrcDirective.class);
   assertNotNull(imgSrcDirective);
   assertTrue(firstDirective instanceof ImgSrcDirective);
   assertEquals("", imgSrcDirective, (ImgSrcDirective) firstDirective);
   assertEquals("", "img-src", ImgSrcDirective.name);
   assertEquals("", "img-src a", imgSrcDirective.show());
 }
コード例 #2
0
ファイル: ParserTest.java プロジェクト: ikarienator/salvation
  @Test
  public void testDirectiveNameParsing() throws ParseException, TokeniserException {
    Policy p;

    p = parse("font-src a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("form-action a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("frame-ancestors 'none'");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("frame-src a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("img-src a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("media-src a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("object-src a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("plugin-types */*");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("report-uri https://example.com/report");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("sandbox allow-scripts");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("script-src a");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("style-src http://*.example.com:*");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    p = parse("style-src samba://*.example.com");
    assertNotNull("policy should not be null", p);
    assertEquals("directive count", 1, p.getDirectives().size());

    failsToParse("abc");
    failsToParse("zzscript-src *; bla");
  }