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 => 12;
47
        plan tests => 14;
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 74-95 subtest 'token-based tests' => sub { Link Here
74
74
75
    my $access_token = $t->tx->res->json->{access_token};
75
    my $access_token = $t->tx->res->json->{access_token};
76
76
77
    # With access token and permissions, it returns 200
78
    #$patron->flags(2**4)->store;
79
80
    my $stash;
77
    my $stash;
78
    my $interface;
79
    my $userenv;
81
80
82
    my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders');
81
    my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders');
83
    $tx->req->headers->authorization("Bearer $access_token");
82
    $tx->req->headers->authorization("Bearer $access_token");
84
    $tx->req->headers->header( 'x-koha-embed' => 'fund' );
83
    $tx->req->headers->header( 'x-koha-embed' => 'fund' );
85
84
86
    $t->app->hook(after_dispatch => sub { $stash = shift->stash });
85
    $t->app->hook(after_dispatch => sub {
86
        $stash     = shift->stash;
87
        $interface = C4::Context->interface;
88
        $userenv   = C4::Context->userenv;
89
    });
90
91
    # With access token and permissions, it returns 200
92
    #$patron->flags(2**4)->store;
87
    $t->request_ok($tx)->status_is(200);
93
    $t->request_ok($tx)->status_is(200);
88
94
89
    my $user = $stash->{'koha.user'};
95
    my $user = $stash->{'koha.user'};
90
    ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
96
    ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
91
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
97
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
92
    is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
98
    is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
99
    is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' );
100
    is( $interface, 'api', "Interface correctly set to \'api\'" );
93
101
94
    my $embed = $stash->{'koha.embed'};
102
    my $embed = $stash->{'koha.embed'};
95
    ok( defined $embed, 'The embed hashref is generated and stashed' );
103
    ok( defined $embed, 'The embed hashref is generated and stashed' );
Lines 100-106 subtest 'token-based tests' => sub { Link Here
100
108
101
subtest 'cookie-based tests' => sub {
109
subtest 'cookie-based tests' => sub {
102
110
103
    plan tests => 6;
111
    plan tests => 8;
104
112
105
    $schema->storage->txn_begin;
113
    $schema->storage->txn_begin;
106
114
Lines 111-123 subtest 'cookie-based tests' => sub { Link Here
111
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
119
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
112
120
113
    my $stash;
121
    my $stash;
114
    $t->app->hook(after_dispatch => sub { $stash = shift->stash });
122
    my $interface;
123
    my $userenv;
124
125
    $t->app->hook(after_dispatch => sub {
126
        $stash     = shift->stash;
127
        $interface = C4::Context->interface;
128
        $userenv   = C4::Context->userenv;
129
    });
130
115
    $t->request_ok($tx)->status_is(200);
131
    $t->request_ok($tx)->status_is(200);
116
132
117
    my $user = $stash->{'koha.user'};
133
    my $user = $stash->{'koha.user'};
118
    ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
134
    ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
119
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
135
    is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
120
    is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
136
    is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
137
    is( $userenv->{number}, $borrowernumber, 'userenv set correctly' );
138
    is( $interface, 'api', "Interface correctly set to \'api\'" );
121
139
122
    subtest 'logged-out tests' => sub {
140
    subtest 'logged-out tests' => sub {
123
        plan tests => 3;
141
        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