9 plan(skip_all => "Authen::Passphrase not available")
11 use Authen::Passphrase qw();
15 plan(skip_all => "CGI not available")
21 plan(skip_all => "IPC::Run not available")
28 use_ok('IkiWiki::Plugin::passwordauth');
29 use_ok('IkiWiki::Setup');
30 use_ok('IkiWiki::UserInfo');
34 # We check for English messages
37 my $installed = $ENV{INSTALLED_TESTS};
41 @command = qw(ikiwiki);
44 ok(! system("make -s ikiwiki.out"));
45 @command = ("perl", "-I".getcwd."/blib/lib", './ikiwiki.out',
46 '--underlaydir='.getcwd.'/underlays/basewiki',
47 '--set', 'underlaydirbase='.getcwd.'/underlays',
48 '--templatedir='.getcwd.'/templates');
51 sub write_setup_file {
53 wikiname => 'this is the name of my wiki',
54 srcdir => getcwd.'/t/tmp/in',
55 destdir => getcwd.'/t/tmp/out',
56 url => 'http://example.com',
57 cgiurl => 'http://example.com/cgi-bin/ikiwiki.cgi',
58 cgi_wrapper => getcwd.'/t/tmp/ikiwiki.cgi',
59 cgi_wrappermode => '0751',
60 add_plugins => [qw(anonok attachment lockedit passwordauth recentchanges)],
61 adminuser => [qw(alice)],
62 disable_plugins => [qw(emailauth openid)],
66 $setup{ENV} = { 'PERL5LIB' => getcwd.'/blib/lib' };
68 writefile("test.setup", "t/tmp",
69 "# IkiWiki::Setup::Yaml - YAML formatted setup file\n" .
71 %IkiWiki::config = IkiWiki::defaultconfig();
72 IkiWiki::Setup::load("t/tmp/test.setup");
73 IkiWiki::loadplugins();
74 IkiWiki::checkconfig();
77 sub thoroughly_rebuild {
78 ok(unlink("t/tmp/ikiwiki.cgi") || $!{ENOENT});
79 ok(unlink("t/tmp/in/.git/hooks/post-commit") || $!{ENOENT});
80 ok(! system(@command, qw(--setup t/tmp/test.setup --rebuild --wrappers)));
86 my $method = $args{method} || 'GET';
87 my $environ = $args{environ} || {};
88 my $params = $args{params} || { do => 'prefs' };
91 SCRIPT_NAME => '/cgi-bin/ikiwiki.cgi',
92 HTTP_HOST => 'example.com',
95 my $cgi = CGI->new($args{params});
96 my $query_string = $cgi->query_string();
98 if ($method eq 'POST') {
99 $defaults{REQUEST_METHOD} = 'POST';
101 $defaults{CONTENT_LENGTH} = length $in;
103 $defaults{REQUEST_METHOD} = 'GET';
104 $defaults{QUERY_STRING} = $query_string;
111 print("# $query_string\n");
112 run(["./t/tmp/ikiwiki.cgi"], \$in, \$out, init => sub {
114 $ENV{$_} = $envvars{$_}
125 IkiWiki::userinfo_setall('alice', {regdate => time, email => 'alice@example.com'});
126 IkiWiki::userinfo_setall('bob', {regdate => time, email => 'bob@example.com'});
127 IkiWiki::userinfo_setall('name', {regdate => time, email => 'nobody@example.com'});
128 IkiWiki::Plugin::passwordauth::setpassword('alice', "Alice's password");
129 IkiWiki::Plugin::passwordauth::setpassword('bob', "Bob's password");
137 # prefs requires signing in so we are redirected, with the postsignin
138 # action saved in the session
139 like($content, qr/<form .*name="signin"/);
141 # remember the cookie so we can continue to act in that session
142 my ($cookie) = ($content =~ m/^Set-Cookie: (.*)$/im);
147 HTTP_COOKIE => $cookie,
152 password => "Bob's password",
154 _submitted_signin => '1',
158 # We are signed-in as bob now
159 like($content, qr{page=bob.*Create your user page});
160 like($content, qr{<input.*name="name".*value="bob"});
161 like($content, qr{<input.*name="email".*value="bob\@example.com"});
164 sub test_formbuilder_disaster {
168 ok(! system(qw(rm -rf t/tmp)));
169 ok(! system(qw(mkdir t/tmp)));
170 ok(! system(qw(mkdir t/tmp/in)));
173 thoroughly_rebuild();
175 IkiWiki::userinfo_setall('alice', {regdate => time, email => 'alice@example.com'});
176 IkiWiki::userinfo_setall('bob', {regdate => time, email => 'bob@example.com'});
177 IkiWiki::userinfo_setall('name', {regdate => time, email => 'nobody@example.com'});
178 IkiWiki::Plugin::passwordauth::setpassword('alice', "Alice's password");
179 IkiWiki::Plugin::passwordauth::setpassword('bob', "Bob's password");
187 # prefs requires signing in so we are redirected, with the postsignin
188 # action saved in the session
189 like($content, qr/<form .*name="signin"/);
191 # remember the cookie so we can continue to act in that session
192 my ($cookie) = ($content =~ m/^Set-Cookie: (.*)$/im);
197 HTTP_COOKIE => $cookie,
201 name => ['bob', 'name', 'alice'],
202 password => "Bob's password",
204 _submitted_signin => '1',
208 like($content, qr{page=bob.*Create your user page});
209 like($content, qr{<input.*name="name".*value="bob"});
210 like($content, qr{<input.*name="email".*value="bob\@example.com"});
212 unlike($content, qr{alice});
215 ok(! system(qw(rm -rf t/tmp)));
216 ok(! system(qw(mkdir t/tmp)));
217 ok(! system(qw(mkdir t/tmp/in)));
220 thoroughly_rebuild();
223 test_formbuilder_disaster();