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

(-)a/t/db_dependent/api/v1/auth_authenticate_api_request.t (-1 / +46 lines)
Lines 45-51 t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); Link Here
45
subtest 'token-based tests' => sub {
45
subtest 'token-based tests' => sub {
46
46
47
    if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) {
47
    if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) {
48
        plan tests => 15;
48
        plan tests => 16;
49
    } else {
49
    } else {
50
        plan skip_all => 'Net::OAuth2::AuthorizationServer not available';
50
        plan skip_all => 'Net::OAuth2::AuthorizationServer not available';
51
    }
51
    }
Lines 110-115 subtest 'token-based tests' => sub { Link Here
110
    ok( defined $embed, 'The embed hashref is generated and stashed' );
110
    ok( defined $embed, 'The embed hashref is generated and stashed' );
111
    is_deeply( $embed, { fund => {} }, 'The embed data structure is correct' );
111
    is_deeply( $embed, { fund => {} }, 'The embed data structure is correct' );
112
112
113
    subtest 'TrackLastPatronActivityTriggers tests for api_oauth2' => sub {
114
115
        plan tests => 6;
116
117
        $patron->lastseen(undef)->store;
118
119
        my $tx = $t->ua->build_tx( GET => '/api/v1/patrons' );
120
        $tx->req->headers->authorization("Bearer $access_token");
121
        $t->request_ok($tx);
122
123
        is(
124
            $patron->lastseen, undef,
125
            "'lastseen' is undefined"
126
        );
127
128
        #set login in TrackLastPatronActivity_Triggers
129
        t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' );
130
131
        $patron->lastseen(undef)->store;
132
        $tx = $t->ua->build_tx( GET => '/api/v1/patrons' );
133
        $tx->req->headers->authorization("Bearer $access_token");
134
        $t->request_ok($tx);
135
136
        $patron->discard_changes();
137
        is(
138
            $patron->lastseen, undef,
139
            "'lastseen' untouched if 'api_oauth2' is not enabled in TrackLastPatronActivityTriggers"
140
        );
141
142
        #set api_oauth2 in in TrackLastPatronActivity_Triggers
143
        t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_oauth2' );
144
145
        $patron->lastseen(undef)->store;
146
        $tx = $t->ua->build_tx( GET => '/api/v1/patrons' );
147
        $tx->req->headers->authorization("Bearer $access_token");
148
        $t->request_ok($tx);
149
150
        $patron->discard_changes();
151
        ok(
152
            $patron->lastseen,
153
            "'lastseen' flag updated TrackLastPatronActivityTriggers includes 'api_oauth2'"
154
        );
155
156
    };
157
113
    $schema->storage->txn_rollback;
158
    $schema->storage->txn_rollback;
114
};
159
};
115
160
(-)a/t/db_dependent/api/v1/auth_basic.t (-2 / +43 lines)
Lines 33-39 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
33
33
34
subtest 'success tests' => sub {
34
subtest 'success tests' => sub {
35
35
36
    plan tests => 2;
36
    plan tests => 3;
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
Lines 109-114 subtest 'success tests' => sub { Link Here
109
            );
109
            );
110
    };
110
    };
111
111
112
    subtest 'TrackLastPatronActivityTriggers tests for api_basic_auth' => sub {
113
114
        plan tests => 7;
115
116
        $patron->flags( 2**4 )->store;
117
118
        #set login in TrackLastPatronActivity_Triggers
119
        t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' );
120
121
        $patron->lastseen(undef)->store;
122
        $t->get_ok("//$cardnumber:$password@/api/v1/patrons");
123
124
        $patron->discard_changes();
125
        is(
126
            $patron->lastseen, undef,
127
            "'lastseen' untouched if 'api_basic_auth' is not enabled in TrackLastPatronActivityTriggers"
128
        );
129
130
        #set api_oauth2 in in TrackLastPatronActivity_Triggers
131
        t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_basic_auth' );
132
133
        $patron->lastseen(undef)->store;
134
        $t->get_ok("//$cardnumber:$password@/api/v1/patrons");
135
        $patron->discard_changes();
136
137
        ok(
138
            $patron->lastseen,
139
            "'lastseen' flag updated TrackLastPatronActivityTriggers includes 'api_basic_auth'"
140
        );
141
142
        $patron->lastseen(undef)->store;
143
        $t->get_ok("//$cardnumber:basspassword@/api/v1/patrons")
144
            ->status_is( 403, 'Basic Auth fails due to bad password' );
145
        $patron->discard_changes();
146
147
        is(
148
            $patron->lastseen, undef,
149
            "'lastseen' flag remains untouch due to Basic Auth authentication failure'"
150
        );
151
152
    };
153
112
    $schema->storage->txn_rollback;
154
    $schema->storage->txn_rollback;
113
};
155
};
114
156
115
- 

Return to bug 29900