Bug 29914: (QA follow-up) Expand tests to cover failure case before patches

When asking for permissions we get 'failed', without we get 'ok'
Adding explicit checks for not 'ok'

Add a FIXME:
We should cover the case where we return 'failed' after changes, but that is a larger undertaking

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit e956130f8f)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
(cherry picked from commit 723928fbc84b1552814e8111372e5fb1f850364e)

Signed-off-by: Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz>
This commit is contained in:
Nick Clemens 2022-01-24 14:19:24 +00:00 committed by Wainui Witika-Park
parent 753c03f214
commit 866a5a36ba
1 changed files with 12 additions and 3 deletions

View File

@ -411,7 +411,7 @@ subtest '_timeout_syspref' => sub {
};
subtest 'check_cookie_auth' => sub {
plan tests => 1;
plan tests => 4;
t::lib::Mocks::mock_preference('timeout', "1d"); # back to default
@ -433,8 +433,17 @@ subtest 'check_cookie_auth' => sub {
# Setting authnotrequired=1 or we wont' hit the return but the end of the sub that prints headers
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 1 );
my ($auth_status, $session) = C4::Auth::check_cookie_auth($sessionID, {catalogue => 1});
is( $auth_status, 'anon', 'check_cookie_auth should not return ok if the user has not been authenticated before' );
my ($auth_status, $session) = C4::Auth::check_cookie_auth($sessionID);
isnt( $auth_status, 'ok', 'check_cookie_auth should not return ok if the user has not been authenticated before if no permissions needed' );
is( $auth_status, 'anon', 'check_cookie_auth should return anon if the user has not been authenticated before and no permissions needed' );
( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 1 );
($auth_status, $session) = C4::Auth::check_cookie_auth($sessionID, {catalogue => 1});
isnt( $auth_status, 'ok', 'check_cookie_auth should not return ok if the user has not been authenticated before and permissions needed' );
is( $auth_status, 'anon', 'check_cookie_auth should return anon if the user has not been authenticated before and permissions needed' );
#FIXME We should have a test to cover 'failed' status when a user has logged in, but doesn't have permission
};
$schema->storage->txn_rollback;