Lines 44-50
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
Link Here
|
44 |
subtest 'token-based tests' => sub { |
44 |
subtest 'token-based tests' => sub { |
45 |
|
45 |
|
46 |
if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { |
46 |
if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) { |
47 |
plan tests => 10; |
47 |
plan tests => 12; |
48 |
} |
48 |
} |
49 |
else { |
49 |
else { |
50 |
plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; |
50 |
plan skip_all => 'Net::OAuth2::AuthorizationServer not available'; |
Lines 76-103
subtest 'token-based tests' => sub {
Link Here
|
76 |
|
76 |
|
77 |
my $access_token = $t->tx->res->json->{access_token}; |
77 |
my $access_token = $t->tx->res->json->{access_token}; |
78 |
|
78 |
|
79 |
# With access token and permissions, it returns 200 |
|
|
80 |
#$patron->flags(2**4)->store; |
81 |
|
82 |
my $stash; |
79 |
my $stash; |
|
|
80 |
my $interface; |
81 |
my $userenv; |
83 |
|
82 |
|
84 |
my $tx = $t->ua->build_tx(GET => '/api/v1/patrons'); |
83 |
my $tx = $t->ua->build_tx(GET => '/api/v1/patrons'); |
85 |
$tx->req->headers->authorization("Bearer $access_token"); |
84 |
$tx->req->headers->authorization("Bearer $access_token"); |
86 |
|
85 |
|
87 |
$t->app->hook(after_dispatch => sub { $stash = shift->stash }); |
86 |
$t->app->hook(after_dispatch => sub { |
|
|
87 |
$stash = shift->stash; |
88 |
$interface = C4::Context->interface; |
89 |
$userenv = C4::Context->userenv; |
90 |
}); |
91 |
|
92 |
# With access token and permissions, it returns 200 |
93 |
#$patron->flags(2**4)->store; |
88 |
$t->request_ok($tx)->status_is(200); |
94 |
$t->request_ok($tx)->status_is(200); |
89 |
|
95 |
|
90 |
my $user = $stash->{'koha.user'}; |
96 |
my $user = $stash->{'koha.user'}; |
91 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
97 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
92 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
98 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
93 |
is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); |
99 |
is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' ); |
|
|
100 |
is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' ); |
101 |
is( $interface, 'api', "Interface correctly set to \'api\'" ); |
94 |
|
102 |
|
95 |
$schema->storage->txn_rollback; |
103 |
$schema->storage->txn_rollback; |
96 |
}; |
104 |
}; |
97 |
|
105 |
|
98 |
subtest 'cookie-based tests' => sub { |
106 |
subtest 'cookie-based tests' => sub { |
99 |
|
107 |
|
100 |
plan tests => 6; |
108 |
plan tests => 8; |
101 |
|
109 |
|
102 |
$schema->storage->txn_begin; |
110 |
$schema->storage->txn_begin; |
103 |
|
111 |
|
Lines 108-120
subtest 'cookie-based tests' => sub {
Link Here
|
108 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
116 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
109 |
|
117 |
|
110 |
my $stash; |
118 |
my $stash; |
111 |
$t->app->hook(after_dispatch => sub { $stash = shift->stash }); |
119 |
my $interface; |
|
|
120 |
my $userenv; |
121 |
|
122 |
$t->app->hook(after_dispatch => sub { |
123 |
$stash = shift->stash; |
124 |
$interface = C4::Context->interface; |
125 |
$userenv = C4::Context->userenv; |
126 |
}); |
127 |
|
112 |
$t->request_ok($tx)->status_is(200); |
128 |
$t->request_ok($tx)->status_is(200); |
113 |
|
129 |
|
114 |
my $user = $stash->{'koha.user'}; |
130 |
my $user = $stash->{'koha.user'}; |
115 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
131 |
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and |
116 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
132 |
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and |
117 |
is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' ); |
133 |
is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' ); |
|
|
134 |
is( $userenv->{number}, $borrowernumber, 'userenv set correctly' ); |
135 |
is( $interface, 'api', "Interface correctly set to \'api\'" ); |
118 |
|
136 |
|
119 |
subtest 'logged-out tests' => sub { |
137 |
subtest 'logged-out tests' => sub { |
120 |
plan tests => 3; |
138 |
plan tests => 3; |