View | Details | Raw Unified | Return to bug 24003
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/auth_authenticate_api_request.t (-7 / +25 lines)
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;
(-)a/t/db_dependent/api/v1/auth_basic.t (-2 / +18 lines)
Lines 30-36 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
30
30
31
subtest 'success tests' => sub {
31
subtest 'success tests' => sub {
32
32
33
    plan tests => 5;
33
    plan tests => 10;
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
Lines 43-51 subtest 'success tests' => sub { Link Here
43
    $patron->set_password({ password => $password });
43
    $patron->set_password({ password => $password });
44
    my $userid = $patron->userid;
44
    my $userid = $patron->userid;
45
45
46
    my $stash;
47
    my $interface;
48
    my $userenv;
49
50
    $t->app->hook(after_dispatch => sub {
51
        $stash     = shift->stash;
52
        $interface = C4::Context->interface;
53
        $userenv   = C4::Context->userenv;
54
    });
55
46
    $t->get_ok("//$userid:$password@/api/v1/patrons")
56
    $t->get_ok("//$userid:$password@/api/v1/patrons")
47
      ->status_is( 200, 'Successful authentication and permissions check' );
57
      ->status_is( 200, 'Successful authentication and permissions check' );
48
58
59
    my $user = $stash->{'koha.user'};
60
    ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
61
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
62
    is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
63
    is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' );
64
    is( $interface, 'api', "Interface correctly set to \'api\'" );
65
49
    $patron->flags(undef)->store;
66
    $patron->flags(undef)->store;
50
67
51
    $t->get_ok("//$userid:$password@/api/v1/patrons")
68
    $t->get_ok("//$userid:$password@/api/v1/patrons")
52
- 

Return to bug 24003