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

(-)a/Koha/Token.pm (-1 / +4 lines)
Lines 215-221 sub decode_jwt { Link Here
215
sub _add_default_csrf_params {
215
sub _add_default_csrf_params {
216
    my ( $params ) = @_;
216
    my ( $params ) = @_;
217
    $params->{session_id} //= DEFA_SESSION_ID;
217
    $params->{session_id} //= DEFA_SESSION_ID;
218
    my $userenv = C4::Context->userenv // { id => DEFA_SESSION_USERID };
218
    my $userenv = C4::Context->userenv;
219
    if ( ( !$userenv ) || !$userenv->{id} ) {
220
        $userenv = { id => DEFA_SESSION_USERID };
221
    }
219
    $params->{id} //= Encode::encode( 'UTF-8', $userenv->{id} );
222
    $params->{id} //= Encode::encode( 'UTF-8', $userenv->{id} );
220
    $params->{id} .= '_' . $params->{session_id};
223
    $params->{id} .= '_' . $params->{session_id};
221
224
(-)a/t/Token.t (-2 / +12 lines)
Lines 120-126 subtest 'JWT' => sub { Link Here
120
};
120
};
121
121
122
subtest 'testing _add_default_csrf_params with/without userenv (bug 27849)' => sub {
122
subtest 'testing _add_default_csrf_params with/without userenv (bug 27849)' => sub {
123
    plan tests => 5;
123
    plan tests => 8;
124
124
125
    # Current userenv: userid == 42
125
    # Current userenv: userid == 42
126
    my $result = Koha::Token::_add_default_csrf_params({ session_id => '567' });
126
    my $result = Koha::Token::_add_default_csrf_params({ session_id => '567' });
Lines 133-136 subtest 'testing _add_default_csrf_params with/without userenv (bug 27849)' => s Link Here
133
    $result = Koha::Token::_add_default_csrf_params({}); # pass no session_id
133
    $result = Koha::Token::_add_default_csrf_params({}); # pass no session_id
134
    is( $result->{session_id}, Koha::Token::DEFA_SESSION_ID, 'Check session id' );
134
    is( $result->{session_id}, Koha::Token::DEFA_SESSION_ID, 'Check session id' );
135
    is( $result->{id}, Koha::Token::DEFA_SESSION_USERID. '_'. $result->{session_id}, 'Check userid' );
135
    is( $result->{id}, Koha::Token::DEFA_SESSION_USERID. '_'. $result->{session_id}, 'Check userid' );
136
137
    # Empty anonymous userenv (see C4::Auth::check_cookie_auth)
138
    C4::Context->_new_userenv('ANON SESSION');
139
    C4::Context->set_userenv( undef, q{} );
140
    ok( C4::Context->userenv, "Userenv exists" );
141
    $result = Koha::Token::_add_default_csrf_params( {} );    # pass no session_id
142
    is( $result->{session_id}, Koha::Token::DEFA_SESSION_ID, 'Check session id for anon session' );
143
    is(
144
        $result->{id}, Koha::Token::DEFA_SESSION_USERID . '_' . $result->{session_id},
145
        'Check userid for anon session'
146
    );
136
};
147
};
137
- 

Return to bug 34163