Skip to content

Commit

Permalink
t: Extend unit-test for WebAPI::Auth::OpenID
Browse files Browse the repository at this point in the history
Tested with

```
rm -rf cover_db/ && cover -coverage stmt -test -make 'prove -Ilib t/03-auth-openid.t; echo 0' && html2text cover_db/lib-OpenQA-WebAPI-Auth-OpenID-pm.html
```

this can be used to extend further and cover more paths.
  • Loading branch information
okurz committed Mar 2, 2024
1 parent 5d8b505 commit 56875ca
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions t/03-auth-openid.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib";
use OpenQA::Test::TimeLimit '10';
use OpenQA::WebAPI::Auth::OpenID;


is OpenQA::WebAPI::Auth::OpenID::_first_last_name({'value.firstname' => 'Mordred'}), 'Mordred ',
'_first_last_name concats also with empty fields';
my $openid = OpenQA::WebAPI::Auth::OpenID->new();
my (%openid_res, %openid_res2);
my $vident = Test::MockObject->new->set_series('signed_extension_fields', \%openid_res, \%openid_res2);
$vident->{identity} = 'mordred';
my $mock = Test::MockModule->new('OpenQA::WebAPI::Auth::OpenID');
$mock->noop('_create_user');
$mock->mock('session', {});
ok $openid->_handle_verified($vident), 'can call _handle_verified';
my $users = Test::MockObject->new->set_always('create_user', 1);
my $schema = Test::MockObject->new->set_always(resultset => $users);
my %session;
my $c
= Test::MockObject->new->set_always(schema => $schema)->set_always(session => \%session)->set_true('_create_user');
ok OpenQA::WebAPI::Auth::OpenID::_handle_verified($c, $vident), 'can call _handle_verified';
$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(app => Test::MockObject->new->set_always(config => {})
->set_always(log => Test::MockObject->new->set_true('error', 'debug')))->set_true('flash');
is OpenQA::WebAPI::Auth::OpenID::auth_response($c), 0, 'can call auth_response';

done_testing;

0 comments on commit 56875ca

Please sign in to comment.