From: Jason Etheridge Date: Tue, 13 Sep 2022 12:32:27 +0000 (-0400) Subject: SIP filters: tests X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7bdc0e3879893ff4bf19711dbfe2377a6ce46757;p=working%2FSIPServer.git SIP filters: tests Signed-off-by: Jason Etheridge --- diff --git a/t/16filter.t b/t/16filter.t new file mode 100755 index 0000000..ae39d49 --- /dev/null +++ b/t/16filter.t @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006-2008 Georgia Public Library Service +# +# Author: David J. Fiander +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program. If not, see . +# +# checkout: test Checkout Response + +use strict; +use warnings; +use Clone qw(clone); + +use Sip::Constants qw(:all); + +use SIPtest qw($datepat $textpat $instid $currency + $blocked_br1_user_barcode $unblocked_br1_user_barcode + $blocked_br2_user_barcode $unblocked_br2_user_barcode + $filter_test_br1_item_barcode $filter_test_br2_item_barcode); + +my $br1_checkin = { + id => 'Checkout: cleanup: check in item', + msg => "09N20050102 08423620060113 084235APUnder the bed|AO$instid|AB$filter_test_br1_item_barcode|ACterminal password|", + pat => qr/^101YNN$datepat/o, + fields => [], +}; + +my $br2_checkin_template = clone( $br1_checkin ); +$br2_checkin_template->{msg} =~ s/$filter_test_br1_item_barcode/$filter_test_br2_item_barcode/g; + +my $unfiltered_screen_msg = clone( $SIPtest::field_specs{(FID_SCREEN_MSG)} ); +$unfiltered_screen_msg->{pat} = 'Patron is not allowed to checkout the selected item'; + +my $filtered_screen_msg = clone( $SIPtest::field_specs{(FID_SCREEN_MSG)} ); +$filtered_screen_msg->{pat} = 'BLOCKED'; + +my $checkout_test_template = { + id => 'Checkout attempt: valid item, valid patron but circ not allowed ', + msg => "11YN20060329 203000 AO$instid|AA$blocked_br1_user_barcode|AB$filter_test_br1_item_barcode|AC|", + pat => qr/^12[01][YN][YN][YN]$datepat/, + fields => [ + $SIPtest::field_specs{(FID_INST_ID)}, + $SIPtest::field_specs{(FID_SCREEN_MSG)}, + $SIPtest::field_specs{(FID_PRINT_LINE)}, + { field => FID_PATRON_ID, + pat => qr/^$blocked_br1_user_barcode$/o, + required => 1, }, + { field => FID_ITEM_ID, + pat => qr/^$filter_test_br1_item_barcode$/o, + required => 1, }, + { field => FID_TITLE_ID, + pat => $textpat, + required => 1, }, + { field => FID_DUE_DATE, + pat => $textpat, + required => 1, }, + { field => FID_FEE_TYPE, + pat => qr/^\d{2}$/, + required => 0, }, + { field => FID_SECURITY_INHIBIT, + pat => qr/^[YN]$/, + required => 0, }, + { field => FID_CURRENCY, + pat => qr/^$currency$/o, + required => 0, }, + { field => FID_FEE_AMT, + pat => qr/^[.0-9]+$/, + required => 0, }, + { field => FID_MEDIA_TYPE, + pat => qr/^\d{3}$/, + required => 0, }, + { field => FID_ITEM_PROPS, + pat => $textpat, + required => 0, }, + { field => FID_TRANSACTION_ID, + pat => $textpat, + required => 0, }, + ] +}; + +my $filtered_and_blocked_checkout = clone( $checkout_test_template ); +$filtered_and_blocked_checkout->{id} .= '(filtered,blocked)'; +$filtered_and_blocked_checkout->{fields}[1] = $filtered_screen_msg; + +my $filtered_and_unblocked_checkout = clone( $checkout_test_template ); +$filtered_and_unblocked_checkout->{id} .= '(filtered,unblocked)'; +$filtered_and_unblocked_checkout->{fields}[1] = $filtered_screen_msg; +$filtered_and_unblocked_checkout->{fields}[3] = { + field => FID_PATRON_ID, + pat => qr/^$unblocked_br1_user_barcode$/o, + required => 1 }, +$filtered_and_unblocked_checkout->{msg} =~ s/$blocked_br1_user_barcode/$unblocked_br1_user_barcode/g; + +# TODO - use BR2 patron/item for no matching filter rule, to hit every combination + +my @tests = ( + $SIPtest::login_test, + $SIPtest::sc_status_test, + $filtered_and_unblocked_checkout, + $br1_checkin, + $filtered_and_blocked_checkout, + $br1_checkin +); + +SIPtest::run_sip_tests(@tests); + +1; diff --git a/t/SIPtest.pm b/t/SIPtest.pm index aa23533..94385e3 100644 --- a/t/SIPtest.pm +++ b/t/SIPtest.pm @@ -44,6 +44,8 @@ our @EXPORT_OK = qw(run_sip_tests no_tagged_fields $second_user_email $second_user_phone $second_user_birthday $second_user_ptype $second_user_inet $second_user_homelib $cancel_hold_user_barcode $user_with_fees_barcode + $blocked_br1_user_barcode $unblocked_br1_user_barcode $filter_test_br1_item_barcode + $blocked_br2_user_barcode $unblocked_br2_user_barcode $filter_test_br2_item_barcode $item_barcode $item_title $item_owner $item2_barcode $item2_title $item2_owner $item_on_hold_barcode @@ -143,6 +145,20 @@ our $item_diacritic_barcode = 'CONC40000546'; our $item_diacritic_title = 'Composition student recital, April 6, 2000, Huntington University / composition students of Daniel Bédard'; our $item_diacritic_owner = 'BR1'; +# For 16filter.t, testing SIP filters + +# Users with a block_circ penalty +our $blocked_br1_user_barcode = '99999329410'; +our $blocked_br2_user_barcode = '99999329410'; + +# And users without such a penalty +our $unblocked_br1_user_barcode = '99999354736'; +our $unblocked_br2_user_barcode = '99999324566'; + +# And items with which to attempt checkouts to such users +our $filter_test_br1_item_barcode = 'CONC40000565'; +our $filter_test_br2_item_barcode = 'CONC51000136'; + # End configuration # Pattern for a SIP datestamp, to be used by individual tests to diff --git a/t/augment_concerto.sql b/t/augment_concerto.sql index 76d58b8..f60d648 100644 --- a/t/augment_concerto.sql +++ b/t/augment_concerto.sql @@ -17,3 +17,87 @@ set where name = 'sip.sc_status_before_login_institution' ; + +-- the following section is for testing SIP Filters using SIP2Mediator + +INSERT INTO actor.usr_standing_penalty (usr, staff, org_unit, standing_penalty) VALUES (53, 1, 4, 22); + +INSERT INTO permission.grp_tree (name,parent,description,application_perm) +VALUES ('SIP', 1, 'SIP2 Client Systems', 'group_application.user.sip_client'); + +INSERT INTO + permission.grp_perm_map (grp, perm, depth, grantable) +SELECT + g.id, p.id, 0, FALSE +FROM + permission.grp_tree g, + permission.perm_list p +WHERE + g.name = 'SIP' AND + p.code IN ( + 'COPY_CHECKIN', + 'COPY_CHECKOUT', + 'RENEW_CIRC', + 'VIEW_CIRCULATIONS', + 'VIEW_COPY_CHECKOUT_HISTORY', + 'VIEW_PERMIT_CHECKOUT', + 'VIEW_USER', + 'VIEW_USER_FINES_SUMMARY', + 'VIEW_USER_TRANSACTIONS', + 'UPDATE_USER', + 'CANCEL_HOLDS', + 'CREATE_PAYMENT' + ); + +INSERT INTO actor.usr ( + profile, + usrname, + passwd, + ident_type, + first_given_name, + family_name, + home_ou, + super_user) +VALUES ( + (SELECT id FROM permission.grp_tree WHERE name ~ 'SIP' LIMIT 1), + 'scclient', + 'clientpwd', + (SELECT MAX(id) FROM config.identification_type), + 'Ima', + 'SIP', + (SELECT MIN(id) FROM actor.org_unit WHERE ou_type = (SELECT MIN(id) FROM actor.org_unit_type WHERE can_have_users)), + 'f' +); + +INSERT INTO actor.card ( + usr, + barcode +) VALUES ( + (SELECT CURRVAL('actor.usr_id_seq')), + 'scclient' +); + +UPDATE actor.usr + SET card = CURRVAL('actor.card_id_seq') + WHERE id = (SELECT CURRVAL('actor.usr_id_seq')); + +SELECT actor.set_passwd((select id from actor.usr where usrname = 'scclient'), 'sip2', 'sip_password'); + +INSERT INTO actor.workstation (name, owning_lib) VALUES ('BR1-SIP2-Gateway', 4); + +INSERT INTO sip.account( + enabled, transient, setting_group, sip_username, usr, workstation +) VALUES ( + 't', 'f', 1, 'scclient', + (select id from actor.usr where usrname = 'scclient'), + (SELECT id FROM actor.workstation WHERE name = 'BR1-SIP2-Gateway') +); + +-- for t/16filter.t + +insert into sip.filter (enabled, setting_group, identifier, strip, replace_with) values ('t',1,'AF','f','BLOCKED'); +insert into actor.usr_standing_penalty (org_unit, usr, standing_penalty, staff, set_date) values (4, 16, 22, 1, now()); +insert into actor.usr_standing_penalty (org_unit, usr, standing_penalty, staff, set_date) values (5, 15, 22, 1, now()); + + +