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; |