blob: f1e57301f6e90431789b47b06115f277cc7c9fd3 [file] [log] [blame]
Akron0c4cd222019-07-19 16:33:34 +02001use Mojo::Base -strict;
2use Test::More;
3use Test::Mojo;
4use Mojo::File qw/path/;
5use utf8;
6
7my $t = Test::Mojo->new('Kalamar' => {
8 Kalamar => {
9 plugins => ['Auth']
Akron7fb78d62021-06-10 12:51:13 +020010 },
11 'Kalamar-Auth' => {
12 client_id => 2,
13 client_secret => 'k414m4r-s3cr3t',
14 oauth2 => 1
Akron0c4cd222019-07-19 16:33:34 +020015 }
16});
17
18$t->app->mode('production');
19
Akronbc6b3f22021-01-13 14:53:12 +010020my $q = qr!(?:\"|")!;
21
Akrone208d302020-11-28 11:14:50 +010022$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020023 ->status_is(302)
24 ->header_is('Location' => '/');
25
26$t->get_ok('/')
27 ->status_is(200)
28 ->element_exists('link[rel=stylesheet][href^=/css/kalamar-]')
29 ->element_exists('script[src^=/js/kalamar-]')
30 ->element_exists('div.notify-error')
31 ->text_is('div.notify-error', 'Bad CSRF token')
Akrone208d302020-11-28 11:14:50 +010032 ->element_exists('input[name=handle][value=test]')
Akron0c4cd222019-07-19 16:33:34 +020033 ->element_exists_not('div.button.top a')
Akronbc6b3f22021-01-13 14:53:12 +010034 ->attr_is('body','data-korap-url','')
Akron1bee5a42021-01-13 17:44:18 +010035 ->header_exists_not('Strict-Transport-Security')
Akron0c4cd222019-07-19 16:33:34 +020036 ;
37
38is('kalamar',$t->app->sessions->cookie_name);
39ok(!$t->app->sessions->secure);
40
41$t = Test::Mojo->new('Kalamar' => {
42 Kalamar => {
43 plugins => ['Auth'],
44 https_only => 1
Akron7fb78d62021-06-10 12:51:13 +020045 },
46 'Kalamar-Auth' => {
47 client_id => 2,
48 client_secret => 'k414m4r-s3cr3t',
49 oauth2 => 1
Akron0c4cd222019-07-19 16:33:34 +020050 }
51});
52
Akrone208d302020-11-28 11:14:50 +010053$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020054 ->status_is(302)
Akron1bee5a42021-01-13 17:44:18 +010055 ->header_is('Location' => '/')
56 ->header_is('Strict-Transport-Security', 'max-age=3600; includeSubDomains')
57 ;
Akron0c4cd222019-07-19 16:33:34 +020058
59$t->get_ok('/')
60 ->status_is(200)
61 ->element_exists_not('div.notify-error')
62 ;
63
64is('kalamar',$t->app->sessions->cookie_name);
65ok($t->app->sessions->secure);
66
67$t = Test::Mojo->new('Kalamar' => {
68 Kalamar => {
69 plugins => ['Auth'],
70 proxy_prefix => '/korap/test',
71 https_only => 1
Akron7fb78d62021-06-10 12:51:13 +020072 },
73 'Kalamar-Auth' => {
74 client_id => 2,
75 client_secret => 'k414m4r-s3cr3t',
76 oauth2 => 1
Akron0c4cd222019-07-19 16:33:34 +020077 }
78});
79
80$t->app->mode('production');
81
82$t->get_ok('/')
83 ->status_is(200)
84 ->element_exists('link[rel=stylesheet][href^=/korap/test/css/kalamar-]')
85 ->element_exists('script[src^=/korap/test/js/kalamar-]')
86 ;
87
88is('kalamar-koraptest',$t->app->sessions->cookie_name);
89ok($t->app->sessions->secure);
90
Akrone208d302020-11-28 11:14:50 +010091$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020092 ->status_is(302)
93 ->header_is('Location' => '/');
94
95# Session can't be used
96$t->get_ok('/')
97 ->status_is(200)
98 ->element_exists_not('div.notify-error')
Akronbc6b3f22021-01-13 14:53:12 +010099 ->attr_is('body','data-korap-url','/korap/test')
Akron0c4cd222019-07-19 16:33:34 +0200100 ;
101
102
103done_testing();