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

(-)a/t/integration/auth/cas.t (+102 lines)
Line 0 Link Here
1
#!/usr/bin/env perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
use Test::Mojo;
7
use Test::MockModule;
8
9
use Authen::CAS::Client;
10
use Authen::CAS::Client::Response;
11
12
use t::lib::TestBuilder;
13
use t::lib::Mocks;
14
15
use Koha::AuthUtils qw( hash_password );
16
use Koha::Database;
17
18
my $authen_cas_client = Test::MockModule->new('Authen::CAS::Client');
19
$authen_cas_client->mock(service_validate => sub {
20
    my ($self, $service, $ticket) = @_;
21
    if ($ticket eq 'goodticket') {
22
        return Authen::CAS::Client::Response::AuthSuccess->new(
23
            user => 'test',
24
        );
25
    }
26
27
    return Authen::CAS::Client::Response::AuthFailure->new(
28
        message => 'bad ticket',
29
    );
30
});
31
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
t::lib::Mocks::mock_preference('SessionStorage', 'tmp');
36
37
my $builder = t::lib::TestBuilder->new;
38
39
my $borrower = $builder->build({
40
    source => 'Borrower',
41
    value => {
42
        userid => 'test',
43
        password => hash_password('test'),
44
        firstname => 'John',
45
        surname => 'Doe',
46
        flags => 1,
47
    },
48
});
49
50
subtest 'intranet' => sub {
51
    plan tests => 10;
52
53
    my $t = Test::Mojo->new('Koha::App::Koha');
54
55
    $t->get_ok('/cgi-bin/koha/mainpage.pl')
56
        ->element_exists('form#loginform');
57
58
    my $formdata = {
59
        ticket => 'goodticket',
60
    };
61
    $t->post_ok('/cgi-bin/koha/mainpage.pl', form => $formdata)
62
        ->element_exists_not('form#loginform')
63
        ->text_is('#logged-in-info-full .loggedinusername', 'test');
64
65
    $t->get_ok('/cgi-bin/koha/mainpage.pl?logout.x=1')
66
        ->element_exists('form#loginform');
67
68
    $formdata = {
69
        ticket => 'badticket',
70
    };
71
    $t->post_ok('/cgi-bin/koha/mainpage.pl', form => $formdata)
72
        ->element_exists('form#loginform')
73
        ->content_like(qr/Sorry, the CAS login failed/);
74
};
75
76
subtest 'opac' => sub {
77
    plan tests => 10;
78
79
    my $t = Test::Mojo->new('Koha::App::Koha');
80
81
    $t->get_ok('/cgi-bin/koha/opac-user.pl')
82
        ->element_exists('form#auth');
83
84
    my $formdata = {
85
        ticket => 'goodticket',
86
    };
87
    $t->post_ok('/cgi-bin/koha/opac-user.pl', form => $formdata)
88
        ->element_exists_not('form#auth')
89
        ->text_like('.loggedinusername', qr/John Doe$/);
90
91
    $t->get_ok('/cgi-bin/koha/opac-user.pl?logout.x=1')
92
        ->element_exists('form#auth');
93
94
    $formdata = {
95
        ticket => 'badticket',
96
    };
97
    $t->post_ok('/cgi-bin/koha/opac-user.pl', form => $formdata)
98
        ->element_exists('form#auth')
99
        ->content_like(qr/Sorry, the CAS login failed/);
100
};
101
102
$schema->storage->txn_rollback;
(-)a/t/integration/auth/password.t (-1 / +90 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
use Test::Mojo;
7
8
use t::lib::TestBuilder;
9
use t::lib::Mocks;
10
11
use Koha::AuthUtils qw( hash_password );
12
use Koha::Database;
13
14
my $schema = Koha::Database->new->schema;
15
$schema->storage->txn_begin;
16
17
t::lib::Mocks::mock_preference('SessionStorage', 'tmp');
18
19
my $builder = t::lib::TestBuilder->new;
20
21
my $borrower = $builder->build({
22
    source => 'Borrower',
23
    value => {
24
        userid => 'test',
25
        password => hash_password('test'),
26
        firstname => 'John',
27
        surname => 'Doe',
28
        flags => 1,
29
    },
30
});
31
32
subtest 'intranet' => sub {
33
    plan tests => 10;
34
35
    my $t = Test::Mojo->new('Koha::App::Koha');
36
37
    $t->get_ok('/cgi-bin/koha/mainpage.pl')
38
        ->element_exists('form#loginform');
39
40
    my $formdata = {
41
        userid => 'test',
42
        password => 'test',
43
    };
44
    $t->post_ok('/cgi-bin/koha/mainpage.pl', form => $formdata)
45
        ->element_exists_not('form#loginform')
46
        ->text_is('#logged-in-info-full .loggedinusername', 'test');
47
48
    $t->get_ok('/cgi-bin/koha/mainpage.pl?logout.x=1')
49
        ->element_exists('form#loginform');
50
51
    $formdata = {
52
        userid => 'test',
53
        password => 'test2',
54
    };
55
    $t->post_ok('/cgi-bin/koha/mainpage.pl', form => $formdata)
56
        ->element_exists('form#loginform')
57
        ->element_exists('#login_error');
58
};
59
60
subtest 'opac' => sub {
61
    plan tests => 10;
62
63
    my $t = Test::Mojo->new('Koha::App::Koha');
64
65
    $t->get_ok('/cgi-bin/koha/opac-user.pl')
66
        ->element_exists('form#auth');
67
68
    my $formdata = {
69
        userid => 'test',
70
        password => 'test',
71
        koha_login_context => 'opac',
72
    };
73
    $t->post_ok('/cgi-bin/koha/opac-user.pl', form => $formdata)
74
        ->element_exists_not('form#auth')
75
        ->text_like('.loggedinusername', qr/John Doe$/);
76
77
    $t->get_ok('/cgi-bin/koha/opac-user.pl?logout.x=1')
78
        ->element_exists('form#auth');
79
80
    $formdata = {
81
        userid => 'test',
82
        password => 'badpassword',
83
        koha_login_context => 'opac',
84
    };
85
    $t->post_ok('/cgi-bin/koha/opac-user.pl', form => $formdata)
86
        ->element_exists('form#auth')
87
        ->element_exists('div.alert');
88
};
89
90
$schema->storage->txn_rollback;

Return to bug 20635