|
Lines 78-102
subtest 'logout_cas() tests' => sub {
Link Here
|
| 78 |
|
78 |
|
| 79 |
plan tests => 4; |
79 |
plan tests => 4; |
| 80 |
|
80 |
|
| 81 |
my $cas_url = "https://mycasserver.url"; |
81 |
my $cas_url = "https://mycasserver.url"; |
|
|
82 |
my $fixed_logout = "$cas_url/logout/?url=https://mykoha.url"; |
| 82 |
|
83 |
|
| 83 |
my $auth_with_cas_mock = Test::MockModule->new('C4::Auth_with_cas'); |
84 |
# Mock the CAS client to return a predictable logout URL |
| 84 |
$auth_with_cas_mock->mock( |
85 |
my $cas_client_mock = Test::MockObject->new(); |
| 85 |
'_get_cas_and_service', |
86 |
$cas_client_mock->mock( 'logout_url', sub { $fixed_logout } ); |
| 86 |
sub { |
87 |
|
| 87 |
my $cas = Test::MockObject->new(); |
88 |
my $authen_cas_mock = Test::MockModule->new('Authen::CAS::Client'); |
| 88 |
$cas->mock( |
89 |
$authen_cas_mock->mock( 'new', sub { $cas_client_mock } ); |
| 89 |
'logout_url', |
|
|
| 90 |
sub { |
| 91 |
return "$cas_url/logout/?url=https://mykoha.url"; |
| 92 |
} |
| 93 |
); |
| 94 |
return ( $cas, "$cas_url?logout.x=1" ); |
| 95 |
} |
| 96 |
); |
| 97 |
|
90 |
|
| 98 |
my $cas_version; |
91 |
# Mock a CAS identity provider so _get_cas_provider returns something useful |
| 99 |
my $expected_logout_url; |
92 |
my $mock_provider = Test::MockObject->new(); |
|
|
93 |
$mock_provider->mock( 'code', sub { 'test_cas' } ); |
| 94 |
|
| 95 |
my $auth_with_cas_mock = Test::MockModule->new('C4::Auth_with_cas'); |
| 96 |
$auth_with_cas_mock->mock( '_get_cas_provider', sub { $mock_provider } ); |
| 100 |
|
97 |
|
| 101 |
# Yeah, this gets funky |
98 |
# Yeah, this gets funky |
| 102 |
my $cgi_mock = Test::MockModule->new('CGI'); |
99 |
my $cgi_mock = Test::MockModule->new('CGI'); |
|
Lines 108-136
subtest 'logout_cas() tests' => sub {
Link Here
|
| 108 |
} |
105 |
} |
| 109 |
); |
106 |
); |
| 110 |
|
107 |
|
| 111 |
# Test CAS 2.0 behavior |
108 |
# Test CAS 2.0 behavior (version stored in provider config) |
| 112 |
$cas_version = 2; |
109 |
$mock_provider->mock( 'get_config', sub { { server_url => $cas_url, version => '2' } } ); |
| 113 |
$expected_logout_url = "$cas_url/logout/?url=https://mykoha.url"; |
110 |
my $expected_logout_url = $fixed_logout; # no substitution for v2 |
| 114 |
|
111 |
|
| 115 |
my $redirect_output = ''; |
112 |
my $redirect_output = ''; |
| 116 |
close(STDOUT); |
113 |
close(STDOUT); |
| 117 |
open( STDOUT, ">", \$redirect_output ) or die "Error opening STDOUT"; |
114 |
open( STDOUT, ">", \$redirect_output ) or die "Error opening STDOUT"; |
| 118 |
|
115 |
|
| 119 |
t::lib::Mocks::mock_preference( 'casServerVersion', $cas_version ); |
116 |
C4::Auth_with_cas::logout_cas( CGI->new, 'anything', 'test_cas' ); |
| 120 |
C4::Auth_with_cas::logout_cas( CGI->new, 'anything' ); |
117 |
is( $redirect_output, $expected_logout_url, "The generated URL is correct (v2.0)" ); |
| 121 |
is( $redirect_output, $expected_logout_url, "The generated URL is correct (v$cas_version\.0)" ); |
|
|
| 122 |
unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' ); |
118 |
unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' ); |
| 123 |
|
119 |
|
| 124 |
# Test CAS 3.0 behavior |
120 |
# Test CAS 3.0 behavior (url= replaced with service=) |
|
|
121 |
$mock_provider->mock( 'get_config', sub { { server_url => $cas_url, version => '3' } } ); |
| 122 |
$expected_logout_url = $fixed_logout =~ s/url=/service=/r; |
| 123 |
|
| 125 |
$redirect_output = ''; |
124 |
$redirect_output = ''; |
| 126 |
close(STDOUT); |
125 |
close(STDOUT); |
| 127 |
open( STDOUT, ">", \$redirect_output ) or die "Error opening STDOUT"; |
126 |
open( STDOUT, ">", \$redirect_output ) or die "Error opening STDOUT"; |
| 128 |
|
127 |
|
| 129 |
$cas_version = 3; |
128 |
C4::Auth_with_cas::logout_cas( CGI->new, 'anything', 'test_cas' ); |
| 130 |
$expected_logout_url = "$cas_url/logout/?service=https://mykoha.url"; |
129 |
is( $redirect_output, $expected_logout_url, "The generated URL is correct (v3.0)" ); |
| 131 |
|
|
|
| 132 |
t::lib::Mocks::mock_preference( 'casServerVersion', $cas_version ); |
| 133 |
C4::Auth_with_cas::logout_cas( CGI->new, 'anything' ); |
| 134 |
is( $redirect_output, $expected_logout_url, "The generated URL is correct (v$cas_version\.0)" ); |
| 135 |
unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' ); |
130 |
unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' ); |
| 136 |
}; |
131 |
}; |
| 137 |
- |
|
|