Bugzilla – Attachment 118348 Details for
Bug 20854
Redirect after logout with CAS 3.0 broken
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20854: Add more CAS tests
Bug-20854-Add-more-CAS-tests.patch (text/plain), 3.57 KB, created by
Tomás Cohen Arazi
on 2021-03-16 19:59:26 UTC
(
hide
)
Description:
Bug 20854: Add more CAS tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2021-03-16 19:59:26 UTC
Size:
3.57 KB
patch
obsolete
>From b44e35a080a6d51520c6210d63024a4f9254ab0d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 16 Mar 2021 16:46:14 -0300 >Subject: [PATCH] Bug 20854: Add more CAS tests > >This patch aims to add full test coverage for 'logout_cas' the way we do >it nowadays (in a subtest, mocking things, etc). It is provided as a >separate patch so we can test the follow-up tidy and see no behavior >change. > >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/Auth_with_cas.t >=> SUCCESS: Tests pass! >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests pass! >4. Apply the refactoring follow-up >5. Repeat 3 >=> SUCCESS: Tests still pass! >6. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Auth_with_cas.t | 61 +++++++++++++++++++++++++++++++--- > 1 file changed, 56 insertions(+), 5 deletions(-) > >diff --git a/t/db_dependent/Auth_with_cas.t b/t/db_dependent/Auth_with_cas.t >index 2f1075542ee..3038228e6a7 100755 >--- a/t/db_dependent/Auth_with_cas.t >+++ b/t/db_dependent/Auth_with_cas.t >@@ -18,6 +18,9 @@ > use Modern::Perl; > > use Test::More tests => 5; >+use Test::MockModule; >+use Test::MockObject; >+ > use CGI; > > use t::lib::Mocks; >@@ -63,8 +66,56 @@ is(C4::Auth_with_cas::_url_with_get_params($cgi, 'intranet'), > "$staff_base_url/cgi-bin/koha/circ/circulation-home.pl?bar=baz", > "Intranet URL should be returned when using intranet login (Bug 13507)"); > >-# logout parameter >-t::lib::Mocks::mock_preference('casServerVersion','3'); >-is(C4::Auth_with_cas::_fix_logout_url('https://mycasserver.url/logout/?url=https://mykoha.url'), >- 'https://mycasserver.url/logout/?service=https://mykoha.url', >- 'service parameter should be used on logout when Cas server is 3.0 or superior (Bug 20854)'); >+subtest 'logout_cas() tests' => sub { >+ >+ plan tests => 4; >+ >+ my $cas_url = "https://mycasserver.url"; >+ >+ my $auth_with_cas_mock = Test::MockModule->new('C4::Auth_with_cas'); >+ $auth_with_cas_mock->mock( '_get_cas_and_service', sub >+ { >+ my $cas = Test::MockObject->new(); >+ $cas->mock( 'logout_url', sub { >+ return "$cas_url/logout/?url=https://mykoha.url"; >+ }); >+ return ( $cas, "$cas_url?logout.x=1" ); >+ } >+ ); >+ >+ my $cas_version; >+ my $expected_logout_url; >+ >+ # Yeah, this gets funky >+ my $cgi_mock = Test::MockModule->new('CGI'); >+ $cgi_mock->mock( 'redirect', sub { >+ my ( $self, $url ) = @_; >+ return $url; >+ }); >+ >+ # Test CAS 2.0 behavior >+ $cas_version = 2; >+ $expected_logout_url = "$cas_url/logout/?url=https://mykoha.url"; >+ >+ my $redirect_output = ''; >+ close(STDOUT); >+ open(STDOUT, ">", \$redirect_output) or die "Error opening STDOUT"; >+ >+ t::lib::Mocks::mock_preference( 'casServerVersion', $cas_version ); >+ C4::Auth_with_cas::logout_cas( CGI->new, 'anything' ); >+ is( $redirect_output, $expected_logout_url, "The generated URL is correct (v$cas_version\.0)" ); >+ unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' ); >+ >+ # Test CAS 3.0 behavior >+ $redirect_output = ''; >+ close(STDOUT); >+ open(STDOUT, ">", \$redirect_output) or die "Error opening STDOUT"; >+ >+ $cas_version = 3; >+ $expected_logout_url = "$cas_url/logout/?service=https://mykoha.url"; >+ >+ t::lib::Mocks::mock_preference( 'casServerVersion', $cas_version ); >+ C4::Auth_with_cas::logout_cas( CGI->new, 'anything' ); >+ is( $redirect_output, $expected_logout_url, "The generated URL is correct (v$cas_version\.0)" ); >+ unlike( $redirect_output, qr/logout\.x\=1/, 'logout.x=1 gets removed' ); >+}; >-- >2.31.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20854
:
112561
|
118347
|
118348
|
118349
|
119789
|
119790
|
119791
|
119792