Bugzilla – Attachment 122489 Details for
Bug 28615
Add a simple way to mock Koha::Logger
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28615: Fix t/Auth_with_shibboleth.t
Bug-28615-Fix-tAuthwithshibboletht.patch (text/plain), 12.21 KB, created by
Kyle M Hall (khall)
on 2021-06-29 12:43:35 UTC
(
hide
)
Description:
Bug 28615: Fix t/Auth_with_shibboleth.t
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2021-06-29 12:43:35 UTC
Size:
12.21 KB
patch
obsolete
>From 7cb844dd6213aaaf04fb6527353aed054c00d980 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 28 Jun 2021 15:28:49 -0300 >Subject: [PATCH] Bug 28615: Fix t/Auth_with_shibboleth.t > >This patch makes t/Auth_with_shibboleth.t use the new >t::lib::Mocks::Logger tools > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/Auth_with_shibboleth.t | 178 +++++++++++++++++---------------------- > 1 file changed, 76 insertions(+), 102 deletions(-) > >diff --git a/t/Auth_with_shibboleth.t b/t/Auth_with_shibboleth.t >index 622fd161fd..17cbdc8856 100755 >--- a/t/Auth_with_shibboleth.t >+++ b/t/Auth_with_shibboleth.t >@@ -24,13 +24,15 @@ use Test::MockModule; > use Test::Warn; > use File::Temp qw(tempdir); > >+use t::lib::Mocks::Logger; >+ > use utf8; > use CGI qw(-utf8 ); > use C4::Context; > > BEGIN { > if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 17; >+ plan tests => 18; > } > else { > plan skip_all => "Need Test::DBIx::Class"; >@@ -89,10 +91,11 @@ $database->mock( 'schema', \&mockedSchema ); > # Tests > ############################################################## > >+my $logger = t::lib::Mocks::Logger->new(); >+ > # Can module load > use C4::Auth_with_shibboleth; > require_ok('C4::Auth_with_shibboleth'); >-$C4::Auth_with_shibboleth::debug = '0'; > > # Subroutine tests > ## shib_ok >@@ -117,7 +120,7 @@ subtest "shib_ok tests" => sub { > is( $result, '0', "bad config" ); > > # add test for undefined shibboleth block >- >+ $logger->clear; > reset_config(); > }; > >@@ -172,34 +175,24 @@ subtest "login_shib_url tests" => sub { > > ## get_login_shib > subtest "get_login_shib tests" => sub { >- plan tests => 4; >+ >+ plan tests => 3; >+ > my $login; > >- # good config >- ## debug off >- $C4::Auth_with_shibboleth::debug = '0'; >- warnings_are { $login = get_login_shib() }[], >- "good config with debug off, no warnings received"; >- is( $login, "test1234", >- "good config with debug off, attribute value returned" ); >- >- ## debug on >- $C4::Auth_with_shibboleth::debug = '1'; >- warnings_are { $login = get_login_shib() }[ >- "koha borrower field to match: userid", >- "shibboleth attribute to match: uid", >- "uid value: test1234" >- ], >- "good config with debug enabled, correct warnings received"; >- is( $login, "test1234", >- "good config with debug enabled, attribute value returned" ); >- >-# bad config - with shib_ok implemented, we should never reach this sub with a bad config >+ $login = get_login_shib(); >+ >+ $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: uid", "shib match attribute debug info") >+ ->clear(); >+ >+ is( $login, "test1234", "good config, attribute value returned" ); > }; > > ## checkpw_shib > subtest "checkpw_shib tests" => sub { >- plan tests => 24; >+ >+ plan tests => 33; > > my $shib_login; > my ( $retval, $retcard, $retuserid ); >@@ -216,48 +209,42 @@ subtest "checkpw_shib tests" => sub { > ], > 'Installed some custom fixtures via the Populate fixture class'; > >- # debug off >- $C4::Auth_with_shibboleth::debug = '0'; >- > # good user > $shib_login = "test1234"; >- warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [], "good user with no debug"; >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >+ >+ is( $logger->count(), 2, "Two debugging entries"); > is( $retval, "1", "user authenticated" ); > is( $retcard, "testcardnumber", "expected cardnumber returned" ); > is( $retuserid, "test1234", "expected userid returned" ); >+ $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: uid", "shib match attribute debug info") >+ ->clear(); > > # bad user > $shib_login = 'martin'; >- warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [], "bad user with no debug"; >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > is( $retval, "0", "user not authenticated" ); >+ $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: uid", "shib match attribute debug info") >+ ->clear(); > > # duplicated matchpoint > $matchpoint = 'email'; > $mapping{'email'} = { is => 'email' }; > $shib_login = 'kid@clamp.io'; >- warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [], "bad user with no debug"; >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > is( $retval, "0", "user not authenticated if duplicated matchpoint" ); >- $C4::Auth_with_shibboleth::debug = '1'; >- warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [ >- q/checkpw_shib/, >- q/koha borrower field to match: email/, >- q/shibboleth attribute to match: email/, >- q/User Shibboleth-authenticated as: kid@clamp.io/, >- q/There are several users with email of kid@clamp.io, matchpoints must be unique/ >- ], "duplicated matchpoint warned with debug"; >- $C4::Auth_with_shibboleth::debug = '0'; >+ $logger->debug_is("koha borrower field to match: email", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: email", "shib match attribute debug info") >+ ->clear(); >+ >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >+ $logger->debug_is("koha borrower field to match: email", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: email", "shib match attribute debug info") >+ ->warn_is('There are several users with email of kid@clamp.io, matchpoints must be unique', "duplicated matchpoint warned with debug") >+ ->clear(); >+ > reset_config(); > > # autocreate user >@@ -269,12 +256,14 @@ subtest "checkpw_shib tests" => sub { > $ENV{'cat'} = "S"; > $ENV{'add'} = 'Address'; > $ENV{'city'} = 'City'; >- warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [], "new user added with no debug"; >+ >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > is( $retval, "1", "user authenticated" ); > is( $retuserid, "test4321", "expected userid returned" ); >+ $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: uid", "shib match attribute debug info") >+ ->clear(); >+ > ok my $new_user = ResultSet('Borrower') > ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "new user found"; > is_fields [qw/surname dateexpiry address city/], $new_user->next, >@@ -285,10 +274,10 @@ subtest "checkpw_shib tests" => sub { > # sync user > $sync = 1; > $ENV{'city'} = 'AnotherCity'; >- warnings_are { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [], "good user with sync"; >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >+ $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: uid", "shib match attribute debug info") >+ ->clear(); > > ok my $sync_user = ResultSet('Borrower') > ->search( { 'userid' => 'test4321' }, { rows => 1 } ), "sync user found"; >@@ -298,40 +287,21 @@ subtest "checkpw_shib tests" => sub { > 'Found $sync_user synced city'; > $sync = 0; > >- # debug on >- $C4::Auth_with_shibboleth::debug = '1'; >- > # good user > $shib_login = "test1234"; >- warnings_exist { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [ >- qr/checkpw_shib/, >- qr/koha borrower field to match: userid/, >- qr/shibboleth attribute to match: uid/, >- qr/User Shibboleth-authenticated as:/ >- ], >- "good user with debug enabled"; >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > is( $retval, "1", "user authenticated" ); > is( $retcard, "testcardnumber", "expected cardnumber returned" ); > is( $retuserid, "test1234", "expected userid returned" ); >+ $logger->debug_is("koha borrower field to match: userid", "borrower match field debug info") >+ ->debug_is("shibboleth attribute to match: uid", "shib match attribute debug info") >+ ->clear(); > > # bad user > $shib_login = "martin"; >- warnings_exist { >- ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); >- } >- [ >- qr/checkpw_shib/, >- qr/koha borrower field to match: userid/, >- qr/shibboleth attribute to match: uid/, >- qr/User Shibboleth-authenticated as:/, >- qr/not a valid Koha user/ >- ], >- "bad user with debug enabled"; >+ ( $retval, $retcard, $retuserid ) = checkpw_shib($shib_login); > is( $retval, "0", "user not authenticated" ); >- >+ $logger->info_is("There are several users with userid of martin, matchpoints must be unique", "Duplicated matchpoint warned to info"); > }; > > ## _get_uri - opac >@@ -339,48 +309,52 @@ $OPACBaseURL = "testopac.com"; > is( C4::Auth_with_shibboleth::_get_uri(), > "https://testopac.com", "https opac uri returned" ); > >+$logger->clear; >+ > $OPACBaseURL = "http://testopac.com"; >-my $result; >-warnings_are { $result = C4::Auth_with_shibboleth::_get_uri() }[ >- "shibboleth interface: $interface", >-"Shibboleth requires OPACBaseURL/staffClientBaseURL to use the https protocol!" >-], >- "improper protocol - received expected warning"; >+my $result = C4::Auth_with_shibboleth::_get_uri(); > is( $result, "https://testopac.com", "https opac uri returned" ); >+$logger->warn_is("Shibboleth requires OPACBaseURL/staffClientBaseURL to use the https protocol!", "Improper protocol logged to warn") >+ ->clear(); > > $OPACBaseURL = "https://testopac.com"; > is( C4::Auth_with_shibboleth::_get_uri(), > "https://testopac.com", "https opac uri returned" ); > >+$logger->clear(); >+ > $OPACBaseURL = undef; >-warnings_are { $result = C4::Auth_with_shibboleth::_get_uri() } >-[ "shibboleth interface: $interface", "OPACBaseURL not set!" ], >- "undefined OPACBaseURL - received expected warning"; >+$result = C4::Auth_with_shibboleth::_get_uri(); > is( $result, "https://", "https $interface uri returned" ); > >+$logger->warn_is("Syspref staffClientBaseURL or OPACBaseURL not set!", "undefined OPACBaseURL - received expected warning") >+ ->clear(); >+ > ## _get_uri - intranet > $interface = 'intranet'; > $staffClientBaseURL = "teststaff.com"; > is( C4::Auth_with_shibboleth::_get_uri(), > "https://teststaff.com", "https $interface uri returned" ); > >+ >+$logger->clear; >+ > $staffClientBaseURL = "http://teststaff.com"; >-warnings_are { $result = C4::Auth_with_shibboleth::_get_uri() }[ >- "shibboleth interface: $interface", >-"Shibboleth requires OPACBaseURL/staffClientBaseURL to use the https protocol!" >-], >- "improper protocol - received expected warning"; >+$result = C4::Auth_with_shibboleth::_get_uri(); > is( $result, "https://teststaff.com", "https $interface uri returned" ); >+$logger->warn_is("Shibboleth requires OPACBaseURL/staffClientBaseURL to use the https protocol!") >+ ->clear; > > $staffClientBaseURL = "https://teststaff.com"; > is( C4::Auth_with_shibboleth::_get_uri(), > "https://teststaff.com", "https $interface uri returned" ); >+is( $logger->count(), 0, 'No logging' ); > > $staffClientBaseURL = undef; >-warnings_are { $result = C4::Auth_with_shibboleth::_get_uri() } >-[ "shibboleth interface: $interface", "staffClientBaseURL not set!" ], >- "undefined staffClientBaseURL - received expected warning"; >+$result = C4::Auth_with_shibboleth::_get_uri(); > is( $result, "https://", "https $interface uri returned" ); >+$logger->warn_is("Syspref staffClientBaseURL or OPACBaseURL not set!", "undefined staffClientBaseURL - received expected warning") >+ ->clear; > > ## _get_shib_config > # Internal helper function, covered in tests above >-- >2.30.1 (Apple Git-130)
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 28615
:
122306
|
122307
|
122480
|
122481
|
122484
|
122485
|
122488
| 122489 |
122496
|
122497