6 use Test::More tests => 31;
11 use lib $FindBin::Bin;
12 use_ok('C4::Scrubber');
17 (@_) or return "#" x $max . "\n";
18 my $phrase = " " . shift() . " ";
19 my $half = "#" x (($max - length($phrase))/2);
20 return $half . $phrase . $half . "\n";
23 my ($scrubber,$html,$result,@types,$collapse);
25 @types = qw(default comment tag staff);
27 <![CDATA[selfdestruct]]]>
28 <?php echo(" EVIL EVIL EVIL "); ?> <!-- COMMENT -->
29 <hr> <!-- TMPL_VAR NAME="password" -->
30 <style type="text/css">body{display:none;}</style>
31 <link media="screen" type="text/css" rev="stylesheet" rel="stylesheet" href="css.css">
32 <I FAKE="attribute" > I am ITALICS with fake="attribute" </I><br />
33 <em FAKE="attribute" > I am em with fake="attribute" </em><br />
34 <B> I am BOLD </B><br />
35 <span style="background-image: url(http://hackersite.cn/porno.jpg);"> I am a span w/ style. Bad style.</span>
36 <span> I am a span trying to inject a link: <a href="badlink.html"> link </a></span>
39 <A HREF="javascript:alert('OMG YOO R HACKED');">I am a link firing javascript.</A>
41 <A HREF="image/bigone.jpg" ONMOUSEOVER="alert('OMG YOO R HACKED');">
42 <IMG SRC="image/smallone.jpg" ALT="ONMOUSEOVER JAVASCRIPT">
45 At the end here, I actually have some regular text.
48 ok($scrubber = C4::Scrubber->new(), "Constructor: C4::Scrubber->new()");
50 isa_ok($scrubber, 'HTML::Scrubber', 'Constructor returns HTML::Scrubber object');
52 warning_like { $scrubber->default() } '', "\$scrubber->default ran without fault.";
53 warning_like { $scrubber->comment() } '', "\$scrubber->comment ran without fault.";
54 warning_like { $scrubber->process() } '', "\$scrubber->process ran without fault.";
56 ok($result = $scrubber->scrub($html), "Getting scrubbed text (type: [default])");
59 ok($scrubber = C4::Scrubber->new($_), "testing Constructor: C4::Scrubber->new($_)");
61 warning_like { $scrubber->default() } '', "\$scrubber->default ran without fault.";
62 warning_like { $scrubber->comment() } '', "\$scrubber->comment ran without fault.";
63 warning_like { $scrubber->process() } '', "\$scrubber->process ran without fault.";
65 ok($result = $scrubber->scrub($html), "Getting scrubbed text (type: $_)");
68 #Test for invalid new entry
70 C4::Scrubber->new("");
71 fail("test should fail on entry of ''");
74 pass("Test should have failed on entry of '' (empty string) and it did. YAY!");
78 C4::Scrubber->new("Client");
79 fail("test should fail on entry of 'Client'");
82 pass("Test should have failed on entry of 'Client' and it did. YAY!");
86 '<div><span><p><b>bold</b><i>ital</i><em>emphatic</em><big>embiggen</big><small>shrink</small><strong>strongbad</strong><br><u>under</u><hr></p></span></div>';
88 '<b>bold</b><i>ital</i><em>emphatic</em><big>embiggen</big><small>shrink</small><strong>strongbad</strong><br>under';
89 is( C4::Scrubber->new('comment')->scrub($scrub_text), $scrub_comment, "Comment scrubber removes expected elements" );
91 C4::Scrubber->new('note')->scrub($scrub_text), $scrub_text,
92 "Note scrubber removes (additional) expected elements"