blob: 5731e138ece687dec9981367f210f5ef145036d4 [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','')
Akron0c4cd222019-07-19 16:33:34 +020030 ;
31
32is('kalamar',$t->app->sessions->cookie_name);
33ok(!$t->app->sessions->secure);
34
35$t = Test::Mojo->new('Kalamar' => {
36 Kalamar => {
37 plugins => ['Auth'],
38 https_only => 1
39 }
40});
41
Akrone208d302020-11-28 11:14:50 +010042$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020043 ->status_is(302)
44 ->header_is('Location' => '/');
45
46$t->get_ok('/')
47 ->status_is(200)
48 ->element_exists_not('div.notify-error')
49 ;
50
51is('kalamar',$t->app->sessions->cookie_name);
52ok($t->app->sessions->secure);
53
54$t = Test::Mojo->new('Kalamar' => {
55 Kalamar => {
56 plugins => ['Auth'],
57 proxy_prefix => '/korap/test',
58 https_only => 1
59 }
60});
61
62$t->app->mode('production');
63
64$t->get_ok('/')
65 ->status_is(200)
66 ->element_exists('link[rel=stylesheet][href^=/korap/test/css/kalamar-]')
67 ->element_exists('script[src^=/korap/test/js/kalamar-]')
68 ;
69
70is('kalamar-koraptest',$t->app->sessions->cookie_name);
71ok($t->app->sessions->secure);
72
Akrone208d302020-11-28 11:14:50 +010073$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
Akron0c4cd222019-07-19 16:33:34 +020074 ->status_is(302)
75 ->header_is('Location' => '/');
76
77# Session can't be used
78$t->get_ok('/')
79 ->status_is(200)
80 ->element_exists_not('div.notify-error')
Akronbc6b3f22021-01-13 14:53:12 +010081 ->attr_is('body','data-korap-url','/korap/test')
Akron0c4cd222019-07-19 16:33:34 +020082 ;
83
84
85done_testing();