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

(-)a/t/db_dependent/api/v1/auth_authenticate_api_request.t (-17 / +33 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 => 14;
47
        plan tests => 15;
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 77-92 subtest 'token-based tests' => sub { Link Here
77
    my $stash;
77
    my $stash;
78
    my $interface;
78
    my $interface;
79
    my $userenv;
79
    my $userenv;
80
    my $language_env;
80
81
81
    my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders');
82
    my $accept_language = 'es-ES,es;q=0.9,en-US;q=0.8,en;q=0.7';
83
84
    my $tx = $t->ua->build_tx( GET => '/api/v1/acquisitions/orders' );
82
    $tx->req->headers->authorization("Bearer $access_token");
85
    $tx->req->headers->authorization("Bearer $access_token");
83
    $tx->req->headers->header( 'x-koha-embed' => 'fund' );
86
    $tx->req->headers->header( 'x-koha-embed' => 'fund' );
87
    $tx->req->headers->accept_language($accept_language);
84
88
85
    $t->app->hook(after_dispatch => sub {
89
    $t->app->hook(
86
        $stash     = shift->stash;
90
        after_dispatch => sub {
87
        $interface = C4::Context->interface;
91
            $stash        = shift->stash;
88
        $userenv   = C4::Context->userenv;
92
            $interface    = C4::Context->interface;
89
    });
93
            $userenv      = C4::Context->userenv;
94
            $language_env = $ENV{HTTP_ACCEPT_LANGUAGE};
95
        }
96
    );
90
97
91
    # With access token and permissions, it returns 200
98
    # With access token and permissions, it returns 200
92
    #$patron->flags(2**4)->store;
99
    #$patron->flags(2**4)->store;
Lines 98-103 subtest 'token-based tests' => sub { Link Here
98
    is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
105
    is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
99
    is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' );
106
    is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' );
100
    is( $interface, 'api', "Interface correctly set to \'api\'" );
107
    is( $interface, 'api', "Interface correctly set to \'api\'" );
108
    is( $language_env, $accept_language, 'HTTP_ACCEPT_LANGUAGE correctly set in %ENV' );
101
109
102
    my $embed = $stash->{'koha.embed'};
110
    my $embed = $stash->{'koha.embed'};
103
    ok( defined $embed, 'The embed hashref is generated and stashed' );
111
    ok( defined $embed, 'The embed hashref is generated and stashed' );
Lines 108-132 subtest 'token-based tests' => sub { Link Here
108
116
109
subtest 'cookie-based tests' => sub {
117
subtest 'cookie-based tests' => sub {
110
118
111
    plan tests => 8;
119
    plan tests => 9;
112
120
113
    $schema->storage->txn_begin;
121
    $schema->storage->txn_begin;
114
122
115
    my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 1 });
123
    my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 1 });
116
124
125
    my $stash;
126
    my $interface;
127
    my $userenv;
128
    my $language_env;
129
130
    my $accept_language = 'es-ES,es;q=0.9,en-US;q=0.8,en;q=0.7';
131
117
    $tx = $t->ua->build_tx( GET => "/api/v1/patrons" );
132
    $tx = $t->ua->build_tx( GET => "/api/v1/patrons" );
118
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
133
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
119
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
134
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
135
    $tx->req->headers->accept_language($accept_language);
120
136
121
    my $stash;
137
    $t->app->hook(
122
    my $interface;
138
        after_dispatch => sub {
123
    my $userenv;
139
            $stash        = shift->stash;
140
            $interface    = C4::Context->interface;
141
            $userenv      = C4::Context->userenv;
142
            $language_env = $ENV{HTTP_ACCEPT_LANGUAGE};
124
143
125
    $t->app->hook(after_dispatch => sub {
144
        }
126
        $stash     = shift->stash;
145
    );
127
        $interface = C4::Context->interface;
128
        $userenv   = C4::Context->userenv;
129
    });
130
146
131
    $t->request_ok($tx)->status_is(200);
147
    $t->request_ok($tx)->status_is(200);
132
148
Lines 136-141 subtest 'cookie-based tests' => sub { Link Here
136
    is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
152
    is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
137
    is( $userenv->{number}, $borrowernumber, 'userenv set correctly' );
153
    is( $userenv->{number}, $borrowernumber, 'userenv set correctly' );
138
    is( $interface, 'api', "Interface correctly set to \'api\'" );
154
    is( $interface, 'api', "Interface correctly set to \'api\'" );
155
    is( $language_env, $accept_language, 'HTTP_ACCEPT_LANGUAGE correctly set in %ENV' );
139
156
140
    subtest 'logged-out tests' => sub {
157
    subtest 'logged-out tests' => sub {
141
        plan tests => 3;
158
        plan tests => 3;
142
- 

Return to bug 32551