Lines 45-50
post '/register_user' => sub {
Link Here
|
45 |
} catch { |
45 |
} catch { |
46 |
if ( ref($_) eq 'Koha::Exceptions::Auth::Unauthorized' ) { |
46 |
if ( ref($_) eq 'Koha::Exceptions::Auth::Unauthorized' ) { |
47 |
$c->render( status => 401, json => { message => 'unauthorized' } ); |
47 |
$c->render( status => 401, json => { message => 'unauthorized' } ); |
|
|
48 |
} elsif ( ref($_) eq 'Koha::Exceptions::BadParameter' ) { |
49 |
$c->render( status => 400, json => { message => 'bad parameter: ' . $_->parameter } ); |
50 |
} elsif ( ref($_) eq 'Koha::Exceptions::MissingParameter' ) { |
51 |
$c->render( status => 400, json => { message => 'missing parameter: ' . $_->parameter } ); |
48 |
} else { |
52 |
} else { |
49 |
$c->render( status => 500, json => { message => 'other error' } ); |
53 |
$c->render( status => 500, json => { message => 'other error' } ); |
50 |
} |
54 |
} |
Lines 79-141
use Koha::Database;
Link Here
|
79 |
my $schema = Koha::Database->new()->schema(); |
83 |
my $schema = Koha::Database->new()->schema(); |
80 |
my $builder = t::lib::TestBuilder->new; |
84 |
my $builder = t::lib::TestBuilder->new; |
81 |
|
85 |
|
|
|
86 |
my $t = Test::Mojo->new; |
87 |
|
82 |
# FIXME: sessionStorage defaults to mysql, but it seems to break transaction handling |
88 |
# FIXME: sessionStorage defaults to mysql, but it seems to break transaction handling |
83 |
# this affects the other REST api tests |
89 |
# this affects the other REST api tests |
84 |
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); |
90 |
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); |
85 |
|
91 |
|
86 |
subtest 'auth.register helper' => sub { |
92 |
subtest 'auth.register helper' => sub { |
87 |
plan tests => 6; |
93 |
|
|
|
94 |
plan tests => 18; |
88 |
|
95 |
|
89 |
$schema->storage->txn_begin; |
96 |
$schema->storage->txn_begin; |
90 |
|
97 |
|
91 |
# generate a random patron |
98 |
# generate a random patron |
92 |
my $patron_to_delete = $builder->build_object( { class => 'Koha::Patrons' } ); |
99 |
my $patron_to_delete_1 = $builder->build_object( { class => 'Koha::Patrons' } ); |
93 |
my $userid = $patron_to_delete->userid; |
100 |
my $patron_to_delete_2 = $builder->build_object( { class => 'Koha::Patrons' } ); |
|
|
101 |
my $userid_1 = $patron_to_delete_1->userid; |
102 |
my $userid_2 = $patron_to_delete_2->userid; |
94 |
|
103 |
|
95 |
# delete patron |
104 |
# delete patron |
96 |
$patron_to_delete->delete; |
105 |
$patron_to_delete_1->delete; |
|
|
106 |
$patron_to_delete_2->delete; |
97 |
|
107 |
|
98 |
my $provider = |
108 |
my $provider = |
99 |
$builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); |
109 |
$builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); |
100 |
|
110 |
|
101 |
my $domain_with_register = $builder->build_object( |
111 |
my $domain_1 = $builder->build_object( |
102 |
{ |
112 |
{ |
103 |
class => 'Koha::Auth::Identity::Provider::Domains', |
113 |
class => 'Koha::Auth::Identity::Provider::Domains', |
104 |
value => { identity_provider_id => $provider->id, domain => 'domain1.com', auto_register => 1 } |
114 |
value => { |
|
|
115 |
identity_provider_id => $provider->id, |
116 |
domain => 'domain1.com', |
117 |
auto_register_opac => 1, |
118 |
auto_register_staff => 0 |
119 |
} |
105 |
} |
120 |
} |
106 |
); |
121 |
); |
107 |
|
122 |
|
108 |
my $domain_without_register = $builder->build_object( |
123 |
my $domain_2 = $builder->build_object( |
109 |
{ |
124 |
{ |
110 |
class => 'Koha::Auth::Identity::Provider::Domains', |
125 |
class => 'Koha::Auth::Identity::Provider::Domains', |
111 |
value => { identity_provider_id => $provider->id, domain => 'domain2.com', auto_register => 0 } |
126 |
value => { |
|
|
127 |
identity_provider_id => $provider->id, |
128 |
domain => 'domain2.com', |
129 |
auto_register_opac => 0, |
130 |
auto_register_staff => 1 |
131 |
} |
112 |
} |
132 |
} |
113 |
); |
133 |
); |
114 |
|
134 |
|
115 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
135 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
116 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); |
136 |
my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); |
117 |
|
137 |
|
118 |
my $user_data = { |
|
|
119 |
firstname => 'test', |
120 |
surname => 'test', |
121 |
userid => $userid, |
122 |
branchcode => $library->branchcode, |
123 |
categorycode => $category->categorycode |
124 |
}; |
125 |
|
126 |
my $t = Test::Mojo->new; |
127 |
|
128 |
$t->post_ok( |
138 |
$t->post_ok( |
129 |
'/register_user' => json => { |
139 |
'/register_user' => json => { |
130 |
data => $user_data, domain_id => $domain_with_register->identity_provider_domain_id, interface => 'opac' |
140 |
data => { |
|
|
141 |
firstname => 'test', |
142 |
surname => 'test', |
143 |
userid => $userid_1, |
144 |
branchcode => $library->branchcode, |
145 |
categorycode => $category->categorycode |
146 |
}, |
147 |
domain_id => $domain_1->identity_provider_domain_id, |
148 |
interface => 'opac' |
131 |
} |
149 |
} |
132 |
)->status_is(200)->json_has( '/firstname', 'test' ); |
150 |
)->status_is(200)->json_is( '/userid', $userid_1 ); |
|
|
151 |
|
152 |
$t->post_ok( '/register_user' => json => |
153 |
{ data => {}, domain_id => $domain_2->identity_provider_domain_id, interface => 'opac' } )->status_is(401) |
154 |
->json_is( '/message', 'unauthorized' ); |
155 |
|
156 |
$t->post_ok( '/register_user' => json => |
157 |
{ data => {}, domain_id => $domain_1->identity_provider_domain_id, interface => 'staff' } )->status_is(401) |
158 |
->json_is( '/message', 'unauthorized' ); |
133 |
|
159 |
|
134 |
$t->post_ok( |
160 |
$t->post_ok( |
135 |
'/register_user' => json => { |
161 |
'/register_user' => json => { |
136 |
data => $user_data, domain_id => $domain_without_register->identity_provider_domain_id, interface => 'opac' |
162 |
data => { |
|
|
163 |
firstname => 'test', |
164 |
surname => 'test', |
165 |
userid => $userid_2, |
166 |
branchcode => $library->branchcode, |
167 |
categorycode => $category->categorycode |
168 |
}, |
169 |
domain_id => $domain_2->identity_provider_domain_id, |
170 |
interface => 'staff' |
137 |
} |
171 |
} |
138 |
)->status_is(401)->json_has( '/message', 'unauthorized' ); |
172 |
)->status_is(200)->json_is( '/userid', $userid_2 ); |
|
|
173 |
|
174 |
$t->post_ok( '/register_user' => json => { data => {}, domain_id => $domain_1->identity_provider_domain_id } ) |
175 |
->status_is(400)->json_is( '/message', 'missing parameter: interface' ); |
176 |
|
177 |
$t->post_ok( '/register_user' => json => |
178 |
{ data => {}, domain_id => $domain_1->identity_provider_domain_id, interface => 'invalid' } ) |
179 |
->status_is(400)->json_is( '/message', 'bad parameter: interface' ); |
139 |
|
180 |
|
140 |
$schema->storage->txn_rollback; |
181 |
$schema->storage->txn_rollback; |
141 |
}; |
182 |
}; |
Lines 147-153
subtest 'auth.session helper' => sub {
Link Here
|
147 |
|
188 |
|
148 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
189 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
149 |
|
190 |
|
150 |
my $t = Test::Mojo->new; |
|
|
151 |
$t->post_ok( '/start_session' => json => { userid => $patron->userid } )->status_is(200) |
191 |
$t->post_ok( '/start_session' => json => { userid => $patron->userid } )->status_is(200) |
152 |
->json_has( '/status', 'ok' ); |
192 |
->json_has( '/status', 'ok' ); |
153 |
|
193 |
|
154 |
- |
|
|