View | Details | Raw Unified | Return to bug 20854
Collapse All | Expand All

(-)a/t/db_dependent/Auth_with_cas.t (-6 / +56 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 5;
21
use Test::MockModule;
22
use Test::MockObject;
23
21
use CGI;
24
use CGI;
22
25
23
use t::lib::Mocks;
26
use t::lib::Mocks;
Lines 63-70 is(C4::Auth_with_cas::_url_with_get_params($cgi, 'intranet'), Link Here
63
    "$staff_base_url/cgi-bin/koha/circ/circulation-home.pl?bar=baz",
66
    "$staff_base_url/cgi-bin/koha/circ/circulation-home.pl?bar=baz",
64
   "Intranet URL should be returned when using intranet login (Bug 13507)");
67
   "Intranet URL should be returned when using intranet login (Bug 13507)");
65
68
66
# logout parameter
69
subtest 'logout_cas() tests' => sub {
67
t::lib::Mocks::mock_preference('casServerVersion','3');
70
68
is(C4::Auth_with_cas::_fix_logout_url('https://mycasserver.url/logout/?url=https://mykoha.url'),
71
    plan tests => 4;
69
    'https://mycasserver.url/logout/?service=https://mykoha.url',
72
70
    'service parameter should be used on logout when Cas server is 3.0 or superior (Bug 20854)');
73
    my $cas_url = "https://mycasserver.url";
74
75
    my $auth_with_cas_mock = Test::MockModule->new('C4::Auth_with_cas');
76
    $auth_with_cas_mock->mock( '_get_cas_and_service', sub
77
        {
78
            my $cas = Test::MockObject->new();
79
            $cas->mock( 'logout_url', sub {
80
                return "$cas_url/logout/?url=https://mykoha.url";
81
            });
82
            return ( $cas, "$cas_url?logout.x=1" );
83
        }
84
    );
85
86
    my $cas_version;
87
    my $expected_logout_url;
88
89
    # Yeah, this gets funky
90
    my $cgi_mock = Test::MockModule->new('CGI');
91
    $cgi_mock->mock( 'redirect', sub {
92
        my ( $self, $url ) = @_;
93
        return $url;
94
    });
95
96
    # Test CAS 2.0 behavior
97
    $cas_version = 2;
98
    $expected_logout_url = "$cas_url/logout/?url=https://mykoha.url";
99
100
    my $redirect_output = '';
101
    close(STDOUT);
102
    open(STDOUT, ">", \$redirect_output) or die "Error opening STDOUT";
103
104
    t::lib::Mocks::mock_preference( 'casServerVersion', $cas_version );
105
    C4::Auth_with_cas::logout_cas( CGI->new, 'anything' );
106
    is( $redirect_output, $expected_logout_url, "The generated URL is correct (v$cas_version\.0)" );
107
    unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' );
108
109
    # Test CAS 3.0 behavior
110
    $redirect_output = '';
111
    close(STDOUT);
112
    open(STDOUT, ">", \$redirect_output) or die "Error opening STDOUT";
113
114
    $cas_version = 3;
115
    $expected_logout_url = "$cas_url/logout/?service=https://mykoha.url";
116
117
    t::lib::Mocks::mock_preference( 'casServerVersion', $cas_version );
118
    C4::Auth_with_cas::logout_cas( CGI->new, 'anything' );
119
    is( $redirect_output, $expected_logout_url, "The generated URL is correct (v$cas_version\.0)" );
120
    unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' );
121
};
71
- 

Return to bug 20854