Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use lib '../lib', 'lib'; |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 3 | use Test::More; |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 4 | use Test::Mojo; |
| 5 | use Data::Dumper; |
| 6 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 7 | $ENV{MOJO_MODE} = 'test'; |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 8 | |
| 9 | my $t = Test::Mojo->new('Kalamar'); |
| 10 | |
Akron | 7d75ee3 | 2017-05-02 13:42:41 +0200 | [diff] [blame] | 11 | $t->app->defaults(auth_support => 1); |
| 12 | |
Akron | bc213c0 | 2017-04-20 16:45:55 +0200 | [diff] [blame] | 13 | $t->get_ok('/?q=Baum') |
| 14 | ->status_is(200) |
| 15 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 16 | ->text_like('#total-results', qr/\d+$/) |
| 17 | ->content_like(qr/\"authorized\"\:null/) |
| 18 | ; |
| 19 | |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 20 | $t->get_ok('/') |
| 21 | ->element_exists('form[action=/user/login] input[name=handle_or_email]'); |
| 22 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 23 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' }) |
| 24 | ->status_is(302) |
| 25 | ->header_is('Location' => '/'); |
| 26 | |
| 27 | $t->get_ok('/') |
| 28 | ->status_is(200) |
| 29 | ->element_exists('div.notify-error') |
Akron | 2e3d377 | 2017-04-14 16:20:40 +0200 | [diff] [blame] | 30 | ->element_exists('input[name=handle_or_email][value=test]') |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 31 | ; |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 32 | |
Akron | e5ef4e0 | 2017-04-19 17:07:52 +0200 | [diff] [blame] | 33 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'pass' }) |
| 34 | ->status_is(302) |
| 35 | ->header_is('Location' => '/'); |
| 36 | |
| 37 | $t->get_ok('/') |
| 38 | ->status_is(200) |
| 39 | ->element_exists_not('div.notify-error') |
| 40 | ->element_exists('div.notify-success') |
Akron | bc213c0 | 2017-04-20 16:45:55 +0200 | [diff] [blame] | 41 | ->text_is('div.notify-success', 'Login successful') |
| 42 | ; |
| 43 | |
| 44 | # Now the user is logged in and should be able to |
| 45 | # search with authorization |
| 46 | $t->get_ok('/?q=Baum') |
| 47 | ->status_is(200) |
| 48 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 49 | ->text_like('#total-results', qr/\d+$/) |
| 50 | ->element_exists_not('div.notify-error') |
| 51 | ->content_like(qr/\"authorized\"\:\"test\"/) |
Akron | e5ef4e0 | 2017-04-19 17:07:52 +0200 | [diff] [blame] | 52 | ; |
| 53 | |
Akron | 2e3d377 | 2017-04-14 16:20:40 +0200 | [diff] [blame] | 54 | |
Akron | bc213c0 | 2017-04-20 16:45:55 +0200 | [diff] [blame] | 55 | # Logout |
| 56 | $t->get_ok('/user/logout') |
| 57 | ->status_is(302) |
| 58 | ->header_is('Location' => '/'); |
| 59 | |
| 60 | $t->get_ok('/') |
| 61 | ->status_is(200) |
| 62 | ->element_exists_not('div.notify-error') |
| 63 | ->element_exists('div.notify-success') |
| 64 | ->text_is('div.notify-success', 'Logout successful') |
| 65 | ; |
| 66 | |
| 67 | $t->get_ok('/?q=Baum') |
| 68 | ->status_is(200) |
| 69 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 70 | ->text_like('#total-results', qr/\d+$/) |
| 71 | ->content_like(qr/\"authorized\"\:null/) |
| 72 | ; |
| 73 | |
Akron | be9d5b3 | 2017-04-05 20:48:24 +0200 | [diff] [blame] | 74 | done_testing; |
| 75 | __END__ |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 76 | |
| 77 | |
Akron | 1b0c265 | 2017-04-27 15:28:49 +0200 | [diff] [blame] | 78 | # Login mit falschem Nutzernamen: |
| 79 | # 400 und: |
| 80 | {"errors":[[2022,"LDAP Authentication failed due to unknown user or password!"]]} |
| 81 | |
Akron | 741b2b1 | 2017-04-13 22:15:59 +0200 | [diff] [blame] | 82 | |
| 83 | |
Akron | e8235be | 2016-06-27 11:02:18 +0200 | [diff] [blame] | 84 | ok(!$c->user->get('details'), 'User not logged in'); |
| 85 | |
| 86 | # Login with user credentials |
| 87 | ok($c->user->login('kustvakt', 'kustvakt2015'), 'Login with demo user'); |
| 88 | is($c->stash('user'), 'kustvakt', 'Kustvakt is logged in'); |
| 89 | like($c->stash('auth'), qr/^api_token /, 'Kustvakt is logged in'); |
| 90 | |
| 91 | my $details = $c->user->get('details'); |
| 92 | is($details->{email}, 'kustvakt@ids-mannheim.de', 'Email'); |
| 93 | is($details->{firstName}, 'Kustvakt', 'Firstname'); |
| 94 | is($details->{lastName}, 'KorAP', 'Lastname'); |
| 95 | is($details->{country}, 'Germany', 'Country'); |
| 96 | is($details->{address}, 'Mannheim', 'Address'); |
| 97 | is($details->{username}, 'kustvakt', 'Username'); |
| 98 | is($details->{institution}, 'IDS Mannheim', 'Institution'); |
| 99 | |
| 100 | my $settings = $c->user->get('settings'); |
| 101 | is($settings->{username}, 'kustvakt', 'Username'); |
| 102 | |
| 103 | # ok($c->user->set(details => { firstName => 'Me' }), 'Set first name'); |
| 104 | #ok($c->user->set(details => { |
| 105 | # firstName => 'Akron', |
| 106 | # lastName => 'Fuxfell' |
| 107 | #}), 'Set first name'); |
| 108 | |
| 109 | # diag Dumper $c->user->get('info'); |
| 110 | |
| 111 | ok(1,'Fine'); |
| 112 | |
| 113 | done_testing; |
| 114 | __END__ |