Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::More; |
| 3 | use Test::Mojo; |
| 4 | use Mojo::File qw/path/; |
| 5 | use utf8; |
| 6 | |
| 7 | my $t = Test::Mojo->new('Kalamar' => { |
| 8 | Kalamar => { |
| 9 | plugins => ['Auth'] |
| 10 | } |
| 11 | }); |
| 12 | |
| 13 | $t->app->mode('production'); |
| 14 | |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 15 | my $q = qr!(?:\"|")!; |
| 16 | |
Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 17 | $t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' }) |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 18 | ->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') |
Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 27 | ->element_exists('input[name=handle][value=test]') |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 28 | ->element_exists_not('div.button.top a') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 29 | ->attr_is('body','data-korap-url','') |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 30 | ; |
| 31 | |
| 32 | is('kalamar',$t->app->sessions->cookie_name); |
| 33 | ok(!$t->app->sessions->secure); |
| 34 | |
| 35 | $t = Test::Mojo->new('Kalamar' => { |
| 36 | Kalamar => { |
| 37 | plugins => ['Auth'], |
| 38 | https_only => 1 |
| 39 | } |
| 40 | }); |
| 41 | |
Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 42 | $t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' }) |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 43 | ->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 | |
| 51 | is('kalamar',$t->app->sessions->cookie_name); |
| 52 | ok($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 | |
| 70 | is('kalamar-koraptest',$t->app->sessions->cookie_name); |
| 71 | ok($t->app->sessions->secure); |
| 72 | |
Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 73 | $t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' }) |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 74 | ->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') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 81 | ->attr_is('body','data-korap-url','/korap/test') |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 82 | ; |
| 83 | |
| 84 | |
| 85 | done_testing(); |