Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 4; |
20 |
use Test::More tests => 5; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
22 |
use t::lib::TestBuilder; |
22 |
use t::lib::TestBuilder; |
23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
Lines 27-37
use Koha::ImportBatchProfiles;
Link Here
|
27 |
|
27 |
|
28 |
my $schema = Koha::Database->new->schema; |
28 |
my $schema = Koha::Database->new->schema; |
29 |
my $builder = t::lib::TestBuilder->new(); |
29 |
my $builder = t::lib::TestBuilder->new(); |
|
|
30 |
my $dbh = C4::Context->dbh; |
30 |
|
31 |
|
31 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
32 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
32 |
|
33 |
|
33 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
34 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
34 |
|
35 |
|
|
|
36 |
subtest 'unauth access' => sub { |
37 |
plan tests => 4; |
38 |
|
39 |
$schema->storage->txn_begin; |
40 |
|
41 |
# Patron without specific flag |
42 |
my $patron1 = $builder->build_object( |
43 |
{ |
44 |
class => 'Koha::Patrons', |
45 |
value => { |
46 |
flags => 4 |
47 |
} |
48 |
} |
49 |
); |
50 |
|
51 |
# Patron with correct flag, but without specific permission |
52 |
my $patron2 = $builder->build_object( |
53 |
{ |
54 |
class => 'Koha::Patrons', |
55 |
value => { |
56 |
flags => 4096 |
57 |
} |
58 |
} |
59 |
); |
60 |
|
61 |
my $uid = $patron1->userid; |
62 |
my $pwd = $patron1->password; |
63 |
$t->get_ok("//$uid:$pwd@/api/v1/import_batch_profiles?_order_by=+name") |
64 |
->status_is(403); |
65 |
|
66 |
$uid = $patron1->userid; |
67 |
$pwd = $patron1->password; |
68 |
$t->get_ok("//$uid:$pwd@/api/v1/import_batch_profiles?_order_by=+name") |
69 |
->status_is(403); |
70 |
|
71 |
$schema->storage->txn_rollback; |
72 |
}; |
73 |
|
35 |
subtest 'list profiles' => sub { |
74 |
subtest 'list profiles' => sub { |
36 |
plan tests => 4; |
75 |
plan tests => 4; |
37 |
|
76 |
|
Lines 46-56
subtest 'list profiles' => sub {
Link Here
|
46 |
{ |
85 |
{ |
47 |
class => 'Koha::Patrons', |
86 |
class => 'Koha::Patrons', |
48 |
value => { |
87 |
value => { |
49 |
flags => 1 |
88 |
flags => 4096 |
50 |
} |
89 |
} |
51 |
} |
90 |
} |
52 |
); |
91 |
); |
53 |
|
92 |
|
|
|
93 |
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
94 |
SELECT ?, bit, ? |
95 |
FROM userflags |
96 |
WHERE flag = ?"); |
97 |
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
98 |
|
54 |
my $pwd = 'thePassword123'; |
99 |
my $pwd = 'thePassword123'; |
55 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
100 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
56 |
|
101 |
|
Lines 77-87
subtest 'add profile' => sub {
Link Here
|
77 |
{ |
122 |
{ |
78 |
class => 'Koha::Patrons', |
123 |
class => 'Koha::Patrons', |
79 |
value => { |
124 |
value => { |
80 |
flags => 1 |
125 |
flags => 4096 |
81 |
} |
126 |
} |
82 |
} |
127 |
} |
83 |
); |
128 |
); |
84 |
|
129 |
|
|
|
130 |
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
131 |
SELECT ?, bit, ? |
132 |
FROM userflags |
133 |
WHERE flag = ?"); |
134 |
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
135 |
|
85 |
my $pwd = 'thePassword123'; |
136 |
my $pwd = 'thePassword123'; |
86 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
137 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
87 |
|
138 |
|
Lines 112-122
subtest 'edit profile' => sub {
Link Here
|
112 |
{ |
163 |
{ |
113 |
class => 'Koha::Patrons', |
164 |
class => 'Koha::Patrons', |
114 |
value => { |
165 |
value => { |
115 |
flags => 1 |
166 |
flags => 4096 |
116 |
} |
167 |
} |
117 |
} |
168 |
} |
118 |
); |
169 |
); |
119 |
|
170 |
|
|
|
171 |
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
172 |
SELECT ?, bit, ? |
173 |
FROM userflags |
174 |
WHERE flag = ?"); |
175 |
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
176 |
|
120 |
my $pwd = 'thePassword123'; |
177 |
my $pwd = 'thePassword123'; |
121 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
178 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
122 |
|
179 |
|
Lines 153-163
subtest 'delete profile' => sub {
Link Here
|
153 |
{ |
210 |
{ |
154 |
class => 'Koha::Patrons', |
211 |
class => 'Koha::Patrons', |
155 |
value => { |
212 |
value => { |
156 |
flags => 1 |
213 |
flags => 4096 |
157 |
} |
214 |
} |
158 |
} |
215 |
} |
159 |
); |
216 |
); |
160 |
|
217 |
|
|
|
218 |
my $sth = $dbh->prepare("INSERT INTO user_permissions (borrowernumber, module_bit, code) |
219 |
SELECT ?, bit, ? |
220 |
FROM userflags |
221 |
WHERE flag = ?"); |
222 |
$sth->execute($patron->borrowernumber, 'stage_marc_import', 'tools'); |
223 |
|
161 |
my $pwd = 'thePassword123'; |
224 |
my $pwd = 'thePassword123'; |
162 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
225 |
$patron->set_password( { password => $pwd, skip_validation => 1 } ); |
163 |
|
226 |
|
164 |
- |
|
|