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