blob: e4aa9a4b42a0ba4d561513fcc9006b41d3c1f97e [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']
10 }
11});
12
13$t->app->mode('production');
14
Akrone208d302020-11-28 11:14:50 +010015$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020016 ->status_is(302)
17 ->header_is('Location' => '/');
18
19$t->get_ok('/')
20 ->status_is(200)
21 ->element_exists('link[rel=stylesheet][href^=/css/kalamar-]')
22 ->element_exists('script[src^=/js/kalamar-]')
23 ->element_exists('div.notify-error')
24 ->text_is('div.notify-error', 'Bad CSRF token')
Akrone208d302020-11-28 11:14:50 +010025 ->element_exists('input[name=handle][value=test]')
Akron0c4cd222019-07-19 16:33:34 +020026 ->element_exists_not('div.button.top a')
27 ->content_like(qr!KorAP\.URL = ''!)
28 ;
29
30is('kalamar',$t->app->sessions->cookie_name);
31ok(!$t->app->sessions->secure);
32
33$t = Test::Mojo->new('Kalamar' => {
34 Kalamar => {
35 plugins => ['Auth'],
36 https_only => 1
37 }
38});
39
Akrone208d302020-11-28 11:14:50 +010040$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020041 ->status_is(302)
42 ->header_is('Location' => '/');
43
44$t->get_ok('/')
45 ->status_is(200)
46 ->element_exists_not('div.notify-error')
47 ;
48
49is('kalamar',$t->app->sessions->cookie_name);
50ok($t->app->sessions->secure);
51
52$t = Test::Mojo->new('Kalamar' => {
53 Kalamar => {
54 plugins => ['Auth'],
55 proxy_prefix => '/korap/test',
56 https_only => 1
57 }
58});
59
60$t->app->mode('production');
61
62$t->get_ok('/')
63 ->status_is(200)
64 ->element_exists('link[rel=stylesheet][href^=/korap/test/css/kalamar-]')
65 ->element_exists('script[src^=/korap/test/js/kalamar-]')
66 ;
67
68is('kalamar-koraptest',$t->app->sessions->cookie_name);
69ok($t->app->sessions->secure);
70
Akrone208d302020-11-28 11:14:50 +010071$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020072 ->status_is(302)
73 ->header_is('Location' => '/');
74
75# Session can't be used
76$t->get_ok('/')
77 ->status_is(200)
78 ->element_exists_not('div.notify-error')
79 ->content_like(qr!KorAP\.URL = '/korap/test'!)
80 ;
81
82
83done_testing();