Files
oddmuse/t/cookie.t
Alex Schroeder 007ce8db86 cookie.t: no longer hardcode the wiki name
Changed the tests to no longer assume the default value for
$CookieName. This is important when running the tests on a system
where Apache starts a number of wikis for various virtual hosts and
one of them will end up as the host to use for http://localhost/. That
wiki might very well have a cookie name set.
2014-09-23 22:17:47 +02:00

90 lines
3.5 KiB
Perl
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (C) 20092014 Alex Schroeder <alex@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require 't/test.pl';
package OddMuse;
use Test::More tests => 18;
use utf8;
clear_pages();
# Basic usage that broke when I last changed the cookie handling code.
test_page(get_page('username=Alex'), 'Status: 404');
test_page(get_page('action=browse id=Alex'), 'Alex');
# Username
test_page(get_page('action=browse id=HomePage username=Alex'), 'username=Alex');
test_page(get_page('action=browse id=HomePage username=01234567890123456789012345678901234567890123456789'),
'username=01234567890123456789012345678901234567890123456789');
test_page(get_page('action=browse id=HomePage username=01234567890123456789012345678901234567890123456789X'),
'UserName must be 50 characters or less: not saved');
test_page(get_page('action=browse id=HomePage username=AlexSchroeder'),
'username=AlexSchroeder');
test_page(get_page('action=browse id=HomePage username=Alex%20Schroeder'),
'username=Alex Schroeder');
AppendStringToFile($ConfigFile, "\$FreeLinks = 0;\n");
test_page(get_page('action=browse id=HomePage username=Alex%20Schroeder'),
'Invalid UserName Alex Schroeder: not saved');
test_page(get_page('action=browse id=HomePage username=AlexSchroeder'),
'username=AlexSchroeder');
test_page(get_page('action=browse id=HomePage username=Alex'),
'Invalid UserName Alex: not saved');
# single words are ok if we switch off $WikiLinks as well!
AppendStringToFile($ConfigFile, "\$WikiLinks = 0;\n");
test_page(get_page('action=browse id=HomePage username=Alex'),
'username=Alex');
SKIP: {
eval { require LWP::UserAgent; };
skip "LWP::UserAgent not installed", 7 if $@;
eval { require HTTP::Cookies; };
skip "HTTP::Cookies not installed", 7 if $@;
my $wiki = 'http://localhost/cgi-bin/wiki.pl';
my $ua = LWP::UserAgent->new;
my $response = $ua->get("$wiki?action=version");
skip("No wiki running at $wiki", 7)
unless $response->is_success;
$ua = LWP::UserAgent->new;
my $cookie = HTTP::Cookies->new;
$ua ->cookie_jar($cookie);
# Set the cookie
$response = $ua->get("$wiki?action=debug;pwd=foo");
ok($response->is_success, 'request the page');
$ua->cookie_jar->as_string =~ /Set-Cookie.*: ([^=]+)=pwd%251efoo/;
my $cookie = $1;
ok($cookie, 'pwd was set in the cookie');
test_page_negative($response->content, 'pwd');
# Change the cookie
$response = $ua->get("$wiki?action=debug;pwd=test");
test_page($ua->cookie_jar->as_string, qq{Set-Cookie.*: $cookie=pwd%251etest});
# Delete the cookie
$response = $ua->get("$wiki?action=debug;pwd=");
test_page($ua->cookie_jar->as_string, qq{Set-Cookie.*: $cookie=""});
# Encoding issues
$response = $ua->get("$wiki?action=rc;username=Alex\%20Schr\%C3\%B6der");
test_page($ua->cookie_jar->as_string,
qq{Set-Cookie.*: $cookie=username%251eAlex%20Schr%C3%B6der});
test_page($response->decoded_content,
qq{Cookie: $cookie, username=Alex Schröder});
};