Bugzilla – Attachment 139820 Details for
Bug 31380
Build Mojolicious controller for running Koha plugins
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31380: Add unit tests
Bug-31380-Add-unit-tests.patch (text/plain), 3.38 KB, created by
Paul Derscheid
on 2022-08-26 09:08:05 UTC
(
hide
)
Description:
Bug 31380: Add unit tests
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2022-08-26 09:08:05 UTC
Size:
3.38 KB
patch
obsolete
>From 77c363031ccaa32acf4a6da3cf46d035dbf85e34 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Thu, 18 Aug 2022 06:57:42 +0000 >Subject: [PATCH] Bug 31380: Add unit tests > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> >--- > t/db_dependent/Koha/Auth.t | 92 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 92 insertions(+) > create mode 100755 t/db_dependent/Koha/Auth.t > >diff --git a/t/db_dependent/Koha/Auth.t b/t/db_dependent/Koha/Auth.t >new file mode 100755 >index 0000000000..b5f88a1a44 >--- /dev/null >+++ b/t/db_dependent/Koha/Auth.t >@@ -0,0 +1,92 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use C4::Auth qw( get_session ); >+use Test::More tests => 5; >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+ >+use_ok('Koha::Auth'); >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+subtest 'Successful authentication' => sub { >+ plan tests => 2; >+ >+ $ENV{REMOTE_ADDR} = '127.0.0.1'; >+ my $builder = t::lib::TestBuilder->new; >+ my $borrower = $builder->build({ source => 'Borrower' }); >+ my $session = C4::Auth::get_session; >+ $session->param( 'id', $borrower->{userid} ); >+ $session->param( 'lasttime', time() ); >+ $session->param( 'ip', '127.0.0.1' ); >+ $session->flush; >+ my $sessionID = $session->id; >+ >+ my ($user,$user_session) = Koha::Auth->authenticate({ >+ sessionID => $sessionID, >+ }); >+ is(ref $user, 'Koha::Patron', 'User found'); >+ is(ref $user_session, 'CGI::Session', 'User session found'); >+ >+ $session->delete; >+}; >+ >+subtest 'Failed authentication' => sub { >+ plan tests => 2; >+ >+ $ENV{REMOTE_ADDR} = '127.0.0.1'; >+ my $session = C4::Auth::get_session; >+ $session->flush; >+ $session->param( 'ip', '127.0.0.1' ); >+ my $sessionID = $session->id; >+ >+ my ($user,$user_session) = Koha::Auth->authenticate({ >+ sessionID => $sessionID, >+ }); >+ is($user, undef, 'User not found'); >+ is($user_session, undef, 'User session not found'); >+ >+ $session->delete; >+}; >+ >+subtest 'Superlibrarian authorization' => sub { >+ plan tests => 1; >+ my $builder = t::lib::TestBuilder->new; >+ my $borrower = $builder->build({ source => 'Borrower', value => {flags => 1,} }); >+ >+ my $session = C4::Auth::get_session; >+ $session->param( 'id', $borrower->{userid} ); >+ $session->param( 'lasttime', time() ); >+ $session->param( 'ip', '127.0.0.1' ); >+ $session->flush; >+ >+ my $flags = Koha::Auth->authorize({ >+ session => $session, >+ flagsrequired => { circulate => 1 }, >+ }); >+ is($flags->{superlibrarian},1,'Got superlibrarian authorization'); >+}; >+ >+subtest 'Circulation staff authorization' => sub { >+ plan tests => 2; >+ my $builder = t::lib::TestBuilder->new; >+ my $borrower = $builder->build({ source => 'Borrower', value => {flags => 2,} }); >+ >+ my $session = C4::Auth::get_session; >+ $session->param( 'id', $borrower->{userid} ); >+ $session->param( 'lasttime', time() ); >+ $session->param( 'ip', '127.0.0.1' ); >+ $session->flush; >+ >+ my $flags = Koha::Auth->authorize({ >+ session => $session, >+ flagsrequired => { circulate => 1 }, >+ }); >+ is($flags->{superlibrarian},0,'Did not get superlibrarian authorization'); >+ is($flags->{circulate},1,'Did get circulate authorization'); >+}; >+ >+$schema->storage->txn_rollback; >-- >2.31.1
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 31380
:
139308
|
139309
|
139312
|
139313
|
139314
|
139315
|
139316
|
139317
|
139318
|
139319
|
139320
|
139321
|
139322
|
139323
|
139324
|
139325
|
139327
|
139328
|
139394
|
139395
|
139396
|
139818
|
139819
|
139820
|
140673
|
140674
|
140675
|
144968
|
144969
|
144970
|
158583
|
158584