1 # Copyright (C) 2009, 2012 Alex Schroeder <alex@gnu.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 use Test::More tests => 18;
23 # Basic usage that broke when I last changed the cookie handling code.
24 test_page(get_page('username=Alex'), 'Status: 404');
25 test_page(get_page('action=browse id=Alex'), 'Alex');
28 test_page(get_page('action=browse id=HomePage username=Alex'), 'username=Alex');
29 test_page(get_page('action=browse id=HomePage username=01234567890123456789012345678901234567890123456789'),
30 'username=01234567890123456789012345678901234567890123456789');
31 test_page(get_page('action=browse id=HomePage username=01234567890123456789012345678901234567890123456789X'),
32 'UserName must be 50 characters or less: not saved');
33 test_page(get_page('action=browse id=HomePage username=AlexSchroeder'),
34 'username=AlexSchroeder');
35 test_page(get_page('action=browse id=HomePage username=Alex%20Schroeder'),
36 'username=Alex Schroeder');
37 AppendStringToFile($ConfigFile, "\$FreeLinks = 0;\n");
38 test_page(get_page('action=browse id=HomePage username=Alex%20Schroeder'),
39 'Invalid UserName Alex Schroeder: not saved');
40 test_page(get_page('action=browse id=HomePage username=AlexSchroeder'),
41 'username=AlexSchroeder');
42 test_page(get_page('action=browse id=HomePage username=Alex'),
43 'Invalid UserName Alex: not saved');
44 # single words are ok if we switch off $WikiLinks as well!
45 AppendStringToFile($ConfigFile, "\$WikiLinks = 0;\n");
46 test_page(get_page('action=browse id=HomePage username=Alex'),
52 eval { require LWP::UserAgent; };
53 skip "LWP::UserAgent not installed", 7 if $@;
55 eval { require HTTP::Cookies; };
56 skip "HTTP::Cookies not installed", 7 if $@;
58 my $wiki = 'http://localhost/cgi-bin/wiki.pl';
59 my $ua = LWP::UserAgent->new;
60 my $response = $ua->get("$wiki?action=version");
61 skip("No wiki running at $wiki", 7)
62 unless $response->is_success;
64 $ua = LWP::UserAgent->new;
65 my $cookie = HTTP::Cookies->new;
66 $ua ->cookie_jar($cookie);
69 $response = $ua->get("$wiki?action=debug;pwd=foo");
70 ok($response->is_success, 'request the page');
71 test_page($ua->cookie_jar->as_string, 'Set-Cookie.*: Wiki=pwd%251efoo');
72 test_page_negative($response->content, 'pwd');
75 $response = $ua->get("$wiki?action=debug;pwd=test");
76 test_page($ua->cookie_jar->as_string, 'Set-Cookie.*: Wiki=pwd%251etest');
79 $response = $ua->get("$wiki?action=debug;pwd=");
80 test_page($ua->cookie_jar->as_string, 'Set-Cookie.*: Wiki=""');
83 $response = $ua->get("$wiki?action=rc;username=Alex\%20Schr\%C3\%B6der");
84 test_page($ua->cookie_jar->as_string,
85 'Set-Cookie.*: Wiki=username%251eAlex%20Schr%C3%B6der');
86 test_page($response->decoded_content,
87 'Cookie: Wiki, username=Alex Schröder');