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 | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 100 | |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 101 | $t->get_ok('/realapi/v1.0') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 102 | ->status_is(200) |
| 103 | ->content_is('Fake server available'); |
| 104 | |
| 105 | $t->get_ok('/?q=Baum') |
| 106 | ->status_is(200) |
| 107 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 108 | ->text_like('#total-results', qr/\d+$/) |
| 109 | ->content_like(qr/\"authorized\"\:null/) |
| 110 | ->element_exists_not('div.button.top a') |
| 111 | ->element_exists_not('aside.active') |
| 112 | ->element_exists_not('aside.off') |
| 113 | ; |
| 114 | |
| 115 | $t->get_ok('/') |
| 116 | ->status_is(200) |
| 117 | ->element_exists('form[action=/user/login] input[name=handle_or_email]') |
| 118 | ->element_exists('aside.active') |
| 119 | ->element_exists_not('aside.off') |
| 120 | ; |
| 121 | |
| 122 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' }) |
| 123 | ->status_is(302) |
| 124 | ->header_is('Location' => '/'); |
| 125 | |
| 126 | $t->get_ok('/') |
| 127 | ->status_is(200) |
| 128 | ->element_exists('div.notify-error') |
| 129 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 130 | ->element_exists('input[name=handle_or_email][value=test]') |
| 131 | ->element_exists_not('div.button.top a') |
| 132 | ; |
| 133 | |
| 134 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'pass' }) |
| 135 | ->status_is(302) |
| 136 | ->header_is('Location' => '/'); |
| 137 | |
| 138 | my $csrf = $t->get_ok('/') |
| 139 | ->status_is(200) |
| 140 | ->element_exists('div.notify-error') |
| 141 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 142 | ->element_exists_not('div.button.top a') |
| 143 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 144 | ; |
| 145 | |
| 146 | $t->post_ok('/user/login' => form => { |
| 147 | handle_or_email => 'test', |
| 148 | pwd => 'ldaperr', |
| 149 | csrf_token => $csrf |
| 150 | }) |
| 151 | ->status_is(302) |
| 152 | ->content_is('') |
| 153 | ->header_is('Location' => '/'); |
| 154 | |
| 155 | $csrf = $t->get_ok('/') |
| 156 | ->status_is(200) |
| 157 | ->element_exists('div.notify-error') |
| 158 | ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!') |
| 159 | ->element_exists('input[name=handle_or_email][value=test]') |
| 160 | ->element_exists_not('div.button.top a') |
| 161 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 162 | ; |
| 163 | |
| 164 | $t->post_ok('/user/login' => form => { |
| 165 | handle_or_email => 'test', |
| 166 | pwd => 'unknown', |
| 167 | csrf_token => $csrf |
| 168 | }) |
| 169 | ->status_is(302) |
| 170 | ->content_is('') |
| 171 | ->header_is('Location' => '/'); |
| 172 | |
| 173 | $csrf = $t->get_ok('/') |
| 174 | ->status_is(200) |
| 175 | ->element_exists('div.notify-error') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 176 | ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 177 | ->element_exists('input[name=handle_or_email][value=test]') |
| 178 | ->element_exists_not('div.button.top a') |
| 179 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 180 | ; |
| 181 | |
| 182 | $t->post_ok('/user/login' => form => { |
| 183 | handle_or_email => 'test', |
| 184 | pwd => 'pass', |
| 185 | csrf_token => $csrf |
| 186 | }) |
| 187 | ->status_is(302) |
| 188 | ->content_is('') |
| 189 | ->header_is('Location' => '/'); |
| 190 | |
| 191 | $t->get_ok('/') |
| 192 | ->status_is(200) |
| 193 | ->element_exists_not('div.notify-error') |
| 194 | ->element_exists('div.notify-success') |
| 195 | ->text_is('div.notify-success', 'Login successful') |
| 196 | ->element_exists('aside.off') |
| 197 | ->element_exists_not('aside.active') |
| 198 | ; |
| 199 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 200 | # Now the user is logged in and should be able to |
| 201 | # search with authorization |
| 202 | $t->get_ok('/?q=Baum') |
| 203 | ->status_is(200) |
Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 204 | ->session_has('/auth') |
| 205 | ->session_is('/auth', 'Bearer ' . $access_token) |
| 206 | ->session_is('/auth_r', $refresh_token) |
| 207 | ->session_is('/user', 'test') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 208 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 209 | ->text_like('#total-results', qr/\d+$/) |
| 210 | ->element_exists_not('div.notify-error') |
| 211 | ->content_like(qr/\"authorized\"\:\"yes\"/) |
| 212 | ->element_exists('div.button.top a') |
| 213 | ->element_exists('div.button.top a.logout[title~="test"]') |
| 214 | ; |
| 215 | |
| 216 | # Logout |
| 217 | $t->get_ok('/user/logout') |
| 218 | ->status_is(302) |
Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 219 | ->session_hasnt('/auth') |
| 220 | ->session_hasnt('/auth_r') |
| 221 | ->session_hasnt('/user') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 222 | ->header_is('Location' => '/'); |
| 223 | |
| 224 | $t->get_ok('/') |
| 225 | ->status_is(200) |
| 226 | ->element_exists_not('div.notify-error') |
| 227 | ->element_exists('div.notify-success') |
| 228 | ->text_is('div.notify-success', 'Logout successful') |
Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 229 | ->element_exists("input[name=handle_or_email]") |
| 230 | ->element_exists("input[name=handle_or_email][value=test]") |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 231 | ; |
| 232 | |
| 233 | $t->get_ok('/?q=Baum') |
| 234 | ->status_is(200) |
| 235 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 236 | ->text_like('#total-results', qr/\d+$/) |
| 237 | ->content_like(qr/\"authorized\"\:null/) |
| 238 | ; |
| 239 | |
| 240 | # Get redirect |
| 241 | my $fwd = $t->get_ok('/?q=Baum&ql=poliqarp') |
| 242 | ->status_is(200) |
| 243 | ->element_exists_not('div.notify-error') |
| 244 | ->tx->res->dom->at('input[name=fwd]')->attr('value') |
| 245 | ; |
| 246 | |
| 247 | is($fwd, '/?q=Baum&ql=poliqarp', 'Redirect is valid'); |
| 248 | |
| 249 | $t->post_ok('/user/login' => form => { |
| 250 | handle_or_email => 'test', |
| 251 | pwd => 'pass', |
| 252 | csrf_token => $csrf, |
| 253 | fwd => 'http://bad.example.com/test' |
| 254 | }) |
| 255 | ->status_is(302) |
| 256 | ->header_is('Location' => '/'); |
| 257 | |
| 258 | $t->get_ok('/') |
| 259 | ->status_is(200) |
| 260 | ->element_exists('div.notify-error') |
| 261 | ->element_exists_not('div.notify-success') |
| 262 | ->text_is('div.notify-error', 'Redirect failure') |
| 263 | ; |
| 264 | |
| 265 | $t->post_ok('/user/login' => form => { |
| 266 | handle_or_email => 'test', |
| 267 | pwd => 'pass', |
| 268 | csrf_token => $csrf, |
| 269 | fwd => $fwd |
| 270 | }) |
| 271 | ->status_is(302) |
| 272 | ->header_is('Location' => '/?q=Baum&ql=poliqarp'); |
| 273 | |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 274 | $t->get_ok('/?q=Baum&ql=poliqarp') |
| 275 | ->status_is(200) |
| 276 | ->element_exists_not('div.notify-error') |
| 277 | ->element_exists('div.notify-success') |
| 278 | ->text_is('div.notify-success', 'Login successful') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 279 | ->session_has('/auth') |
| 280 | ->session_is('/auth', 'Bearer ' . $access_token) |
| 281 | ->session_is('/auth_r', $refresh_token) |
| 282 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 283 | ; |
| 284 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 285 | # Expire the session |
| 286 | # (makes the token be marked as expired - though it isn't serverside) |
| 287 | $t->get_ok('/x/expire') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 288 | ->status_is(200) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 289 | ->content_is('okay') |
| 290 | ; |
| 291 | |
| 292 | ## It may be a problem, but the cache is still valid |
| 293 | $t->get_ok('/?q=Baum') |
| 294 | ->status_is(200) |
| 295 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 296 | ->text_like('#total-results', qr/\d+$/) |
| 297 | ->content_like(qr/\"authorized\"\:\"yes\"/) |
| 298 | ->header_is('X-Kalamar-Cache', 'true') |
| 299 | ; |
| 300 | |
| 301 | # Query without partial cache (unfortunately) (but no total results) |
| 302 | $t->get_ok('/?q=baum&cutoff=true') |
| 303 | ->status_is(200) |
| 304 | ->session_is('/auth', 'Bearer ' . $access_token_2) |
| 305 | ->session_is('/auth_r', $refresh_token_2) |
| 306 | ->text_is('#error','') |
| 307 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 308 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 309 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 310 | ->content_like(qr/\"authorized\"\:\"yes\"/) |
| 311 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 312 | ->content_like(qr!\"cutOff":true!) |
| 313 | ->element_exists_not('#total-results') |
| 314 | ; |
| 315 | |
| 316 | # Expire the session and remove the refresh option |
| 317 | $t->get_ok('/x/expire-no-refresh') |
| 318 | ->status_is(200) |
| 319 | ->content_is('okay') |
| 320 | ; |
| 321 | |
| 322 | $t->app->defaults(no_cache => 1); |
| 323 | |
| 324 | |
| 325 | $t->get_ok('/x/invalid-no-refresh') |
| 326 | ->status_is(200) |
| 327 | ->content_is('okay') |
| 328 | ; |
| 329 | |
| 330 | # Query without cache |
| 331 | # The token is invalid and can't be refreshed! |
| 332 | $t->get_ok('/?q=baum&cutoff=true') |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 333 | ->status_is(400) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 334 | ->session_hasnt('/auth') |
| 335 | ->session_hasnt('/auth_r') |
| 336 | ->text_is('#error','') |
| 337 | ->text_is('div.notify-error','Access token invalid') |
| 338 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 339 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 340 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 341 | ->content_unlike(qr/\"authorized\"\:\"yes\"/) |
| 342 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 343 | ->element_exists('p.no-results') |
| 344 | ; |
| 345 | |
| 346 | $t->get_ok('/x/invalid') |
| 347 | ->status_is(200) |
| 348 | ->content_is('okay') |
| 349 | ; |
| 350 | |
| 351 | # Query without cache |
| 352 | # The token is invalid and can't be refreshed! |
| 353 | $t->get_ok('/?q=baum&cutoff=true') |
| 354 | ->status_is(200) |
| 355 | ->session_is('/auth', 'Bearer ' . $access_token_2) |
| 356 | ->session_is('/auth_r', $refresh_token_2) |
| 357 | ->text_is('#error','') |
| 358 | ->element_exists_not('div.notify-error','Access token invalid') |
| 359 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 360 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 361 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
| 362 | ->content_like(qr/\"authorized\"\:\"yes\"/) |
| 363 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 364 | ->element_exists_not('p.no-results') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 365 | ; |
| 366 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 367 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 368 | $t->get_ok('/x/expired-with-wrong-refresh') |
| 369 | ->status_is(200) |
| 370 | ->content_is('okay') |
| 371 | ; |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 372 | |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 373 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 374 | # The token is invalid and can't be refreshed! |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 375 | $csrf = $t->get_ok('/?q=baum&cutoff=true') |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 376 | ->status_is(400) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 377 | ->session_hasnt('/auth') |
| 378 | ->session_hasnt('/auth_r') |
| 379 | ->text_is('#error','') |
| 380 | ->text_is('div.notify-error','Refresh token is expired') |
| 381 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 382 | ->content_unlike(qr/\"authorized\"\:\"yes\"/) |
| 383 | ->element_exists('p.no-results') |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 384 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 385 | ->attr('value') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 386 | ; |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 387 | |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 388 | # Login: |
| 389 | $t->post_ok('/user/login' => form => { |
| 390 | handle_or_email => 'test', |
| 391 | pwd => 'pass', |
| 392 | csrf_token => $csrf |
| 393 | }) |
| 394 | ->status_is(302) |
| 395 | ->content_is('') |
| 396 | ->header_is('Location' => '/'); |
| 397 | |
| 398 | $t->get_ok('/') |
| 399 | ->status_is(200) |
| 400 | ->element_exists_not('div.notify-error') |
| 401 | ->element_exists('div.notify-success') |
| 402 | ->text_is('div.notify-success', 'Login successful') |
| 403 | ->element_exists('aside.off') |
| 404 | ->element_exists_not('aside.active') |
| 405 | ; |
| 406 | |
| 407 | $t->get_ok('/settings/oauth') |
| 408 | ->text_is('form.form-table legend', 'Register new client application') |
| 409 | ->attr_is('form.oauth-register','action', '/settings/oauth/register') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 410 | ->element_exists('ul.client-list') |
| 411 | ->element_exists_not('ul.client-list > li') |
| 412 | # ->text_is('ul.client-list > li > span.client-name', 'R statistical computing tool ') |
| 413 | # ->text_is('ul.client-list > li > span.client-desc', 'R is a free software environment for statistical computing and graphics.') |
| 414 | # ->text_is('ul.client-list > li > span.client-url a', 'https://www.r-project.org/') |
| 415 | # ->text_is('ul.client-list > li a.client-unregister', 'Unregister') |
| 416 | # ->attr_is('ul.client-list > li a.client-unregister', 'href', '/settings/oauth/unregister/9aHsGW6QflV13ixNpez?name=R+statistical+computing+tool') |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 417 | ; |
| 418 | |
| 419 | $csrf = $t->post_ok('/settings/oauth/register' => form => { |
| 420 | name => 'MyApp', |
| 421 | type => 'PUBLIC', |
| 422 | desc => 'This is my application' |
| 423 | }) |
| 424 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 425 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 426 | ->attr('value') |
| 427 | ; |
| 428 | |
| 429 | $t->post_ok('/settings/oauth/register' => form => { |
| 430 | name => 'MyApp', |
| 431 | type => 'CONFIDENTIAL', |
| 432 | desc => 'This is my application', |
| 433 | csrf_token => $csrf |
| 434 | }) |
| 435 | ->status_is(200) |
| 436 | ->element_exists('div.notify-success') |
| 437 | ->text_is('legend', 'Client Credentials') |
| 438 | ->text_is('label[for=client_id]', 'ID of the client application') |
| 439 | ->element_exists('input[name=client_id][readonly][value]') |
| 440 | ->element_exists('input[name=client_secret][readonly][value]') |
| 441 | ; |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 442 | |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 443 | $t->get_ok('/settings/oauth') |
| 444 | ->text_is('form.form-table legend', 'Register new client application') |
| 445 | ->attr_is('form.oauth-register','action', '/settings/oauth/register') |
| 446 | ->text_is('ul.client-list > li > span.client-name', 'MyApp') |
| 447 | ->text_is('ul.client-list > li > span.client-desc', 'This is my application') |
| 448 | ->text_is('ul.client-list > li > span.client-url a', '') |
| 449 | ->text_is('ul.client-list > li a.client-unregister', 'Unregister') |
| 450 | ->attr_is('ul.client-list > li a.client-unregister', 'href', '/settings/oauth/unregister/fCBbQkA2NDA3MzM1Yw==?name=MyApp') |
| 451 | ; |
| 452 | |
| 453 | $csrf = $t->get_ok('/settings/oauth/unregister/fCBbQkA2NDA3MzM1Yw==?name=MyApp') |
| 454 | ->content_like(qr!Do you really want to unregister \<span class="client-name"\>MyApp\<\/span\>?!) |
| 455 | ->attr_is('form.form-table input[name=client-id]', 'value', 'fCBbQkA2NDA3MzM1Yw==') |
| 456 | ->attr_is('form.form-table input[name=client-name]', 'value', 'MyApp') |
| 457 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 458 | ->attr('value') |
| 459 | ; |
| 460 | |
| 461 | $t->post_ok('/settings/oauth/unregister' => form => { |
| 462 | 'client-name' => 'MyApp', |
| 463 | 'client-id' => 'xxxx==', |
| 464 | 'csrf_token' => $csrf |
| 465 | })->status_is(302) |
| 466 | ->content_is('') |
| 467 | ->header_is('Location' => '/settings/oauth') |
| 468 | ; |
| 469 | |
| 470 | $t->get_ok('/settings/oauth') |
| 471 | ->text_is('form.form-table legend', 'Register new client application') |
| 472 | ->attr_is('form.oauth-register','action', '/settings/oauth/register') |
| 473 | ->element_exists('ul.client-list > li') |
| 474 | ->text_is('div.notify', 'Unknown client with xxxx==.') |
| 475 | ; |
| 476 | |
| 477 | $t->post_ok('/settings/oauth/unregister' => form => { |
| 478 | 'client-name' => 'MyApp', |
| 479 | 'client-id' => 'fCBbQkA2NDA3MzM1Yw==', |
| 480 | 'csrf_token' => $csrf |
| 481 | })->status_is(302) |
| 482 | ->content_is('') |
| 483 | ->header_is('Location' => '/settings/oauth') |
| 484 | ; |
| 485 | |
| 486 | $t->get_ok('/settings/oauth') |
| 487 | ->text_is('form.form-table legend', 'Register new client application') |
| 488 | ->attr_is('form.oauth-register','action', '/settings/oauth/register') |
| 489 | ->element_exists_not('ul.client-list > li') |
| 490 | ->text_is('div.notify-success', 'Successfully deleted MyApp') |
| 491 | ; |
| 492 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 493 | done_testing; |
| 494 | __END__ |