blob: 01cf33ea9648cb09ba218abd082edd02b34757c9 [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
15$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
16 ->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')
25 ->element_exists('input[name=handle_or_email][value=test]')
26 ->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
40$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
41 ->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
71$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
72 ->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();