blob: d13fdc1cabf5d198f2a54f8a5d4ac648a0b4dc2b [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
Akronbc6b3f22021-01-13 14:53:12 +010015my $q = qr!(?:\"|")!;
16
Akrone208d302020-11-28 11:14:50 +010017$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020018 ->status_is(302)
19 ->header_is('Location' => '/');
20
21$t->get_ok('/')
22 ->status_is(200)
23 ->element_exists('link[rel=stylesheet][href^=/css/kalamar-]')
24 ->element_exists('script[src^=/js/kalamar-]')
25 ->element_exists('div.notify-error')
26 ->text_is('div.notify-error', 'Bad CSRF token')
Akrone208d302020-11-28 11:14:50 +010027 ->element_exists('input[name=handle][value=test]')
Akron0c4cd222019-07-19 16:33:34 +020028 ->element_exists_not('div.button.top a')
Akronbc6b3f22021-01-13 14:53:12 +010029 ->attr_is('body','data-korap-url','')
Akron1bee5a42021-01-13 17:44:18 +010030 ->header_exists_not('Strict-Transport-Security')
Akron0c4cd222019-07-19 16:33:34 +020031 ;
32
33is('kalamar',$t->app->sessions->cookie_name);
34ok(!$t->app->sessions->secure);
35
36$t = Test::Mojo->new('Kalamar' => {
37 Kalamar => {
38 plugins => ['Auth'],
39 https_only => 1
40 }
41});
42
Akrone208d302020-11-28 11:14:50 +010043$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020044 ->status_is(302)
Akron1bee5a42021-01-13 17:44:18 +010045 ->header_is('Location' => '/')
46 ->header_is('Strict-Transport-Security', 'max-age=3600; includeSubDomains')
47 ;
Akron0c4cd222019-07-19 16:33:34 +020048
49$t->get_ok('/')
50 ->status_is(200)
51 ->element_exists_not('div.notify-error')
52 ;
53
54is('kalamar',$t->app->sessions->cookie_name);
55ok($t->app->sessions->secure);
56
57$t = Test::Mojo->new('Kalamar' => {
58 Kalamar => {
59 plugins => ['Auth'],
60 proxy_prefix => '/korap/test',
61 https_only => 1
62 }
63});
64
65$t->app->mode('production');
66
67$t->get_ok('/')
68 ->status_is(200)
69 ->element_exists('link[rel=stylesheet][href^=/korap/test/css/kalamar-]')
70 ->element_exists('script[src^=/korap/test/js/kalamar-]')
71 ;
72
73is('kalamar-koraptest',$t->app->sessions->cookie_name);
74ok($t->app->sessions->secure);
75
Akrone208d302020-11-28 11:14:50 +010076$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020077 ->status_is(302)
78 ->header_is('Location' => '/');
79
80# Session can't be used
81$t->get_ok('/')
82 ->status_is(200)
83 ->element_exists_not('div.notify-error')
Akronbc6b3f22021-01-13 14:53:12 +010084 ->attr_is('body','data-korap-url','/korap/test')
Akron0c4cd222019-07-19 16:33:34 +020085 ;
86
87
88done_testing();