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

(-)a/C4/Auth.pm (-3 / +3 lines)
Lines 791-797 sub checkauth { Link Here
791
    my $type            = shift;
791
    my $type            = shift;
792
    my $emailaddress    = shift;
792
    my $emailaddress    = shift;
793
    my $template_name   = shift;
793
    my $template_name   = shift;
794
    my $params          = shift || {};    # do_not_print
794
    my $params          = shift || {};    # no_print_for_tests: no HTTP response and just return template variables
795
    $type = 'opac' unless $type;
795
    $type = 'opac' unless $type;
796
796
797
    if ( $type eq 'opac' && !C4::Context->preference("OpacPublic") ) {
797
    if ( $type eq 'opac' && !C4::Context->preference("OpacPublic") ) {
Lines 1333-1339 sub checkauth { Link Here
1333
            $uri->query_param_delete('userid');
1333
            $uri->query_param_delete('userid');
1334
            $uri->query_param_delete('password');
1334
            $uri->query_param_delete('password');
1335
            $uri->query_param_delete('koha_login_context');
1335
            $uri->query_param_delete('koha_login_context');
1336
            unless ( $params->{do_not_print} ) {
1336
            unless ( $params->{no_print_for_tests} ) {
1337
                print $query->redirect( -uri => $uri->as_string, -cookie => $cookie, -status => '303 See other' );
1337
                print $query->redirect( -uri => $uri->as_string, -cookie => $cookie, -status => '303 See other' );
1338
                safe_exit;
1338
                safe_exit;
1339
            }
1339
            }
Lines 1484-1490 sub checkauth { Link Here
1484
    );
1484
    );
1485
    $template->param(%info);
1485
    $template->param(%info);
1486
1486
1487
    if ( $params->{do_not_print} ) {
1487
    if ( $params->{no_print_for_tests} ) {
1488
        # This must be used for testing purpose only!
1488
        # This must be used for testing purpose only!
1489
        return ( undef, undef, undef, undef, $template );
1489
        return ( undef, undef, undef, undef, $template );
1490
    }
1490
    }
(-)a/t/db_dependent/Auth.t (-7 / +6 lines)
Lines 156-162 subtest 'checkauth() tests' => sub { Link Here
156
        $cgi->param( 'userid',   $patron->userid );
156
        $cgi->param( 'userid',   $patron->userid );
157
        $cgi->param( 'password', $password );
157
        $cgi->param( 'password', $password );
158
158
159
        my ( $userid, $cookie, $sessionID, $flags, $template ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
159
        my ( $userid, $cookie, $sessionID, $flags, $template ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { no_print_for_tests => 1 } );
160
        is( $template->{VARS}->{password_has_expired}, 1 );
160
        is( $template->{VARS}->{password_has_expired}, 1 );
161
    };
161
    };
162
162
Lines 191-197 subtest 'checkauth() tests' => sub { Link Here
191
        $cgi->param( -name => 'koha_login_context', -value => 1 );
191
        $cgi->param( -name => 'koha_login_context', -value => 1 );
192
        my ( $userid, $cookie, $flags, $template );
192
        my ( $userid, $cookie, $flags, $template );
193
        ( $userid, $cookie, $sessionID, $flags, $template ) =
193
        ( $userid, $cookie, $sessionID, $flags, $template ) =
194
            C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
194
            C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { no_print_for_tests => 1 } );
195
        is( $template->{VARS}->{loginprompt}, 1, 'Changing to non-existent user causes a redirect to login' );
195
        is( $template->{VARS}->{loginprompt}, 1, 'Changing to non-existent user causes a redirect to login' );
196
    };
196
    };
197
197
Lines 226-232 subtest 'checkauth() tests' => sub { Link Here
226
        $cgi->param( -name => 'password',           -value => $password );
226
        $cgi->param( -name => 'password',           -value => $password );
227
        $cgi->param( -name => 'koha_login_context', -value => 1 );
227
        $cgi->param( -name => 'koha_login_context', -value => 1 );
228
        my ( $userid, $cookie, $sessionID, $flags, $template ) =
228
        my ( $userid, $cookie, $sessionID, $flags, $template ) =
229
            C4::Auth::checkauth( $cgi, 0, {}, 'opac', undef, undef, { do_not_print => 1 } );
229
            C4::Auth::checkauth( $cgi, 0, {}, 'opac', undef, undef, { no_print_for_tests => 1 } );
230
        is( $userid, $patron2->userid, 'Login of patron2 approved' );
230
        is( $userid, $patron2->userid, 'Login of patron2 approved' );
231
        isnt( $sessionID, $previous_sessionID, 'Did not return previous session ID' );
231
        isnt( $sessionID, $previous_sessionID, 'Did not return previous session ID' );
232
        ok( $sessionID, 'New session ID not empty' );
232
        ok( $sessionID, 'New session ID not empty' );
Lines 243-249 subtest 'checkauth() tests' => sub { Link Here
243
        $cgi->param( -name => 'password',           -value => $password );
243
        $cgi->param( -name => 'password',           -value => $password );
244
        $cgi->param( -name => 'koha_login_context', -value => 1 );
244
        $cgi->param( -name => 'koha_login_context', -value => 1 );
245
        ( $userid, $cookie, $sessionID, $flags, $template ) =
245
        ( $userid, $cookie, $sessionID, $flags, $template ) =
246
            C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
246
            C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { no_print_for_tests => 1 } );
247
        is( $template->{VARS}->{nopermission}, 1, 'No permission response' );
247
        is( $template->{VARS}->{nopermission}, 1, 'No permission response' );
248
    };
248
    };
249
249
Lines 774-780 subtest 'checkauth & check_cookie_auth' => sub { Link Here
774
    $ENV{"HTTP_COOKIE"} = "CGISESSID=$sessionID";
774
    $ENV{"HTTP_COOKIE"} = "CGISESSID=$sessionID";
775
    # Not authenticated yet, the login form is displayed
775
    # Not authenticated yet, the login form is displayed
776
    my $template;
776
    my $template;
777
    ( $userid, $cookie, $sessionID, $flags, $template ) = C4::Auth::checkauth($cgi, 0, {catalogue => 1}, 'intranet', undef, undef, { do_not_print => 1 } );
777
    ( $userid, $cookie, $sessionID, $flags, $template ) = C4::Auth::checkauth($cgi, 0, {catalogue => 1}, 'intranet', undef, undef, { no_print_for_tests => 1 } );
778
    is( $template->{VARS}->{loginprompt}, 1, );
778
    is( $template->{VARS}->{loginprompt}, 1, );
779
779
780
    # Sending undefined fails obviously
780
    # Sending undefined fails obviously
Lines 816-822 subtest 'checkauth & check_cookie_auth' => sub { Link Here
816
    $cgi->param('logout.x', 1);
816
    $cgi->param('logout.x', 1);
817
    $cgi->delete( 'userid', 'password' );
817
    $cgi->delete( 'userid', 'password' );
818
    ( $userid, $cookie, $sessionID, $flags, $template ) =
818
    ( $userid, $cookie, $sessionID, $flags, $template ) =
819
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } );
819
        C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { no_print_for_tests => 1 } );
820
820
821
    is( $sessionID, undef );
821
    is( $sessionID, undef );
822
    is( $ENV{"HTTP_COOKIE"}, "CGISESSID=$first_sessionID", 'HTTP_COOKIE not unset' );
822
    is( $ENV{"HTTP_COOKIE"}, "CGISESSID=$first_sessionID", 'HTTP_COOKIE not unset' );
823
- 

Return to bug 35904