|
|
@ -17,7 +17,7 @@ |
|
|
|
|
|
|
|
use Modern::Perl; |
|
|
|
|
|
|
|
use Test::More tests => 4; |
|
|
|
use Test::More tests => 5; |
|
|
|
use Test::Mojo; |
|
|
|
use t::lib::TestBuilder; |
|
|
|
use t::lib::Mocks; |
|
|
@ -27,11 +27,50 @@ use Koha::ImportBatchProfiles; |
|
|
|
|
|
|
|
my $schema = Koha::Database->new->schema; |
|
|
|
my $builder = t::lib::TestBuilder->new(); |
|
|
|
my $dbh = C4::Context->dbh; |
|
|
|
|
|
|
|
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
|
|
|
|
|
|
|
my $t = Test::Mojo->new('Koha::REST::V1'); |
|
|
|
|
|
|
|
subtest 'unauth access' => sub { |
|
|
|
plan tests => 4; |
|
|
|
|
|
|
|
$schema->storage->txn_begin; |
|
|
|
|
|
|
|
# Patron without specific flag |
|
|
|
my $patron1 = $builder->build_object( |
|
|
|
{ |
|
|
|
class => 'Koha::Patrons', |
|
|
|
value => { |
|
|
|
flags => 4 |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
# Patron with correct flag, but without specific permission |
|
|
|
my $patron2 = $builder->build_object( |
|
|
|
{ |
|
|
|
class => 'Koha::Patrons', |
|
|
|
value => { |
|
|
|
flags => 4096 |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
my $uid = $patron1->userid; |
|
|
|
my $pwd = $patron1->password; |
|
|
|
$t->get_ok("//$uid:$pwd@/api/v1/import_batch_profiles?_order_by=+name") |
|
|
|
->status_is(403); |
|
|
|
|
|
|
|
$uid = $patron1->userid; |
|
|
|
$pwd = $patron1->password; |
|
|
|
$t->get_ok("//$uid:$pwd@/api/v1/import_batch_profiles?_order_by=+name") |
|
|
|
->status_is(403); |
|
|
|
|
|
|
|
$schema->storage->txn_rollback; |
|
|
|
}; |
|
|
|
|
|
|
|
subtest 'list profiles' => sub { |
|
|
|
plan tests => 4; |
|
|
|
|
|
|
@ -46,11 +85,17 @@ subtest 'list profiles' => sub { |
|
|
|
{ |
|
|
|
class => 'Koha::Patrons', |
|
|
|
value => { |
|
|
|
flags => 1 |
|
|
|
flags => 4096 |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
|
|
|
SELECT ?, bit, ? |
|
|
|
FROM userflags |
|
|
|
WHERE flag = ?"); |
|
|
|
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
|
|
|
|
|
|
|
my $pwd = 'thePassword123'; |
|
|
|
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
|
|
|
|
|
|
@ -77,11 +122,17 @@ subtest 'add profile' => sub { |
|
|
|
{ |
|
|
|
class => 'Koha::Patrons', |
|
|
|
value => { |
|
|
|
flags => 1 |
|
|
|
flags => 4096 |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
|
|
|
SELECT ?, bit, ? |
|
|
|
FROM userflags |
|
|
|
WHERE flag = ?"); |
|
|
|
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
|
|
|
|
|
|
|
my $pwd = 'thePassword123'; |
|
|
|
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
|
|
|
|
|
|
@ -112,11 +163,17 @@ subtest 'edit profile' => sub { |
|
|
|
{ |
|
|
|
class => 'Koha::Patrons', |
|
|
|
value => { |
|
|
|
flags => 1 |
|
|
|
flags => 4096 |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
|
|
|
SELECT ?, bit, ? |
|
|
|
FROM userflags |
|
|
|
WHERE flag = ?"); |
|
|
|
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
|
|
|
|
|
|
|
my $pwd = 'thePassword123'; |
|
|
|
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
|
|
|
|
|
|
@ -153,11 +210,17 @@ subtest 'delete profile' => sub { |
|
|
|
{ |
|
|
|
class => 'Koha::Patrons', |
|
|
|
value => { |
|
|
|
flags => 1 |
|
|
|
flags => 4096 |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
|
|
|
SELECT ?, bit, ? |
|
|
|
FROM userflags |
|
|
|
WHERE flag = ?"); |
|
|
|
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
|
|
|
|
|
|
|
my $pwd = 'thePassword123'; |
|
|
|
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
|
|
|
|
|
|
|