From e6f4c6880e9924860e9e831f1cdba4e618ae1f40 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 24 Jan 2022 14:19:24 +0000 Subject: [PATCH] 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 --- t/db_dependent/Auth.t | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index 79bf960f43..c925f1b7ba 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -442,7 +442,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 @@ -464,8 +464,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; -- 2.30.2