| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; | 
|  | 2 | use Test::More; | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 3 | use Test::Mojo::WithRoles 'Session'; | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 4 | use Mojo::File qw/path/; | 
|  | 5 | use Data::Dumper; | 
|  | 6 |  | 
|  | 7 |  | 
|  | 8 | ##################### | 
|  | 9 | # Start Fake server # | 
|  | 10 | ##################### | 
| Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 11 | my $mount_point = '/realapi/'; | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 12 | $ENV{KALAMAR_API} = $mount_point; | 
|  | 13 |  | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 14 | my $t = Test::Mojo::WithRoles->new('Kalamar' => { | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 15 | Kalamar => { | 
|  | 16 | plugins => ['Auth'] | 
|  | 17 | }, | 
|  | 18 | 'Kalamar-Auth' => { | 
|  | 19 | client_id => 2, | 
|  | 20 | client_secret => 'k414m4r-s3cr3t', | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 21 | oauth2 => 1, | 
|  | 22 | experimental_client_registration => 1 | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 23 | } | 
|  | 24 | }); | 
|  | 25 |  | 
|  | 26 | # Mount fake backend | 
|  | 27 | # Get the fixture path | 
|  | 28 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, '..', 'server'); | 
|  | 29 | my $fake_backend = $t->app->plugin( | 
|  | 30 | Mount => { | 
|  | 31 | $mount_point => | 
|  | 32 | $fixtures_path->child('mock.pl') | 
|  | 33 | } | 
|  | 34 | ); | 
|  | 35 | # Configure fake backend | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 36 | my $fake_backend_app = $fake_backend->pattern->defaults->{app}; | 
|  | 37 |  | 
|  | 38 | # Set general app logger for simplicity | 
|  | 39 | $fake_backend_app->log($t->app->log); | 
|  | 40 |  | 
|  | 41 | my $access_token = $fake_backend_app->get_token('access_token'); | 
|  | 42 | my $refresh_token = $fake_backend_app->get_token('refresh_token'); | 
|  | 43 | my $access_token_2 = $fake_backend_app->get_token('access_token_2'); | 
|  | 44 | my $refresh_token_2 = $fake_backend_app->get_token('refresh_token_2'); | 
|  | 45 |  | 
|  | 46 | # Some routes to modify the session | 
|  | 47 | # This expires the session | 
|  | 48 | $t->app->routes->get('/x/expire')->to( | 
|  | 49 | cb => sub { | 
|  | 50 | my $c = shift; | 
|  | 51 | $c->session(auth_exp => 0); | 
|  | 52 | return $c->render(text => 'okay') | 
|  | 53 | } | 
|  | 54 | ); | 
|  | 55 |  | 
|  | 56 | # This expires the session and removes the refresh token | 
|  | 57 | $t->app->routes->get('/x/expire-no-refresh')->to( | 
|  | 58 | cb => sub { | 
|  | 59 | my $c = shift; | 
|  | 60 | $c->session(auth_exp => 0); | 
|  | 61 | delete $c->session->{auth_r}; | 
|  | 62 | return $c->render(text => 'okay') | 
|  | 63 | } | 
|  | 64 | ); | 
|  | 65 |  | 
|  | 66 | # This sets an invalid token | 
|  | 67 | $t->app->routes->get('/x/invalid')->to( | 
|  | 68 | cb => sub { | 
|  | 69 | my $c = shift; | 
|  | 70 | $c->session(auth_exp => time + 1000); | 
|  | 71 | $c->session(auth_r => $refresh_token_2); | 
|  | 72 | $c->session(auth => 'Bearer inv4lid'); | 
|  | 73 | return $c->render(text => 'okay') | 
|  | 74 | } | 
|  | 75 | ); | 
|  | 76 |  | 
|  | 77 |  | 
|  | 78 | # This sets an invalid token | 
|  | 79 | $t->app->routes->get('/x/invalid-no-refresh')->to( | 
|  | 80 | cb => sub { | 
|  | 81 | my $c = shift; | 
|  | 82 | $c->session(auth_exp => time + 1000); | 
|  | 83 | delete $c->session->{auth_r}; | 
|  | 84 | $c->session(auth => 'Bearer inv4lid'); | 
|  | 85 | return $c->render(text => 'okay') | 
|  | 86 | } | 
|  | 87 | ); | 
|  | 88 |  | 
|  | 89 | # This sets an invalid refresh token | 
|  | 90 | $t->app->routes->get('/x/expired-with-wrong-refresh')->to( | 
|  | 91 | cb => sub { | 
|  | 92 | my $c = shift; | 
|  | 93 | $c->session(auth_exp => 0); | 
|  | 94 | $c->session(auth => 'Bearer inv4lid'); | 
|  | 95 | $c->session(auth_r => 'inv4lid'); | 
|  | 96 | return $c->render(text => 'okay') | 
|  | 97 | } | 
|  | 98 | ); | 
|  | 99 |  | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 100 | my $q = qr!(?:\"|")!; | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 101 |  | 
| Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 102 | $t->get_ok('/realapi/v1.0') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 103 | ->status_is(200) | 
|  | 104 | ->content_is('Fake server available'); | 
|  | 105 |  | 
|  | 106 | $t->get_ok('/?q=Baum') | 
|  | 107 | ->status_is(200) | 
|  | 108 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) | 
|  | 109 | ->text_like('#total-results', qr/\d+$/) | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 110 | ->content_like(qr/${q}authorized${q}:null/) | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 111 | ->element_exists_not('div.button.top a') | 
|  | 112 | ->element_exists_not('aside.active') | 
|  | 113 | ->element_exists_not('aside.off') | 
|  | 114 | ; | 
|  | 115 |  | 
|  | 116 | $t->get_ok('/') | 
|  | 117 | ->status_is(200) | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 118 | ->element_exists('form[action=/user/login] input[name=handle]') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 119 | ->element_exists('aside.active') | 
|  | 120 | ->element_exists_not('aside.off') | 
|  | 121 | ; | 
|  | 122 |  | 
| Akron | 3e0fdc1 | 2020-05-15 16:17:21 +0200 | [diff] [blame] | 123 | # Test for bug with long password | 
|  | 124 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 125 | handle => 'test', | 
| Akron | 3e0fdc1 | 2020-05-15 16:17:21 +0200 | [diff] [blame] | 126 | pwd => 'kjskjhndkjndqknaskjnakjdnkjdankajdnkjdsankjdsakjdfkjahzroiuqzriudjoijdmlamdlkmdsalkmdl' }) | 
|  | 127 | ->status_is(302) | 
|  | 128 | ->header_is('Location' => '/'); | 
|  | 129 |  | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 130 | $t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' }) | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 131 | ->status_is(302) | 
|  | 132 | ->header_is('Location' => '/'); | 
|  | 133 |  | 
|  | 134 | $t->get_ok('/') | 
|  | 135 | ->status_is(200) | 
|  | 136 | ->element_exists('div.notify-error') | 
|  | 137 | ->text_is('div.notify-error', 'Bad CSRF token') | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 138 | ->element_exists('input[name=handle][value=test]') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 139 | ->element_exists_not('div.button.top a') | 
|  | 140 | ; | 
|  | 141 |  | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 142 | $t->post_ok('/user/login' => form => { handle => 'test', pwd => 'pass' }) | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 143 | ->status_is(302) | 
|  | 144 | ->header_is('Location' => '/'); | 
|  | 145 |  | 
|  | 146 | my $csrf = $t->get_ok('/') | 
|  | 147 | ->status_is(200) | 
|  | 148 | ->element_exists('div.notify-error') | 
|  | 149 | ->text_is('div.notify-error', 'Bad CSRF token') | 
|  | 150 | ->element_exists_not('div.button.top a') | 
|  | 151 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') | 
|  | 152 | ; | 
|  | 153 |  | 
|  | 154 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 155 | handle => 'test', | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 156 | pwd => 'ldaperr', | 
|  | 157 | csrf_token => $csrf | 
|  | 158 | }) | 
|  | 159 | ->status_is(302) | 
|  | 160 | ->content_is('') | 
|  | 161 | ->header_is('Location' => '/'); | 
|  | 162 |  | 
|  | 163 | $csrf = $t->get_ok('/') | 
|  | 164 | ->status_is(200) | 
|  | 165 | ->element_exists('div.notify-error') | 
|  | 166 | ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!') | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 167 | ->element_exists('input[name=handle][value=test]') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 168 | ->element_exists_not('div.button.top a') | 
| Akron | 3b3c7af | 2020-05-15 16:23:55 +0200 | [diff] [blame] | 169 | ->element_exists_not('div.notify-success') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 170 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') | 
|  | 171 | ; | 
|  | 172 |  | 
|  | 173 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 174 | handle => 'test', | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 175 | pwd => 'unknown', | 
|  | 176 | csrf_token => $csrf | 
|  | 177 | }) | 
|  | 178 | ->status_is(302) | 
|  | 179 | ->content_is('') | 
|  | 180 | ->header_is('Location' => '/'); | 
|  | 181 |  | 
|  | 182 | $csrf = $t->get_ok('/') | 
|  | 183 | ->status_is(200) | 
|  | 184 | ->element_exists('div.notify-error') | 
| Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 185 | ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!') | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 186 | ->element_exists('input[name=handle][value=test]') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 187 | ->element_exists_not('div.button.top a') | 
|  | 188 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') | 
|  | 189 | ; | 
|  | 190 |  | 
|  | 191 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 192 | handle => 'test', | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 193 | pwd => 'pass', | 
|  | 194 | csrf_token => $csrf | 
|  | 195 | }) | 
|  | 196 | ->status_is(302) | 
|  | 197 | ->content_is('') | 
|  | 198 | ->header_is('Location' => '/'); | 
|  | 199 |  | 
|  | 200 | $t->get_ok('/') | 
|  | 201 | ->status_is(200) | 
|  | 202 | ->element_exists_not('div.notify-error') | 
|  | 203 | ->element_exists('div.notify-success') | 
|  | 204 | ->text_is('div.notify-success', 'Login successful') | 
| Akron | 1d09b53 | 2021-06-15 18:18:25 +0200 | [diff] [blame^] | 205 | ->element_exists_not('aside.off') | 
|  | 206 | ->element_exists('aside.active') | 
|  | 207 | ->element_exists('aside.settings') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 208 | ; | 
|  | 209 |  | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 210 | # Now the user is logged in and should be able to | 
|  | 211 | # search with authorization | 
|  | 212 | $t->get_ok('/?q=Baum') | 
|  | 213 | ->status_is(200) | 
| Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 214 | ->session_has('/auth') | 
|  | 215 | ->session_is('/auth', 'Bearer ' . $access_token) | 
|  | 216 | ->session_is('/auth_r', $refresh_token) | 
|  | 217 | ->session_is('/user', 'test') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 218 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) | 
|  | 219 | ->text_like('#total-results', qr/\d+$/) | 
|  | 220 | ->element_exists_not('div.notify-error') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 221 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 222 | ->element_exists('div.button.top a') | 
|  | 223 | ->element_exists('div.button.top a.logout[title~="test"]') | 
|  | 224 | ; | 
|  | 225 |  | 
| Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 226 | $t->get_ok('/?q=Paum') | 
|  | 227 | ->status_is(200) | 
|  | 228 | ->text_like('h1 span', qr/KorAP: Find .Paum./i) | 
|  | 229 | ->text_is('#total-results', '') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 230 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 231 | ->element_exists_not('p.hint') | 
|  | 232 | ; | 
|  | 233 |  | 
|  | 234 |  | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 235 | # Logout | 
|  | 236 | $t->get_ok('/user/logout') | 
|  | 237 | ->status_is(302) | 
| Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 238 | ->session_hasnt('/auth') | 
|  | 239 | ->session_hasnt('/auth_r') | 
|  | 240 | ->session_hasnt('/user') | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 241 | ->header_is('Location' => '/'); | 
|  | 242 |  | 
|  | 243 | $t->get_ok('/') | 
|  | 244 | ->status_is(200) | 
|  | 245 | ->element_exists_not('div.notify-error') | 
|  | 246 | ->element_exists('div.notify-success') | 
|  | 247 | ->text_is('div.notify-success', 'Logout successful') | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 248 | ->element_exists("input[name=handle]") | 
|  | 249 | ->element_exists("input[name=handle][value=test]") | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 250 | ; | 
|  | 251 |  | 
|  | 252 | $t->get_ok('/?q=Baum') | 
|  | 253 | ->status_is(200) | 
|  | 254 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) | 
|  | 255 | ->text_like('#total-results', qr/\d+$/) | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 256 | ->content_like(qr/${q}authorized${q}:null/) | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 257 | ; | 
|  | 258 |  | 
| Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 259 | $t->get_ok('/?q=Paum') | 
|  | 260 | ->status_is(200) | 
|  | 261 | ->text_like('h1 span', qr/KorAP: Find .Paum./i) | 
|  | 262 | ->text_is('#total-results', '') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 263 | ->content_like(qr/${q}authorized${q}:null/) | 
| Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 264 | ->text_is('p.hint', 'Maybe you need to log in first?') | 
|  | 265 | ; | 
|  | 266 |  | 
|  | 267 |  | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 268 | # Get redirect | 
|  | 269 | my $fwd = $t->get_ok('/?q=Baum&ql=poliqarp') | 
|  | 270 | ->status_is(200) | 
|  | 271 | ->element_exists_not('div.notify-error') | 
|  | 272 | ->tx->res->dom->at('input[name=fwd]')->attr('value') | 
|  | 273 | ; | 
|  | 274 |  | 
|  | 275 | is($fwd, '/?q=Baum&ql=poliqarp', 'Redirect is valid'); | 
|  | 276 |  | 
|  | 277 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 278 | handle => 'test', | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 279 | pwd => 'pass', | 
|  | 280 | csrf_token => $csrf, | 
|  | 281 | fwd => 'http://bad.example.com/test' | 
|  | 282 | }) | 
|  | 283 | ->status_is(302) | 
|  | 284 | ->header_is('Location' => '/'); | 
|  | 285 |  | 
|  | 286 | $t->get_ok('/') | 
|  | 287 | ->status_is(200) | 
|  | 288 | ->element_exists('div.notify-error') | 
|  | 289 | ->element_exists_not('div.notify-success') | 
|  | 290 | ->text_is('div.notify-error', 'Redirect failure') | 
|  | 291 | ; | 
|  | 292 |  | 
|  | 293 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 294 | handle => 'test', | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 295 | pwd => 'pass', | 
|  | 296 | csrf_token => $csrf, | 
|  | 297 | fwd => $fwd | 
|  | 298 | }) | 
|  | 299 | ->status_is(302) | 
|  | 300 | ->header_is('Location' => '/?q=Baum&ql=poliqarp'); | 
|  | 301 |  | 
| Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 302 | $t->get_ok('/?q=Baum&ql=poliqarp') | 
|  | 303 | ->status_is(200) | 
|  | 304 | ->element_exists_not('div.notify-error') | 
|  | 305 | ->element_exists('div.notify-success') | 
|  | 306 | ->text_is('div.notify-success', 'Login successful') | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 307 | ->session_has('/auth') | 
|  | 308 | ->session_is('/auth', 'Bearer ' . $access_token) | 
|  | 309 | ->session_is('/auth_r', $refresh_token) | 
|  | 310 | ->header_isnt('X-Kalamar-Cache', 'true') | 
| Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 311 | ; | 
|  | 312 |  | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 313 | # Expire the session | 
|  | 314 | # (makes the token be marked as expired - though it isn't serverside) | 
|  | 315 | $t->get_ok('/x/expire') | 
| Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 316 | ->status_is(200) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 317 | ->content_is('okay') | 
|  | 318 | ; | 
|  | 319 |  | 
|  | 320 | ## It may be a problem, but the cache is still valid | 
|  | 321 | $t->get_ok('/?q=Baum') | 
|  | 322 | ->status_is(200) | 
|  | 323 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) | 
|  | 324 | ->text_like('#total-results', qr/\d+$/) | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 325 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 326 | ->header_is('X-Kalamar-Cache', 'true') | 
|  | 327 | ; | 
|  | 328 |  | 
|  | 329 | # Query without partial cache (unfortunately) (but no total results) | 
|  | 330 | $t->get_ok('/?q=baum&cutoff=true') | 
|  | 331 | ->status_is(200) | 
|  | 332 | ->session_is('/auth', 'Bearer ' . $access_token_2) | 
|  | 333 | ->session_is('/auth_r', $refresh_token_2) | 
|  | 334 | ->text_is('#error','') | 
|  | 335 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') | 
|  | 336 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') | 
|  | 337 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 338 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 339 | ->header_isnt('X-Kalamar-Cache', 'true') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 340 | ->content_like(qr!${q}cutOff${q}:true!) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 341 | ->element_exists_not('#total-results') | 
|  | 342 | ; | 
|  | 343 |  | 
|  | 344 | # Expire the session and remove the refresh option | 
|  | 345 | $t->get_ok('/x/expire-no-refresh') | 
|  | 346 | ->status_is(200) | 
|  | 347 | ->content_is('okay') | 
|  | 348 | ; | 
|  | 349 |  | 
|  | 350 | $t->app->defaults(no_cache => 1); | 
|  | 351 |  | 
|  | 352 |  | 
|  | 353 | $t->get_ok('/x/invalid-no-refresh') | 
|  | 354 | ->status_is(200) | 
|  | 355 | ->content_is('okay') | 
|  | 356 | ; | 
|  | 357 |  | 
|  | 358 | # Query without cache | 
|  | 359 | # The token is invalid and can't be refreshed! | 
|  | 360 | $t->get_ok('/?q=baum&cutoff=true') | 
| Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 361 | ->status_is(400) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 362 | ->session_hasnt('/auth') | 
|  | 363 | ->session_hasnt('/auth_r') | 
|  | 364 | ->text_is('#error','') | 
|  | 365 | ->text_is('div.notify-error','Access token invalid') | 
|  | 366 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') | 
|  | 367 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') | 
|  | 368 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 369 | ->content_unlike(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 370 | ->header_isnt('X-Kalamar-Cache', 'true') | 
|  | 371 | ->element_exists('p.no-results') | 
|  | 372 | ; | 
|  | 373 |  | 
|  | 374 | $t->get_ok('/x/invalid') | 
|  | 375 | ->status_is(200) | 
|  | 376 | ->content_is('okay') | 
|  | 377 | ; | 
|  | 378 |  | 
|  | 379 | # Query without cache | 
|  | 380 | # The token is invalid and can't be refreshed! | 
|  | 381 | $t->get_ok('/?q=baum&cutoff=true') | 
|  | 382 | ->status_is(200) | 
|  | 383 | ->session_is('/auth', 'Bearer ' . $access_token_2) | 
|  | 384 | ->session_is('/auth_r', $refresh_token_2) | 
|  | 385 | ->text_is('#error','') | 
|  | 386 | ->element_exists_not('div.notify-error','Access token invalid') | 
|  | 387 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') | 
|  | 388 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') | 
|  | 389 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 390 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 391 | ->header_isnt('X-Kalamar-Cache', 'true') | 
|  | 392 | ->element_exists_not('p.no-results') | 
| Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 393 | ; | 
|  | 394 |  | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 395 |  | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 396 | $t->get_ok('/x/expired-with-wrong-refresh') | 
|  | 397 | ->status_is(200) | 
|  | 398 | ->content_is('okay') | 
|  | 399 | ; | 
| Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 400 |  | 
| Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 401 |  | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 402 | # The token is invalid and can't be refreshed! | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 403 | $csrf = $t->get_ok('/?q=baum&cutoff=true') | 
| Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 404 | ->status_is(400) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 405 | ->session_hasnt('/auth') | 
|  | 406 | ->session_hasnt('/auth_r') | 
|  | 407 | ->text_is('#error','') | 
|  | 408 | ->text_is('div.notify-error','Refresh token is expired') | 
|  | 409 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') | 
| Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 410 | ->content_unlike(qr/${q}authorized${q}:${q}yes${q}/) | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 411 | ->element_exists('p.no-results') | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 412 | ->tx->res->dom->at('input[name="csrf_token"]') | 
|  | 413 | ->attr('value') | 
| Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 414 | ; | 
| Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 415 |  | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 416 | # Login: | 
|  | 417 | $t->post_ok('/user/login' => form => { | 
| Akron | e208d30 | 2020-11-28 11:14:50 +0100 | [diff] [blame] | 418 | handle => 'test', | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 419 | pwd => 'pass', | 
|  | 420 | csrf_token => $csrf | 
|  | 421 | }) | 
|  | 422 | ->status_is(302) | 
|  | 423 | ->content_is('') | 
|  | 424 | ->header_is('Location' => '/'); | 
|  | 425 |  | 
|  | 426 | $t->get_ok('/') | 
|  | 427 | ->status_is(200) | 
|  | 428 | ->element_exists_not('div.notify-error') | 
|  | 429 | ->element_exists('div.notify-success') | 
|  | 430 | ->text_is('div.notify-success', 'Login successful') | 
| Akron | 1d09b53 | 2021-06-15 18:18:25 +0200 | [diff] [blame^] | 431 | ->element_exists_not('aside.off') | 
|  | 432 | ->element_exists('aside.active') | 
|  | 433 | ->element_exists('aside.settings') | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 434 | ; | 
|  | 435 |  | 
|  | 436 | $t->get_ok('/settings/oauth') | 
|  | 437 | ->text_is('form.form-table legend', 'Register new client application') | 
|  | 438 | ->attr_is('form.oauth-register','action', '/settings/oauth/register') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 439 | ->element_exists('ul.client-list') | 
|  | 440 | ->element_exists_not('ul.client-list > li') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 441 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 442 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 443 | ->header_is('Pragma','no-cache') | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 444 | ; | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 445 |  | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 446 | $csrf = $t->post_ok('/settings/oauth/register' => form => { | 
|  | 447 | name => 'MyApp', | 
|  | 448 | type => 'PUBLIC', | 
|  | 449 | desc => 'This is my application' | 
|  | 450 | }) | 
|  | 451 | ->text_is('div.notify-error', 'Bad CSRF token') | 
|  | 452 | ->tx->res->dom->at('input[name="csrf_token"]') | 
|  | 453 | ->attr('value') | 
|  | 454 | ; | 
|  | 455 |  | 
|  | 456 | $t->post_ok('/settings/oauth/register' => form => { | 
|  | 457 | name => 'MyApp', | 
|  | 458 | type => 'CONFIDENTIAL', | 
|  | 459 | desc => 'This is my application', | 
|  | 460 | csrf_token => $csrf | 
|  | 461 | }) | 
|  | 462 | ->status_is(200) | 
|  | 463 | ->element_exists('div.notify-success') | 
|  | 464 | ->text_is('legend', 'Client Credentials') | 
|  | 465 | ->text_is('label[for=client_id]', 'ID of the client application') | 
|  | 466 | ->element_exists('input[name=client_id][readonly][value]') | 
|  | 467 | ->element_exists('input[name=client_secret][readonly][value]') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 468 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 469 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 470 | ->header_is('Pragma','no-cache') | 
| Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 471 | ; | 
| Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 472 |  | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 473 | $t->get_ok('/settings/oauth') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 474 | ->text_is('.form-table legend', 'Register new client application') | 
|  | 475 | ->attr_is('.oauth-register','action', '/settings/oauth/register') | 
| Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 476 | ->text_is('ul.client-list > li > span.client-name a', 'MyApp') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 477 | ->text_is('ul.client-list > li > span.client-desc', 'This is my application') | 
|  | 478 | ->text_is('ul.client-list > li > span.client-url a', '') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 479 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 480 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 481 | ->header_is('Pragma','no-cache') | 
| Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 482 | ; | 
|  | 483 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 484 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 485 | ->status_is(200) | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 486 | ->text_is('ul.client-list > li.client > span.client-name', 'MyApp') | 
|  | 487 | ->text_is('ul.client-list > li.client > span.client-desc', 'This is my application') | 
| Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 488 | ->text_is('a.client-unregister', 'Unregister') | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 489 | ->attr_is('a.client-unregister', 'href', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/unregister?name=MyApp') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 490 | ; | 
|  | 491 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 492 | $csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/unregister?name=MyApp') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 493 | ->content_like(qr!Do you really want to unregister \<span class="client-name"\>MyApp\<\/span\>?!) | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 494 | ->attr_is('.form-table input[name=client-name]', 'value', 'MyApp') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 495 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 496 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 497 | ->header_is('Pragma','no-cache') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 498 | ->tx->res->dom->at('input[name="csrf_token"]') | 
|  | 499 | ->attr('value') | 
|  | 500 | ; | 
|  | 501 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 502 | $t->post_ok('/settings/oauth/xxxx==/unregister' => form => { | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 503 | 'client-name' => 'MyApp', | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 504 | 'csrf_token' => $csrf | 
|  | 505 | })->status_is(302) | 
|  | 506 | ->content_is('') | 
|  | 507 | ->header_is('Location' => '/settings/oauth') | 
|  | 508 | ; | 
|  | 509 |  | 
|  | 510 | $t->get_ok('/settings/oauth') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 511 | ->text_is('.form-table legend', 'Register new client application') | 
|  | 512 | ->attr_is('.oauth-register','action', '/settings/oauth/register') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 513 | ->element_exists('ul.client-list > li') | 
|  | 514 | ->text_is('div.notify', 'Unknown client with xxxx==.') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 515 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 516 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 517 | ->header_is('Pragma','no-cache') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 518 | ; | 
|  | 519 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 520 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/unregister' => form => { | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 521 | 'client-name' => 'MyApp', | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 522 | 'csrf_token' => $csrf | 
|  | 523 | })->status_is(302) | 
|  | 524 | ->content_is('') | 
|  | 525 | ->header_is('Location' => '/settings/oauth') | 
|  | 526 | ; | 
|  | 527 |  | 
|  | 528 | $t->get_ok('/settings/oauth') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 529 | ->text_is('.form-table legend', 'Register new client application') | 
|  | 530 | ->attr_is('.oauth-register','action', '/settings/oauth/register') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 531 | ->element_exists_not('ul.client-list > li') | 
|  | 532 | ->text_is('div.notify-success', 'Successfully deleted MyApp') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 533 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 534 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 535 | ->header_is('Pragma','no-cache') | 
| Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 536 | ; | 
|  | 537 |  | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 538 | $t->post_ok('/settings/oauth/register' => form => { | 
|  | 539 | name => 'MyApp2', | 
|  | 540 | type => 'PUBLIC', | 
|  | 541 | desc => 'This is my application', | 
|  | 542 | csrf_token => $csrf | 
|  | 543 | })->status_is(200) | 
|  | 544 | ->element_exists('div.notify-success') | 
|  | 545 | ->text_is('legend', 'Client Credentials') | 
|  | 546 | ->text_is('label[for=client_id]', 'ID of the client application') | 
|  | 547 | ->element_exists('input[name=client_id][readonly][value]') | 
|  | 548 | ->element_exists_not('input[name=client_secret][readonly][value]') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 549 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 550 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 551 | ->header_is('Pragma','no-cache') | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 552 | ; | 
|  | 553 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 554 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 555 | ->text_is('.client-name', 'MyApp2') | 
|  | 556 | ->text_is('.client-desc', 'This is my application') | 
| Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 557 | ->text_is('.client-issue-token', 'Issue new token') | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 558 | ->attr_is('.client-issue-token', 'href', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?name=MyApp2') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 559 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 560 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 561 | ->header_is('Pragma','no-cache') | 
| Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 562 | ->text_is('ul.token-list label[for=token]', 'Access Token') | 
|  | 563 | ->text_is('p[name=created]', 'Created at ') | 
|  | 564 | ->text_is('p[name=expires]', 'Expires in 31533851 seconds.') | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 565 | ; | 
|  | 566 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 567 | $csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?name=MyApp2') | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 568 | ->status_is(200) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 569 | ->attr_is('#issue-token','action', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token') | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 570 | ->attr_is('input[name=client-id]', 'value', 'fCBbQkA2NDA3MzM1Yw==') | 
|  | 571 | ->attr_is('input[name=name]', 'value', 'MyApp2') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 572 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 573 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 574 | ->header_is('Pragma','no-cache') | 
| Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 575 | ->text_is('a.button-abort', 'Abort') | 
|  | 576 | ->attr_is('#issue-token input[type=submit]', 'value', 'Issue new token') | 
|  | 577 | ->content_like(qr!Issue a new token for!) | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 578 | ->tx->res->dom->at('input[name="csrf_token"]') | 
|  | 579 | ->attr('value') | 
|  | 580 | ; | 
|  | 581 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 582 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token' => form => { | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 583 | csrf_token => $csrf, | 
|  | 584 | name => 'MyApp2', | 
|  | 585 | 'client-id' => 'fCBbQkA2NDA3MzM1Yw==' | 
|  | 586 | }) | 
| Akron | bc94a9c | 2021-04-15 00:07:35 +0200 | [diff] [blame] | 587 | ->status_is(302) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 588 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | bc94a9c | 2021-04-15 00:07:35 +0200 | [diff] [blame] | 589 | ; | 
|  | 590 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 591 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
|  | 592 | ->status_is(200) | 
| Akron | bc94a9c | 2021-04-15 00:07:35 +0200 | [diff] [blame] | 593 | ->text_is('div.notify-success', 'New access token created') | 
| Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 594 | ->status_is(200) | 
|  | 595 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') | 
|  | 596 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') | 
|  | 597 | ->header_is('Pragma','no-cache') | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 598 | ; | 
|  | 599 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 600 | $csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 601 | ->status_is(200) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 602 | ->attr_is('form.token-revoke', 'action', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token/revoke') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 603 | ->attr_is('form.token-revoke input[name=token]', 'value', 'jhkhkjhk_hjgjsfz67i') | 
|  | 604 | ->attr_is('form.token-revoke input[name=name]', 'value', 'MyApp2') | 
|  | 605 | ->tx->res->dom->at('input[name="csrf_token"]') | 
|  | 606 | ->attr('value') | 
|  | 607 | ; | 
|  | 608 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 609 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token/revoke' => form => { | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 610 | csrf_token => $csrf, | 
|  | 611 | name => 'MyApp2', | 
|  | 612 | token => 'jhkhkjhk_hjgjsfz67i' | 
|  | 613 | }) | 
|  | 614 | ->status_is(200) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 615 | ->attr_is('form#revoke-token','action','/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 616 | ->attr_is('form#revoke-token','method','POST') | 
|  | 617 | ->attr_is('form#revoke-token input[name=token]','value','jhkhkjhk_hjgjsfz67i') | 
| Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 618 | ->text_is('a.button-abort', 'Abort') | 
|  | 619 | ->attr_is('#revoke-token input[type=submit]', 'value', 'Revoke') | 
|  | 620 | ->content_like(qr!Revoke a token for!) | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 621 | ; | 
|  | 622 |  | 
|  | 623 |  | 
|  | 624 | # CSRF missing | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 625 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE' => form => { | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 626 | name => 'MyApp2', | 
|  | 627 | token => 'jhkhkjhk_hjgjsfz67i' | 
|  | 628 | })->status_is(302) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 629 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 630 | ; | 
|  | 631 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 632 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 633 | ->element_exists_not('div.notify-success') | 
|  | 634 | ->text_is('div.notify-error', 'Bad CSRF token') | 
|  | 635 | ; | 
|  | 636 |  | 
|  | 637 | # Token missing | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 638 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE' => form => { | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 639 | name => 'MyApp2', | 
|  | 640 | csrf_token => $csrf, | 
|  | 641 | })->status_is(302) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 642 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 643 | ; | 
|  | 644 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 645 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 646 | ->element_exists_not('div.notify-success') | 
|  | 647 | ->text_is('div.notify-error', 'Some fields are invalid') | 
|  | 648 | ; | 
|  | 649 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 650 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE' => form => { | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 651 | name => 'MyApp2', | 
|  | 652 | csrf_token => $csrf, | 
|  | 653 | token => 'jhkhkjhk_hjgjsfz67i' | 
|  | 654 | })->status_is(302) | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 655 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 656 | ; | 
|  | 657 |  | 
|  | 658 |  | 
| Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 659 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') | 
| Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 660 | ->element_exists_not('div.notify-error') | 
|  | 661 | ->text_is('div.notify-success', 'Token was revoked successfully') | 
|  | 662 | ; | 
| Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 663 |  | 
| Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 664 | done_testing; | 
|  | 665 | __END__ |