Skip to content

Commit

Permalink
Extend test coverage of OpenID.pm
Browse files Browse the repository at this point in the history
Cover setup_needed handling of OpenID respond.

Signed-off-by: Ioannis Bonatakis <[email protected]>
  • Loading branch information
b10n1k committed Sep 27, 2024
1 parent 0fbaef3 commit cad562b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/OpenQA/WebAPI/Auth/OpenID.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package OpenQA::WebAPI::Auth::OpenID;
use Mojo::Base -base, -signatures;

use OpenQA::Log qw(log_error log_warning);
use OpenQA::Log qw(log_error log_warning log_debug);
use LWP::UserAgent;
use Net::OpenID::Consumer;
use MIME::Base64 qw(encode_base64url decode_base64url);
Expand Down Expand Up @@ -116,7 +116,7 @@ sub auth_response ($c) {
setup_needed => sub ($setup_url) {
# Redirect the user to $setup_url
$setup_url = URI::Escape::uri_unescape($setup_url);
$c->app->log->debug(qq{setup_url[$setup_url]});
log_debug(qq{setup_url[$setup_url]});

return (redirect => $setup_url, error => 0);
},
Expand Down
18 changes: 18 additions & 0 deletions t/03-auth-openid.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,22 @@ stderr_like {
}
qr/Invalid OpenID/, 'warning about invalid OpenID is displayed';

$c->set_always(
req => Test::MockObject->new->set_always(params => Test::MockObject->new->set_always(pairs => [1, 2]))
->set_always(url => Test::MockObject->new->set_always(base => 'openqa'))
->set_always(log => Test::MockObject->new->set_true('error', 'debug'))->set_true('flash'));
my $mock_openid_consumer = Test::MockModule->new('Net::OpenID::Consumer');
$mock_openid_consumer->redefine('handle_server_response', sub {
my ($self, %res_handlers) = @_;
if ($res_handlers{setup_needed}) {
return $res_handlers{setup_needed}->("https://www.opensuse.org/openid/setup");
}
});

stdout_like {
my $ret = OpenQA::WebAPI::Auth::OpenID::auth_response($c);
is_deeply($ret, 0, 'can handle setup_needed response');
}
qr/setup_url\[https:\/\/www.opensuse.org\/openid\/setup\]/, 'debug log is displayed when setup_needed';

done_testing;

0 comments on commit cad562b

Please sign in to comment.