7 use Test
::More tests
=> 29;
12 use lib
$FindBin::Bin
;
13 use_ok
('C4::Scrubber');
18 (@_) or return "#" x
$max . "\n";
19 my $phrase = " " . shift() . " ";
20 my $half = "#" x
(($max - length($phrase))/2);
21 return $half . $phrase . $half . "\n";
24 my ($scrubber,$html,$result,@types,$collapse);
26 @types = qw(default comment tag staff);
28 <![CDATA
[selfdestruct
]]]>
29 <?php echo
(" EVIL EVIL EVIL "); ?
> <!-- COMMENT
-->
30 <hr
> <!-- TMPL_VAR NAME
="password" -->
31 <style type
="text/css">body
{display
:none
;}</style
>
32 <link media
="screen" type
="text/css" rev
="stylesheet" rel
="stylesheet" href
="css.css">
33 <I FAKE
="attribute" > I am ITALICS with fake
="attribute" </I><br />
34 <em FAKE
="attribute" > I am em with fake
="attribute" </em><br />
35 <B
> I am BOLD
</B><br />
36 <span style
="background-image: url(http://hackersite.cn/porno.jpg);"> I am a span w
/ style
. Bad style
.</span
>
37 <span
> I am a span trying to inject a
link: <a href
="badlink.html"> link </a></span
>
40 <A HREF
="javascript:alert('OMG YOO R HACKED');">I am a
link firing javascript
.</A
>
42 <A HREF
="image/bigone.jpg" ONMOUSEOVER
="alert('OMG YOO R HACKED');">
43 <IMG SRC
="image/smallone.jpg" ALT
="ONMOUSEOVER JAVASCRIPT">
46 At the end here
, I actually have some regular text
.
49 ok
($scrubber = C4
::Scrubber
->new(), "Constructor: C4::Scrubber->new()");
51 isa_ok
($scrubber, 'HTML::Scrubber', 'Constructor returns HTML::Scrubber object');
53 warning_like
{ $scrubber->default() } '', "\$scrubber->default ran without fault.";
54 warning_like
{ $scrubber->comment() } '', "\$scrubber->comment ran without fault.";
55 warning_like
{ $scrubber->process() } '', "\$scrubber->process ran without fault.";
57 ok
($result = $scrubber->scrub($html), "Getting scrubbed text (type: [default])");
60 ok
($scrubber = C4
::Scrubber
->new($_), "testing Constructor: C4::Scrubber->new($_)");
62 warning_like
{ $scrubber->default() } '', "\$scrubber->default ran without fault.";
63 warning_like
{ $scrubber->comment() } '', "\$scrubber->comment ran without fault.";
64 warning_like
{ $scrubber->process() } '', "\$scrubber->process ran without fault.";
66 ok
($result = $scrubber->scrub($html), "Getting scrubbed text (type: $_)");
69 #Test for invalid new entry
71 C4
::Scrubber
->new("");
72 fail
("test should fail on entry of ''");
75 pass
("Test should have failed on entry of '' (empty string) and it did. YAY!");
79 C4
::Scrubber
->new("Client");
80 fail
("test should fail on entry of 'Client'");
83 pass
("Test should have failed on entry of 'Client' and it did. YAY!");