Bugzilla – Attachment 119833 Details for
Bug 27305
Use low privileged tokens to enable authenticated iCal feed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27305: Use low privilege tokens to enable authenticated iCal feed
Bug-27305-Use-low-privilege-tokens-to-enable-authe.patch (text/plain), 23.74 KB, created by
David Cook
on 2021-04-19 07:04:23 UTC
(
hide
)
Description:
Bug 27305: Use low privilege tokens to enable authenticated iCal feed
Filename:
MIME Type:
Creator:
David Cook
Created:
2021-04-19 07:04:23 UTC
Size:
23.74 KB
patch
obsolete
>From c52e219a8efed30a9b2e00041d02e59c67787437 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Mon, 19 Apr 2021 03:33:56 +0000 >Subject: [PATCH] Bug 27305: Use low privilege tokens to enable authenticated > iCal feed > >With the push of Bug 21325, it is no longer possible to authenticate >via a GET request using username and password. While this is an >improvement in security, it does mean that calendars like >Google Calendar cannot consume private iCal feeds from Koha. > >This patch allows the autogeneration of unique tokens for users >so that they can access their iCal feeds without their username/password. > >These tokens are pre-authenticated in opac-ics.pl and then passed >to C4::Auth::checkauth() via get_template_and_user() for verification >thanks to two very small changes in C4::Auth. > >Test plan: >1) Apply patch >2) Upgrade database (koha-upgrade-schema koha-dev) >3) Checkout item to patron (e.g. 39999000001310 to koha patron) >4) Log into /cgi-bin/koha/opac-user.pl >5) Right click iCal and copy link (e.g. >http://localhost:8080/cgi-bin/koha/opac-ics.pl?token=facb63f231ecba45bc70aadedfdd045b) >6) Log out of OPAC >7) Go to iCal link >http://localhost:8080/cgi-bin/koha/opac-ics.pl?token=facb63f231ecba45bc70aadedfdd045b >8) Observe that iCal download is performed >9) Go to OPAC home page (e.g. http://localhost:8080/cgi-bin/koha/opac-main.pl) >10) Note that you are not logged into the OPAC >(FYI this is because opac-ics.pl does not send back a cookie. If it did, then >you would be logged into the OPAC.) >--- > C4/Auth.pm | 14 ++- > Koha/Auth/Shim.pm | 106 +++++++++++++++++++++ > Koha/Auth/Type/Token/Ical.pm | 61 ++++++++++++ > Koha/Patron.pm | 33 +++++++ > .../bug27305-use-app-token-for-ical.perl | 14 +++ > .../data/mysql/en/mandatory/patron_attributes.yml | 34 +++++++ > .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 6 +- > opac/opac-ics.pl | 20 +++- > opac/opac-user.pl | 5 + > t/db_dependent/Auth.t | 34 ++++++- > t/db_dependent/Koha/Auth/Shim.t | 52 ++++++++++ > t/db_dependent/Koha/Auth/Type/Token/Ical.t | 61 ++++++++++++ > t/db_dependent/Koha/Patron.t | 18 +++- > 13 files changed, 453 insertions(+), 5 deletions(-) > create mode 100644 Koha/Auth/Shim.pm > create mode 100644 Koha/Auth/Type/Token/Ical.pm > create mode 100644 installer/data/mysql/atomicupdate/bug27305-use-app-token-for-ical.perl > create mode 100644 installer/data/mysql/en/mandatory/patron_attributes.yml > create mode 100644 t/db_dependent/Koha/Auth/Shim.t > create mode 100644 t/db_dependent/Koha/Auth/Type/Token/Ical.t > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 1d79561533..c5fa59eb33 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -150,6 +150,7 @@ Output.pm module. > sub get_template_and_user { > > my $in = shift; >+ my $extensions = shift // {}; > my ( $user, $cookie, $sessionID, $flags ); > > # Get shibboleth login attribute >@@ -168,6 +169,10 @@ sub get_template_and_user { > ); > > if ( $in->{'template_name'} !~ m/maintenance/ ) { >+ my $checkauth_extensions = {}; >+ if ( $extensions && ref $extensions eq 'HASH' ){ >+ $checkauth_extensions = $extensions->{checkauth}; >+ } > ( $user, $cookie, $sessionID, $flags ) = checkauth( > $in->{'query'}, > $in->{'authnotrequired'}, >@@ -175,6 +180,7 @@ sub get_template_and_user { > $in->{'type'}, > undef, > $in->{template_name}, >+ $checkauth_extensions, > ); > } > >@@ -817,8 +823,14 @@ sub checkauth { > my $type = shift; > my $emailaddress = shift; > my $template_name = shift; >+ my $extensions = shift // {}; > $type = 'opac' unless $type; > >+ my $check_sessionID = $query->cookie("CGISESSID"); >+ if ($extensions && ref $extensions eq 'HASH' && $extensions->{sessionID}){ >+ $check_sessionID = $extensions->{sessionID}; >+ } >+ > unless ( C4::Context->preference("OpacPublic") ) { > my @allowed_scripts_for_private_opac = qw( > opac-memberentry.tt >@@ -875,7 +887,7 @@ sub checkauth { > elsif ( $emailaddress) { > # the Google OpenID Connect passes an email address > } >- elsif ( $sessionID = $query->cookie("CGISESSID") ) >+ elsif ( $sessionID = $check_sessionID ) > { # assignment, not comparison > $session = get_session($sessionID); > C4::Context->_new_userenv($sessionID); >diff --git a/Koha/Auth/Shim.pm b/Koha/Auth/Shim.pm >new file mode 100644 >index 0000000000..f49099f8c4 >--- /dev/null >+++ b/Koha/Auth/Shim.pm >@@ -0,0 +1,106 @@ >+package Koha::Auth::Shim; >+ >+# Copyright 2021 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+ >+use Modern::Perl; >+ >+use C4::Auth; >+use C4::Context; >+use Koha::Patrons; >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=head3 cgi_is_authenticated >+ >+ This method checks if there is a CGISESSID and if the associated session >+ exists and has a patron attached to it. >+ >+=cut >+ >+#NOTE: CGI >+sub cgi_is_authenticated { >+ my ($class,$args) = @_; >+ my $is_authenticated; >+ my $cgi = $args->{cgi}; >+ if ($cgi){ >+ my $sessionID = $cgi->cookie('CGISESSID'); >+ if ($sessionID){ >+ my $session = C4::Auth::get_session($sessionID); >+ if ($session){ >+ my $id = $session->param('id'); >+ if ($id){ >+ my $patrons = Koha::Patrons->search({ userid => $id }); >+ if ($patrons->count){ >+ $is_authenticated = 1; >+ } >+ } >+ } >+ } >+ } >+ return $is_authenticated; >+} >+ >+=head3 create_session >+ >+ This method creates a Koha session for a patron. >+ >+=cut >+ >+sub create_session { >+ my ($class,$args) = @_; >+ my $complete_session; >+ my $patron = $args->{patron}; >+ if ($patron){ >+ my $session = C4::Auth::get_session(""); >+ if ($session){ >+ my $sessionID = $session->id; >+ if ($sessionID){ >+ C4::Context->_new_userenv($sessionID); >+ $session->param( 'number', $patron->borrowernumber ); >+ $session->param( 'id', $patron->userid ); >+ $session->param( 'cardnumber', $patron->cardnumber ); >+ $session->param( 'firstname', $patron->firstname ); >+ $session->param( 'surname', $patron->surname ); >+ $session->param( 'branch', $patron->library->branchcode ); >+ $session->param( 'branchname', $patron->library->branchname ); >+ $session->param( 'flags', $patron->flags ); >+ $session->param( 'emailaddress', $patron->email ); >+ $session->param( 'ip', $session->remote_addr() ); >+ $session->param( 'lasttime', time() ); >+ C4::Context->set_userenv( >+ $session->param('number'), $session->param('id'), >+ $session->param('cardnumber'), $session->param('firstname'), >+ $session->param('surname'), $session->param('branch'), >+ $session->param('branchname'), $session->param('flags'), >+ $session->param('emailaddress'), $session->param('shibboleth'), >+ $session->param('desk_id'), $session->param('desk_name'), >+ $session->param('register_id'), $session->param('register_name') >+ ); >+ #NOTE: Persist session immediately. Otherwise, scoping issues can bite you. >+ $session->flush(); >+ $complete_session = $session; >+ } >+ } >+ } >+ return $complete_session; >+} >+ >+1; >diff --git a/Koha/Auth/Type/Token/Ical.pm b/Koha/Auth/Type/Token/Ical.pm >new file mode 100644 >index 0000000000..55d4ebe1c7 >--- /dev/null >+++ b/Koha/Auth/Type/Token/Ical.pm >@@ -0,0 +1,61 @@ >+package Koha::Auth::Type::Token::Ical; >+ >+# Copyright 2021 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Patron::Attributes; >+use Koha::Patrons; >+use Koha::Auth::Shim; >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=head3 authenticate >+ >+ This method takes a factor (ie a token) and finds the associated patron. >+ >+ On success, returns a new Koha session, which can be used to log into Koha. >+ >+=cut >+ >+sub authenticate { >+ my ($class,$args) = @_; >+ my $session; >+ my $token = $args->{token}; >+ if ($token){ >+ my $attributes = Koha::Patron::Attributes->search({ >+ code => 'TOKEN_ICAL', >+ attribute => $token, >+ }); >+ if ($attributes->count() == 1){ >+ my $attribute = $attributes->next; >+ if ($attribute){ >+ my $borrowernumber = $attribute->borrowernumber; >+ my $patron = Koha::Patrons->find( $borrowernumber ); >+ if ($patron){ >+ $session = Koha::Auth::Shim->create_session({ patron => $patron }); >+ } >+ } >+ } >+ } >+ return $session; >+} >+ >+1; >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 8606ab0bb8..a2572c9ccd 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -24,6 +24,8 @@ use Carp; > use List::MoreUtils qw( any uniq ); > use JSON qw( to_json ); > use Unicode::Normalize; >+use String::Random qw( random_string ); >+use Digest::MD5 qw( md5_hex ); > > use C4::Context; > use C4::Log; >@@ -1882,6 +1884,37 @@ sub queue_notice { > return \%return; > } > >+=head3 ical_auth_token >+ >+ my $ical_auth_token = $patron->ical_auth_token(); >+ >+ Fetches the patron's iCal authentication token. If token does not exist, it will be automatically generated. >+ >+=cut >+ >+sub ical_auth_token { >+ my ($self, $args) = @_; >+ my $ical_auth_token; >+ my $attribute_value = $self->get_extended_attribute( 'TOKEN_ICAL' ); >+ if ( $attribute_value ){ >+ $ical_auth_token = $attribute_value->attribute(); >+ } >+ else { >+ my $random_string = random_string("." x 24); >+ if ($random_string){ >+ my $digest = md5_hex($random_string); >+ if ($digest){ >+ $self->add_extended_attribute({ >+ code => 'TOKEN_ICAL', >+ attribute => $digest, >+ }); >+ $ical_auth_token = $digest; >+ } >+ } >+ } >+ return $ical_auth_token; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/installer/data/mysql/atomicupdate/bug27305-use-app-token-for-ical.perl b/installer/data/mysql/atomicupdate/bug27305-use-app-token-for-ical.perl >new file mode 100644 >index 0000000000..de3cbd16c8 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug27305-use-app-token-for-ical.perl >@@ -0,0 +1,14 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ my $sql = q{ >+ INSERT INTO borrower_attribute_types (code,description,unique_id) >+ SELECT 'TOKEN_ICAL','Authentication token for iCal feed',1 >+ FROM borrower_attribute_types >+ WHERE NOT EXISTS ( >+ SELECT * FROM borrower_attribute_types WHERE code = 'TOKEN_ICAL' >+ ) >+ }; >+ $dbh->do($sql); >+ >+ NewVersion( $DBversion, 27305, "Add TOKEN_ICAL borrower extended attribute"); >+} >diff --git a/installer/data/mysql/en/mandatory/patron_attributes.yml b/installer/data/mysql/en/mandatory/patron_attributes.yml >new file mode 100644 >index 0000000000..bef1c2b61d >--- /dev/null >+++ b/installer/data/mysql/en/mandatory/patron_attributes.yml >@@ -0,0 +1,34 @@ >+--- >+# >+# Copyright 2021 Koha Development Team >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+description: >+ - "Mandatory patron attribute types:" >+ - "* TOKEN_ICAL - Authentication token for iCal feed" >+ >+tables: >+ - borrower_attribute_types: >+ translatable: [ description ] >+ multiline: [] >+ rows: >+ - code: "TOKEN_ICAL" >+ description: "Authentication token for iCal feed" >+ repeatable: 0 >+ unique_id: 1 >+ opac_display: 0 >+ staff_searchable: 0 >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >index 24b7adaf33..6a60b6b1eb 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >@@ -832,7 +832,11 @@ > <script> > function tableInit( tableId ){ > if( tableId == "checkoutst" ){ >- $(".dt-buttons").append("<a class=\"dt-button buttons-ical\" href=\"opac-ics.pl\">iCal</a> "); >+ [% IF ( ical_auth_token ) %] >+ $(".dt-buttons").append("<a class=\"dt-button buttons-ical\" href=\"opac-ics.pl?token=[% ical_auth_token | uri %]\">iCal</a> "); >+ [% ELSE %] >+ $(".dt-buttons").append("<a class=\"dt-button buttons-ical\" href=\"opac-ics.pl\">iCal</a> "); >+ [% END %] > [% IF ( OpacRenewalAllowed && canrenew && !userdebarred ) %] > $(".dt-buttons").append("<button id=\"renewselected_link\" class=\"dt-button buttons-renew\"><i class=\"fa fa-check\" aria-hidden=\"true\"></i> "+_("Renew selected")+"</button> <button id=\"renewall_link\" class=\"dt-button buttons-renewall\"><span class=\"fa-stack\"><i class=\"fa fa-check fa-stack-1x\" aria-hidden=\"true\"></i><i class=\"fa fa-check fa-stack-1x\" aria-hidden=\"true\"></i></span> "+_("Renew all")+"</button>"); > [% END %] >diff --git a/opac/opac-ics.pl b/opac/opac-ics.pl >index bbb9b5bf40..75f719739c 100755 >--- a/opac/opac-ics.pl >+++ b/opac/opac-ics.pl >@@ -35,14 +35,32 @@ use C4::Circulation; > use C4::Members; > use Koha::DateUtils; > >+use Koha::Auth::Shim; >+use Koha::Auth::Type::Token::Ical; >+ > my $query = CGI->new; >+ >+#NOTE: Allow authentication by token for iCal feed >+my $auth_extensions = {}; >+my $is_authenticated = Koha::Auth::Shim->cgi_is_authenticated({ cgi => $query }); >+if ( ! $is_authenticated ){ >+ my $token = $query->param('token'); >+ if ($token){ >+ my $session = Koha::Auth::Type::Token::Ical->authenticate({ token => $token }); >+ if ($session){ >+ $auth_extensions->{checkauth}->{sessionID} = $session->id; >+ } >+ } >+} >+ > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > { > template_name => "opac-ics.tt", > query => $query, > type => "opac", > debug => 1, >- } >+ }, >+ $auth_extensions, > ); > > # Create Calendar >diff --git a/opac/opac-user.pl b/opac/opac-user.pl >index 7a9c774d67..3492613185 100755 >--- a/opac/opac-user.pl >+++ b/opac/opac-user.pl >@@ -325,6 +325,11 @@ if ($show_barcode) { > } > $template->param( show_barcode => 1 ) if $show_barcode; > >+my $ical_auth_token = $patron->ical_auth_token(); >+if ($ical_auth_token){ >+ $template->param( ical_auth_token => $ical_auth_token ); >+} >+ > # now the reserved items.... > my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } ); > >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index a612b1a599..543d12799f 100755 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -20,6 +20,7 @@ use C4::Members; > use Koha::AuthUtils qw/hash_password/; > use Koha::Database; > use Koha::Patrons; >+use Koha::Auth::Shim; > > BEGIN { > use_ok('C4::Auth'); >@@ -38,7 +39,7 @@ $schema->storage->txn_begin; > > subtest 'checkauth() tests' => sub { > >- plan tests => 4; >+ plan tests => 5; > > my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); > >@@ -110,6 +111,37 @@ subtest 'checkauth() tests' => sub { > > C4::Context->_new_userenv; # For next tests > >+ subtest 'checkauth with pre-authenticated session' => sub { >+ >+ plan tests => 4; >+ >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', value => { flags => 1 } } ); >+ $cgi = Test::MockObject->new(); >+ $cgi->mock( >+ 'cookie', >+ sub { >+ my ($self,@data) = @_; >+ if (scalar @data > 1){ >+ require CGI::Cookie; >+ my $cookie = CGI::Cookie->new(@data); >+ return $cookie; >+ } >+ } >+ ); >+ $cgi->mock( 'param', sub { return; } ); >+ >+ my $session = Koha::Auth::Shim->create_session({ patron => $patron }); >+ my $extensions = { sessionID => $session->id, }; >+ my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 'authrequired', undef, undef, undef, undef, $extensions ); >+ is( $userid, $patron->userid, 'checkauth completes AuthN and AuthZ using a pre-authenticated session' ); >+ is( $sessionID, $session->id, 'sessionID is correct'); >+ is( ref $flags, 'HASH', 'flags is hash ref'); >+ is( $cookie->value, $session->id, 'cookie returned with correct sessionID'); >+ }; >+ >+ C4::Context->_new_userenv; # For next tests >+ > }; > > subtest 'track_login_daily tests' => sub { >diff --git a/t/db_dependent/Koha/Auth/Shim.t b/t/db_dependent/Koha/Auth/Shim.t >new file mode 100644 >index 0000000000..dc25e3fc31 >--- /dev/null >+++ b/t/db_dependent/Koha/Auth/Shim.t >@@ -0,0 +1,52 @@ >+#!/usr/bin/perl >+ >+# Copyright 2021 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Exception; >+use Test::Warn; >+ >+use Koha::Database; >+use Koha::Auth::Shim; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'ical_auth_token' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ if ($patron){ >+ >+ my $session = Koha::Auth::Shim->create_session({ patron => $patron }); >+ ok($session, 'Session created by Koha::Auth::Type::Token::Ical authenticate method'); >+ is( ref $session, 'CGI::Session', 'Session is correct object type'); >+ $session->delete(); >+ >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ >diff --git a/t/db_dependent/Koha/Auth/Type/Token/Ical.t b/t/db_dependent/Koha/Auth/Type/Token/Ical.t >new file mode 100644 >index 0000000000..43c08876e4 >--- /dev/null >+++ b/t/db_dependent/Koha/Auth/Type/Token/Ical.t >@@ -0,0 +1,61 @@ >+#!/usr/bin/perl >+ >+# Copyright 2021 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Exception; >+use Test::Warn; >+ >+use Koha::Database; >+use Koha::Auth::Type::Token::Ical; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'ical_auth_token' => sub { >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ if ($patron){ >+ my $ical_auth_token = $patron->ical_auth_token(); >+ ok($ical_auth_token,"Generated patron ical_auth_token"); >+ my $ical_auth_token_get = $patron->ical_auth_token(); >+ is($ical_auth_token_get,$ical_auth_token,"Patron ical_auth_token matches previous call"); >+ >+ my $session = Koha::Auth::Type::Token::Ical->authenticate({ token => $ical_auth_token }); >+ ok($session, 'Session created by Koha::Auth::Type::Token::Ical authenticate method'); >+ is( ref $session, 'CGI::Session', 'Session is correct object type'); >+ $session->delete(); >+ >+ my $bad_token_session = Koha::Auth::Type::Token::Ical->authenticate({ token => 'bad' }); >+ is( $bad_token_session, undef, 'Bad token returns a null session'); >+ >+ my $empty_token_session = Koha::Auth::Type::Token::Ical->authenticate({ token => '' }); >+ is( $bad_token_session, undef, 'Empty token returns a null session'); >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index c5a2cbfd90..d4e80d4c48 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > use Test::Exception; > use Test::Warn; > >@@ -34,6 +34,22 @@ use t::lib::Mocks; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >+subtest 'ical_auth_token' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ if ($patron){ >+ my $ical_auth_token = $patron->ical_auth_token(); >+ ok($ical_auth_token,"Generated patron ical_auth_token"); >+ my $ical_auth_token_get = $patron->ical_auth_token(); >+ is($ical_auth_token_get,$ical_auth_token,"Patron ical_auth_token matches previous call"); >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'add_guarantor() tests' => sub { > > plan tests => 6; >-- >2.11.0
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 27305
: 119833