WWW_Tools.t 2.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4

use strict;
use warnings;
use English qw(-no_match_vars);
use File::Path qw(make_path rmtree);
use Test::More;

BEGIN {
    use_ok 'Sympa::WWW::Tools';
}

# get_robot()

%Conf::Conf = (
    domain      => 'mail.example.org',
    listmaster  => 'listmaster@example.org',
    wwsympa_url => 'http://web.example.org/sym/pa',
    etc         => 't/tmp/etc',
);
make_path $Conf::Conf{'etc'} or die $ERRNO;

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/sym/pa';
$ENV{PATH_INFO}   = undef;
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
    ['mail.example.org', '/sym/pa', ''],
    'SCRIPT_NAME & empty PATH_INFO';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/sym/pa';
$ENV{PATH_INFO}   = '/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
    ['mail.example.org', '/sym/pa', '/help'],
    'SCRIPT_NAME & non-empty PATH_INFO';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/sym';
$ENV{PATH_INFO}   = '/pa/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
    ['mail.example.org', '/sym/pa', '/help'],
    'split script-path (e.g. mod_proxy_fcgi on httpd)';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/sym/pa/help';
$ENV{PATH_INFO}   = undef;
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
    ['mail.example.org', '/sym/pa', '/help'],
    'no PATH_INFO (e.g. nginx without fastcgi_split_path_info)';

IKEDA Soji's avatar
IKEDA Soji committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$ENV{SERVER_NAME} = 'other.example.org';
$ENV{SCRIPT_NAME} = '/sym/pa';
$ENV{PATH_INFO}   = '/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')], [],
    'mismatch SERVER_NAME';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/sympa';
$ENV{PATH_INFO}   = '/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')], [],
    'mismatch SCRIPT_NAME';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = 'sym/pa';
$ENV{PATH_INFO}   = '/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')], [],
    'dubious SCRIPT_NAME';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/sym/pa/';
$ENV{PATH_INFO}   = 'help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')], [],
    'dubious PATH_INFO';

IKEDA Soji's avatar
IKEDA Soji committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
$Conf::Conf{wwsympa_url} = 'http://web.example.org';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '';
$ENV{PATH_INFO}   = '/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
    ['mail.example.org', '', '/help'],
    'URL prefix on the top: (empty) SCRIPT_NAME & non-empty PATH_INFO';

$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/help';
$ENV{PATH_INFO}   = undef;
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
    ['mail.example.org', '', '/help'],
    'URL prefix on the top: no PATH_INFO';

92
93
done_testing();
rmtree 't/tmp';