]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/meta.t
small security review and suggestions
[git.ikiwiki.info.git] / t / meta.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More;
5 use IkiWiki;
7 my $tmp = 't/tmp';
8 my $srcdir = "$tmp/in";
9 my $destdir = "$tmp/out";
11 my $installed = $ENV{INSTALLED_TESTS};
13 my @command;
14 if ($installed) {
15         @command = qw(ikiwiki);
16 }
17 else {
18         ok(! system("make -s ikiwiki.out"));
19         @command = qw(perl -I. ./ikiwiki.out
20                 --underlaydir=underlays/basewiki
21                 --set underlaydirbase=underlays
22                 --templatedir=templates);
23 }
25 push @command, qw(--plugin meta --disable-plugin htmlscrubber);
26 push @command, $srcdir, $destdir;
28 sub write_build_read_compare {
29         my ($pagename, $input, $expected_output) = @_;
30         ok(! system("mkdir -p $srcdir"), q{setup});
31         writefile("$pagename.mdwn", $srcdir, $input);
32         ok(! system(@command), q{build});
33         like(readfile("$destdir/$pagename/index.html"), $expected_output);
34         ok(! system("rm -rf $tmp"), q{teardown});
35 }
37 write_build_read_compare(
38         'title',
39         q{[[!meta title="a page about bar"]]},
40         qr{<title>a page about bar</title>},
41 );
43 write_build_read_compare(
44         'description',
45         q{[[!meta description="a page about bar"]]},
46         qr{<meta name="description" content="a page about bar" />},
47 );
49 write_build_read_compare(
50         'guid',
51         q{[[!meta guid="12345"]]},
52         qr{<meta name="guid" content="12345" />},
53 );
55 write_build_read_compare(
56         'license',
57         q{[[!meta license="you get to keep both pieces"]]},
58         qr{<div class="pagelicense">},
59 );
61 write_build_read_compare(
62         'copyright',
63         q{[[!meta copyright="12345"]]},
64         qr{<div class="pagecopyright">},
65 );
67 write_build_read_compare(
68         'enclosure',
69         q{[[!meta enclosure="ikiwiki/login-selector/wordpress.png"]]},
70         qr{<meta name="enclosure" content="/ikiwiki/login-selector/wordpress.png" />},
71 );
73 write_build_read_compare(
74         'author',
75         q{[[!meta author="Noodly J. Appendage"]]},
76         qr{<meta name="author" content="Noodly J. Appendage" />},
77 );
79 write_build_read_compare(
80         'authorurl',
81         q{[[!meta authorurl="http://noodly.appendage"]]},
82         qr{<meta name="authorurl" content="http://noodly.appendage" />},
83 );
85 write_build_read_compare(
86         'permalink',
87         q{[[!meta permalink="http://noodly.appendage"]]},
88         qr{<link rel="bookmark" href="http://noodly.appendage" />},
89 );
91 write_build_read_compare(
92         'date',
93         q{[[!meta date="12345"]]},
94         qr{<meta name="date" content="12345" />},
95 );
97 write_build_read_compare(
98         'updated',
99         q{[[!meta updated="12345"]]},
100         qr{<meta name="updated" content="12345" />},
101 );
103 #write_build_read_compare(
104 #       'stylesheet',
105 #       q{[[!meta stylesheet="wonka.css"]]},
106 #       qr{<link href="wonka.css"},
107 #);
109 #write_build_read_compare(
110 #       'script',
111 #       q{[[!meta script="wonka.js"]]},
112 #       qr{<link href="wonka.js"},
113 #);
115 write_build_read_compare(
116         'openid',
117         q{[[!meta openid="wonka.openid.example"]]},
118         qr{<link href="wonka\.openid\.example" rel="openid\.delegate" />},
119 );
121 write_build_read_compare(
122         'foaf',
123         q{[[!meta foaf="wonka.foaf.example"]]},
124         qr{<link rel="meta" type="application/rdf\+xml" title="FOAF"},
125 );
127 write_build_read_compare(
128         'redir',
129         q{[[!meta redir="http://wonka.redir.example"]]},
130         qr{<meta http-equiv="refresh" content="0; URL=http://wonka\.redir\.example" />},
131 );
133 #write_build_read_compare(
134 #       'link',
135 #       q{[[!meta link="http://wonka.link.example"]]},
136 #       qr{<link href="http://wonka\.link\.example" />},
137 #);
139 write_build_read_compare(
140         'name',
141         q{[[!meta name="thingy" value1="hi" value2="hello"]]},
142         qr{<meta name="thingy" value[0-9]{1}=".+?" value[0-9]{1}=".+?" />},
143 );
145 write_build_read_compare(
146         'keywords',
147         q{[[!meta keywords="word1,word2,word3"]]},
148         qr{<meta name="keywords" content="word1,word2,word3" />},
149 );
151 write_build_read_compare(
152         'arbitrary',
153         q{[[!meta moo="mooooo"]]},
154         qr{<meta name="moo" content="mooooo" />},
155 );
157 #write_build_read_compare(
158 #       'twittercard1',
159 #       '[[!meta twitter:card="player"]]',
160 #       qr{<meta name="twitter:card" content="player" />},
161 #);
163 write_build_read_compare(
164         'twittercard2',
165         '[[!meta name="twitter:card" content="player"]]',
166         qr{<meta name="twitter:card" content="player" />},
167 );
169 done_testing();