Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::More; |
Akron | 6a228db | 2021-10-14 15:57:00 +0200 | [diff] [blame] | 3 | use Mojo::ByteStream 'b'; |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 4 | use Test::Mojo::WithRoles 'Session'; |
Akron | 66ef3b5 | 2022-11-22 14:25:15 +0100 | [diff] [blame] | 5 | use Mojo::File qw/path tempfile/; |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 6 | use Data::Dumper; |
| 7 | |
| 8 | |
| 9 | ##################### |
| 10 | # Start Fake server # |
| 11 | ##################### |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 12 | my $mount_point = '/realapi/'; |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 13 | $ENV{KALAMAR_API} = $mount_point; |
| 14 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 15 | my $t = Test::Mojo::WithRoles->new('Kalamar' => { |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 16 | Kalamar => { |
| 17 | plugins => ['Auth'] |
| 18 | }, |
| 19 | 'Kalamar-Auth' => { |
| 20 | client_id => 2, |
| 21 | client_secret => 'k414m4r-s3cr3t', |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 22 | oauth2 => 1, |
| 23 | experimental_client_registration => 1 |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 24 | } |
| 25 | }); |
| 26 | |
| 27 | # Mount fake backend |
| 28 | # Get the fixture path |
| 29 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, '..', 'server'); |
| 30 | my $fake_backend = $t->app->plugin( |
| 31 | Mount => { |
| 32 | $mount_point => |
| 33 | $fixtures_path->child('mock.pl') |
| 34 | } |
| 35 | ); |
| 36 | # Configure fake backend |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 37 | my $fake_backend_app = $fake_backend->pattern->defaults->{app}; |
| 38 | |
| 39 | # Set general app logger for simplicity |
| 40 | $fake_backend_app->log($t->app->log); |
| 41 | |
| 42 | my $access_token = $fake_backend_app->get_token('access_token'); |
| 43 | my $refresh_token = $fake_backend_app->get_token('refresh_token'); |
| 44 | my $access_token_2 = $fake_backend_app->get_token('access_token_2'); |
| 45 | my $refresh_token_2 = $fake_backend_app->get_token('refresh_token_2'); |
| 46 | |
| 47 | # Some routes to modify the session |
| 48 | # This expires the session |
| 49 | $t->app->routes->get('/x/expire')->to( |
| 50 | cb => sub { |
| 51 | my $c = shift; |
| 52 | $c->session(auth_exp => 0); |
| 53 | return $c->render(text => 'okay') |
| 54 | } |
| 55 | ); |
| 56 | |
| 57 | # This expires the session and removes the refresh token |
| 58 | $t->app->routes->get('/x/expire-no-refresh')->to( |
| 59 | cb => sub { |
| 60 | my $c = shift; |
| 61 | $c->session(auth_exp => 0); |
| 62 | delete $c->session->{auth_r}; |
| 63 | return $c->render(text => 'okay') |
| 64 | } |
| 65 | ); |
| 66 | |
| 67 | # This sets an invalid token |
| 68 | $t->app->routes->get('/x/invalid')->to( |
| 69 | cb => sub { |
| 70 | my $c = shift; |
| 71 | $c->session(auth_exp => time + 1000); |
| 72 | $c->session(auth_r => $refresh_token_2); |
| 73 | $c->session(auth => 'Bearer inv4lid'); |
| 74 | return $c->render(text => 'okay') |
| 75 | } |
| 76 | ); |
| 77 | |
| 78 | |
| 79 | # This sets an invalid token |
| 80 | $t->app->routes->get('/x/invalid-no-refresh')->to( |
| 81 | cb => sub { |
| 82 | my $c = shift; |
| 83 | $c->session(auth_exp => time + 1000); |
| 84 | delete $c->session->{auth_r}; |
| 85 | $c->session(auth => 'Bearer inv4lid'); |
| 86 | return $c->render(text => 'okay') |
| 87 | } |
| 88 | ); |
| 89 | |
| 90 | # This sets an invalid refresh token |
| 91 | $t->app->routes->get('/x/expired-with-wrong-refresh')->to( |
| 92 | cb => sub { |
| 93 | my $c = shift; |
| 94 | $c->session(auth_exp => 0); |
| 95 | $c->session(auth => 'Bearer inv4lid'); |
| 96 | $c->session(auth_r => 'inv4lid'); |
| 97 | return $c->render(text => 'okay') |
| 98 | } |
| 99 | ); |
| 100 | |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 101 | my $q = qr!(?:\"|")!; |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 102 | |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 103 | $t->get_ok('/realapi/v1.0') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 104 | ->status_is(200) |
| 105 | ->content_is('Fake server available'); |
| 106 | |
| 107 | $t->get_ok('/?q=Baum') |
| 108 | ->status_is(200) |
| 109 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 110 | ->text_like('#total-results', qr/\d+$/) |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 111 | ->content_like(qr/${q}authorized${q}:null/) |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 112 | ->element_exists_not('div.button.top a') |
| 113 | ->element_exists_not('aside.active') |
| 114 | ->element_exists_not('aside.off') |
| 115 | ; |
| 116 | |
| 117 | $t->get_ok('/') |
| 118 | ->status_is(200) |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 119 | ->element_exists('form[action=/user/login] input[name=handle_or_email]') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 120 | ->element_exists('aside.active') |
| 121 | ->element_exists_not('aside.off') |
| 122 | ; |
| 123 | |
Akron | ff08811 | 2021-06-15 15:26:04 +0200 | [diff] [blame] | 124 | $t->get_ok('/settings/oauth') |
| 125 | ->status_is(401) |
| 126 | ->text_is('p.no-results', 'Not authenticated') |
| 127 | ; |
| 128 | |
Helge | 278fbca | 2022-11-29 18:49:15 +0100 | [diff] [blame^] | 129 | $t->get_ok('/settings/marketplace') |
| 130 | ->status_is(401) |
| 131 | ->text_is('p.no-results', 'Not authenticated') |
| 132 | ; |
| 133 | |
Akron | 3e0fdc1 | 2020-05-15 16:17:21 +0200 | [diff] [blame] | 134 | # Test for bug with long password |
| 135 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 136 | handle_or_email => 'test', |
Akron | 3e0fdc1 | 2020-05-15 16:17:21 +0200 | [diff] [blame] | 137 | pwd => 'kjskjhndkjndqknaskjnakjdnkjdankajdnkjdsankjdsakjdfkjahzroiuqzriudjoijdmlamdlkmdsalkmdl' }) |
| 138 | ->status_is(302) |
| 139 | ->header_is('Location' => '/'); |
| 140 | |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 141 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' }) |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 142 | ->status_is(302) |
| 143 | ->header_is('Location' => '/'); |
| 144 | |
| 145 | $t->get_ok('/') |
| 146 | ->status_is(200) |
| 147 | ->element_exists('div.notify-error') |
| 148 | ->text_is('div.notify-error', 'Bad CSRF token') |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 149 | ->element_exists('input[name=handle_or_email][value=test]') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 150 | ->element_exists_not('div.button.top a') |
| 151 | ; |
| 152 | |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 153 | $t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'pass' }) |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 154 | ->status_is(302) |
| 155 | ->header_is('Location' => '/'); |
| 156 | |
| 157 | my $csrf = $t->get_ok('/') |
| 158 | ->status_is(200) |
| 159 | ->element_exists('div.notify-error') |
| 160 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 161 | ->element_exists_not('div.button.top a') |
| 162 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 163 | ; |
| 164 | |
| 165 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 166 | handle_or_email => 'test', |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 167 | pwd => 'ldaperr', |
| 168 | csrf_token => $csrf |
| 169 | }) |
| 170 | ->status_is(302) |
| 171 | ->content_is('') |
| 172 | ->header_is('Location' => '/'); |
| 173 | |
| 174 | $csrf = $t->get_ok('/') |
| 175 | ->status_is(200) |
| 176 | ->element_exists('div.notify-error') |
| 177 | ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!') |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 178 | ->element_exists('input[name=handle_or_email][value=test]') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 179 | ->element_exists_not('div.button.top a') |
Akron | 3b3c7af | 2020-05-15 16:23:55 +0200 | [diff] [blame] | 180 | ->element_exists_not('div.notify-success') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 181 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 182 | ; |
| 183 | |
| 184 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 185 | handle_or_email => 'test', |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 186 | pwd => 'unknown', |
| 187 | csrf_token => $csrf |
| 188 | }) |
| 189 | ->status_is(302) |
| 190 | ->content_is('') |
| 191 | ->header_is('Location' => '/'); |
| 192 | |
| 193 | $csrf = $t->get_ok('/') |
| 194 | ->status_is(200) |
| 195 | ->element_exists('div.notify-error') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 196 | ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!') |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 197 | ->element_exists('input[name=handle_or_email][value=test]') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 198 | ->element_exists_not('div.button.top a') |
| 199 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 200 | ; |
| 201 | |
| 202 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 203 | handle_or_email => 'test', |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 204 | pwd => 'pass', |
| 205 | csrf_token => $csrf |
| 206 | }) |
| 207 | ->status_is(302) |
| 208 | ->content_is('') |
| 209 | ->header_is('Location' => '/'); |
| 210 | |
| 211 | $t->get_ok('/') |
| 212 | ->status_is(200) |
| 213 | ->element_exists_not('div.notify-error') |
| 214 | ->element_exists('div.notify-success') |
| 215 | ->text_is('div.notify-success', 'Login successful') |
Akron | 1d09b53 | 2021-06-15 18:18:25 +0200 | [diff] [blame] | 216 | ->element_exists_not('aside.off') |
Akron | dc0b3ab | 2021-06-18 11:52:43 +0200 | [diff] [blame] | 217 | ->element_exists_not('aside.active') |
Akron | 1d09b53 | 2021-06-15 18:18:25 +0200 | [diff] [blame] | 218 | ->element_exists('aside.settings') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 219 | ; |
| 220 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 221 | # Now the user is logged in and should be able to |
| 222 | # search with authorization |
| 223 | $t->get_ok('/?q=Baum') |
| 224 | ->status_is(200) |
Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 225 | ->session_has('/auth') |
| 226 | ->session_is('/auth', 'Bearer ' . $access_token) |
| 227 | ->session_is('/auth_r', $refresh_token) |
| 228 | ->session_is('/user', 'test') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 229 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 230 | ->text_like('#total-results', qr/\d+$/) |
| 231 | ->element_exists_not('div.notify-error') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 232 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 233 | ->element_exists('div.button.top a') |
| 234 | ->element_exists('div.button.top a.logout[title~="test"]') |
| 235 | ; |
| 236 | |
Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 237 | $t->get_ok('/?q=Paum') |
| 238 | ->status_is(200) |
| 239 | ->text_like('h1 span', qr/KorAP: Find .Paum./i) |
| 240 | ->text_is('#total-results', '') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 241 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 242 | ->element_exists_not('p.hint') |
| 243 | ; |
| 244 | |
Akron | cce055c | 2021-07-02 12:18:03 +0200 | [diff] [blame] | 245 | # Query with error |
| 246 | $t->get_ok('/?q=error') |
| 247 | ->status_is(400) |
| 248 | ->text_is('#notifications .notify-error','500: Internal Server Error') |
| 249 | ; |
Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 250 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 251 | # Logout |
| 252 | $t->get_ok('/user/logout') |
| 253 | ->status_is(302) |
Akron | 4cefe1f | 2019-09-04 10:11:28 +0200 | [diff] [blame] | 254 | ->session_hasnt('/auth') |
| 255 | ->session_hasnt('/auth_r') |
| 256 | ->session_hasnt('/user') |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 257 | ->header_is('Location' => '/'); |
| 258 | |
| 259 | $t->get_ok('/') |
| 260 | ->status_is(200) |
| 261 | ->element_exists_not('div.notify-error') |
| 262 | ->element_exists('div.notify-success') |
| 263 | ->text_is('div.notify-success', 'Logout successful') |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 264 | ->element_exists("input[name=handle_or_email]") |
| 265 | ->element_exists("input[name=handle_or_email][value=test]") |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 266 | ; |
| 267 | |
| 268 | $t->get_ok('/?q=Baum') |
| 269 | ->status_is(200) |
| 270 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 271 | ->text_like('#total-results', qr/\d+$/) |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 272 | ->content_like(qr/${q}authorized${q}:null/) |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 273 | ; |
| 274 | |
Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 275 | $t->get_ok('/?q=Paum') |
| 276 | ->status_is(200) |
| 277 | ->text_like('h1 span', qr/KorAP: Find .Paum./i) |
| 278 | ->text_is('#total-results', '') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 279 | ->content_like(qr/${q}authorized${q}:null/) |
Akron | 27031aa | 2020-04-28 14:57:10 +0200 | [diff] [blame] | 280 | ->text_is('p.hint', 'Maybe you need to log in first?') |
| 281 | ; |
| 282 | |
| 283 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 284 | # Get redirect |
| 285 | my $fwd = $t->get_ok('/?q=Baum&ql=poliqarp') |
| 286 | ->status_is(200) |
| 287 | ->element_exists_not('div.notify-error') |
| 288 | ->tx->res->dom->at('input[name=fwd]')->attr('value') |
| 289 | ; |
| 290 | |
| 291 | is($fwd, '/?q=Baum&ql=poliqarp', 'Redirect is valid'); |
| 292 | |
| 293 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 294 | handle_or_email => 'test', |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 295 | pwd => 'pass', |
| 296 | csrf_token => $csrf, |
| 297 | fwd => 'http://bad.example.com/test' |
| 298 | }) |
| 299 | ->status_is(302) |
| 300 | ->header_is('Location' => '/'); |
| 301 | |
| 302 | $t->get_ok('/') |
| 303 | ->status_is(200) |
| 304 | ->element_exists('div.notify-error') |
| 305 | ->element_exists_not('div.notify-success') |
| 306 | ->text_is('div.notify-error', 'Redirect failure') |
| 307 | ; |
| 308 | |
| 309 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 310 | handle_or_email => 'test', |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 311 | pwd => 'pass', |
| 312 | csrf_token => $csrf, |
| 313 | fwd => $fwd |
| 314 | }) |
| 315 | ->status_is(302) |
| 316 | ->header_is('Location' => '/?q=Baum&ql=poliqarp'); |
| 317 | |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 318 | $t->get_ok('/?q=Baum&ql=poliqarp') |
| 319 | ->status_is(200) |
| 320 | ->element_exists_not('div.notify-error') |
| 321 | ->element_exists('div.notify-success') |
| 322 | ->text_is('div.notify-success', 'Login successful') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 323 | ->session_has('/auth') |
| 324 | ->session_is('/auth', 'Bearer ' . $access_token) |
| 325 | ->session_is('/auth_r', $refresh_token) |
| 326 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 327 | ; |
| 328 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 329 | # Expire the session |
| 330 | # (makes the token be marked as expired - though it isn't serverside) |
| 331 | $t->get_ok('/x/expire') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 332 | ->status_is(200) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 333 | ->content_is('okay') |
| 334 | ; |
| 335 | |
| 336 | ## It may be a problem, but the cache is still valid |
| 337 | $t->get_ok('/?q=Baum') |
| 338 | ->status_is(200) |
| 339 | ->text_like('h1 span', qr/KorAP: Find .Baum./i) |
| 340 | ->text_like('#total-results', qr/\d+$/) |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 341 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 342 | ->header_is('X-Kalamar-Cache', 'true') |
| 343 | ; |
| 344 | |
| 345 | # Query without partial cache (unfortunately) (but no total results) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 346 | my $err = $t->get_ok('/?q=baum&cutoff=true') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 347 | ->status_is(200) |
| 348 | ->session_is('/auth', 'Bearer ' . $access_token_2) |
| 349 | ->session_is('/auth_r', $refresh_token_2) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 350 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 351 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 352 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 353 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 354 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 355 | ->content_like(qr!${q}cutOff${q}:true!) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 356 | ->element_exists_not('#total-results') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 357 | ->tx->res->dom->at('#error') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 358 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 359 | is(defined $err ? $err->text : '', ''); |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 360 | |
| 361 | # Expire the session and remove the refresh option |
| 362 | $t->get_ok('/x/expire-no-refresh') |
| 363 | ->status_is(200) |
| 364 | ->content_is('okay') |
| 365 | ; |
| 366 | |
| 367 | $t->app->defaults(no_cache => 1); |
| 368 | |
| 369 | |
| 370 | $t->get_ok('/x/invalid-no-refresh') |
| 371 | ->status_is(200) |
| 372 | ->content_is('okay') |
| 373 | ; |
| 374 | |
| 375 | # Query without cache |
| 376 | # The token is invalid and can't be refreshed! |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 377 | $err = $t->get_ok('/?q=baum&cutoff=true') |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 378 | ->status_is(400) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 379 | ->session_hasnt('/auth') |
| 380 | ->session_hasnt('/auth_r') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 381 | ->text_is('div.notify-error','Access token invalid') |
| 382 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 383 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 384 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 385 | ->content_unlike(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 386 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 387 | ->element_exists('p.no-results') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 388 | ->tx->res->dom->at('#error') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 389 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 390 | is(defined $err ? $err->text : '', ''); |
| 391 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 392 | |
| 393 | $t->get_ok('/x/invalid') |
| 394 | ->status_is(200) |
| 395 | ->content_is('okay') |
| 396 | ; |
| 397 | |
| 398 | # Query without cache |
| 399 | # The token is invalid and can't be refreshed! |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 400 | $err = $t->get_ok('/?q=baum&cutoff=true') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 401 | ->status_is(200) |
| 402 | ->session_is('/auth', 'Bearer ' . $access_token_2) |
| 403 | ->session_is('/auth_r', $refresh_token_2) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 404 | ->element_exists_not('div.notify-error','Access token invalid') |
| 405 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
| 406 | ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]') |
| 407 | ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 408 | ->content_like(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 409 | ->header_isnt('X-Kalamar-Cache', 'true') |
| 410 | ->element_exists_not('p.no-results') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 411 | ->tx->res->dom->at('#error') |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 412 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 413 | is(defined $err ? $err->text : '', ''); |
Akron | 8bbbecf | 2019-07-01 18:57:30 +0200 | [diff] [blame] | 414 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 415 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 416 | $t->get_ok('/x/expired-with-wrong-refresh') |
| 417 | ->status_is(200) |
| 418 | ->content_is('okay') |
| 419 | ; |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 420 | |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 421 | |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 422 | # The token is invalid and can't be refreshed! |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 423 | my $dom = $t->get_ok('/?q=baum&cutoff=true') |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 424 | ->status_is(400) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 425 | ->session_hasnt('/auth') |
| 426 | ->session_hasnt('/auth_r') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 427 | ->text_is('div.notify-error','Refresh token is expired') |
| 428 | ->text_is('title', 'KorAP: Find »baum« with Poliqarp') |
Akron | bc6b3f2 | 2021-01-13 14:53:12 +0100 | [diff] [blame] | 429 | ->content_unlike(qr/${q}authorized${q}:${q}yes${q}/) |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 430 | ->element_exists('p.no-results') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 431 | ->tx->res->dom; |
| 432 | |
| 433 | $csrf = $dom->at('input[name="csrf_token"]') |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 434 | ->attr('value') |
Akron | cdfd9d5 | 2019-07-23 11:35:00 +0200 | [diff] [blame] | 435 | ; |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 436 | |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 437 | $err = $dom->at('#error'); |
| 438 | is(defined $err ? $err->text : '', ''); |
| 439 | |
| 440 | |
Akron | 6a228db | 2021-10-14 15:57:00 +0200 | [diff] [blame] | 441 | # This should fail |
| 442 | my $wide_char_login = "\x{61}\x{E5}\x{61}"; # "\x{443}\x{434}"; |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 443 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 444 | handle_or_email => $wide_char_login, |
Akron | 6a228db | 2021-10-14 15:57:00 +0200 | [diff] [blame] | 445 | pwd => 'pass', |
| 446 | csrf_token => $csrf, |
| 447 | fwd => $fwd |
| 448 | }) |
| 449 | ->status_is(302) |
| 450 | ->header_is('Location' => '/'); |
| 451 | |
| 452 | $t->get_ok('/') |
| 453 | ->status_is(200) |
| 454 | ->element_exists('div.notify-error') |
| 455 | ->text_is('div.notify-error', 'Invalid character in request') |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 456 | ->element_exists('input[name=handle_or_email]:not([value])') |
Akron | 6a228db | 2021-10-14 15:57:00 +0200 | [diff] [blame] | 457 | ->element_exists_not('div.button.top a') |
| 458 | ; |
| 459 | |
| 460 | # Login: |
| 461 | # UTF8 request |
| 462 | my $username = b('täst')->encode; |
| 463 | $t->post_ok('/user/login' => form => { |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 464 | handle_or_email => $username, |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 465 | pwd => 'pass', |
| 466 | csrf_token => $csrf |
| 467 | }) |
| 468 | ->status_is(302) |
| 469 | ->content_is('') |
| 470 | ->header_is('Location' => '/'); |
| 471 | |
| 472 | $t->get_ok('/') |
| 473 | ->status_is(200) |
| 474 | ->element_exists_not('div.notify-error') |
| 475 | ->element_exists('div.notify-success') |
| 476 | ->text_is('div.notify-success', 'Login successful') |
Akron | 6a228db | 2021-10-14 15:57:00 +0200 | [diff] [blame] | 477 | ->attr_is('a.logout', 'title', "Logout: $username") |
Akron | 1d09b53 | 2021-06-15 18:18:25 +0200 | [diff] [blame] | 478 | ->element_exists_not('aside.off') |
Akron | dc0b3ab | 2021-06-18 11:52:43 +0200 | [diff] [blame] | 479 | ->element_exists_not('aside.active') |
Akron | 1d09b53 | 2021-06-15 18:18:25 +0200 | [diff] [blame] | 480 | ->element_exists('aside.settings') |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 481 | ; |
| 482 | |
| 483 | $t->get_ok('/settings/oauth') |
| 484 | ->text_is('form.form-table legend', 'Register new client application') |
| 485 | ->attr_is('form.oauth-register','action', '/settings/oauth/register') |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 486 | ->text_is('label[for=name]','Name of the client application') |
| 487 | ->text_is('label[for=type]','Type of the client application') |
| 488 | ->text_is('label[for=desc]','Short description') |
| 489 | ->text_is('label[for=url]','Homepage') |
| 490 | ->text_is('label[for=redirect_uri]','Redirect URI') |
| 491 | ->text_is('label[for=src]','Declaration of the plugin (*.json file)') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 492 | ->element_exists('ul.client-list') |
| 493 | ->element_exists_not('ul.client-list > li') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 494 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 495 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 496 | ->header_is('Pragma','no-cache') |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 497 | ; |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 498 | |
Helge | 278fbca | 2022-11-29 18:49:15 +0100 | [diff] [blame^] | 499 | |
| 500 | $t->get_ok('/settings/marketplace') |
| 501 | ->status_is(200) |
| 502 | ->text_is('html head title' => 'Marketplace') |
| 503 | ; |
| 504 | |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 505 | $csrf = $t->post_ok('/settings/oauth/register' => form => { |
| 506 | name => 'MyApp', |
| 507 | type => 'PUBLIC', |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 508 | desc => 'This is my plugin application' |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 509 | }) |
| 510 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 511 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 512 | ->attr('value') |
| 513 | ; |
| 514 | |
| 515 | $t->post_ok('/settings/oauth/register' => form => { |
| 516 | name => 'MyApp', |
Akron | 99968a9 | 2022-06-03 12:32:07 +0200 | [diff] [blame] | 517 | type => 'PUBLIC', |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 518 | desc => 'This is my plugin application', |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 519 | csrf_token => $csrf, |
| 520 | src => { |
| 521 | filename => '', |
| 522 | content => '' |
| 523 | } |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 524 | }) |
| 525 | ->status_is(200) |
| 526 | ->element_exists('div.notify-success') |
| 527 | ->text_is('legend', 'Client Credentials') |
| 528 | ->text_is('label[for=client_id]', 'ID of the client application') |
| 529 | ->element_exists('input[name=client_id][readonly][value]') |
Akron | 99968a9 | 2022-06-03 12:32:07 +0200 | [diff] [blame] | 530 | ->element_exists_not('input[name=client_secret][readonly][value]') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 531 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 532 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 533 | ->header_is('Pragma','no-cache') |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 534 | ; |
Akron | 4796e00 | 2019-07-05 10:13:15 +0200 | [diff] [blame] | 535 | |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 536 | my $anchor = $t->get_ok('/settings/oauth') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 537 | ->text_is('.form-table legend', 'Register new client application') |
| 538 | ->attr_is('.oauth-register','action', '/settings/oauth/register') |
Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 539 | ->text_is('ul.client-list > li > span.client-name a', 'MyApp') |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 540 | ->text_is('ul.client-list > li > p.client-desc', 'This is my plugin application') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 541 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 542 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 543 | ->header_is('Pragma','no-cache') |
Akron | b6b156e | 2022-03-31 14:57:49 +0200 | [diff] [blame] | 544 | ->tx->res->dom->at('ul.client-list > li > p.client-url a') |
Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 545 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 546 | is(defined $anchor ? $anchor->text : '', ''); |
Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 547 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 548 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 549 | ->status_is(200) |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 550 | ->text_is('ul.client-list > li.client > span.client-name', 'MyApp') |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 551 | ->text_is('ul.client-list > li.client > p.client-desc', 'This is my plugin application') |
Akron | 17de86e | 2020-04-16 16:03:40 +0200 | [diff] [blame] | 552 | ->text_is('a.client-unregister', 'Unregister') |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 553 | ->attr_is('a.client-unregister', 'href', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/unregister?name=MyApp') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 554 | ; |
| 555 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 556 | $csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/unregister?name=MyApp') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 557 | ->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] | 558 | ->attr_is('.form-table input[name=client-name]', 'value', 'MyApp') |
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 | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 562 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 563 | ->attr('value') |
| 564 | ; |
| 565 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 566 | $t->post_ok('/settings/oauth/xxxx==/unregister' => form => { |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 567 | 'client-name' => 'MyApp', |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 568 | 'csrf_token' => $csrf |
| 569 | })->status_is(302) |
| 570 | ->content_is('') |
| 571 | ->header_is('Location' => '/settings/oauth') |
| 572 | ; |
| 573 | |
| 574 | $t->get_ok('/settings/oauth') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 575 | ->text_is('.form-table legend', 'Register new client application') |
| 576 | ->attr_is('.oauth-register','action', '/settings/oauth/register') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 577 | ->element_exists('ul.client-list > li') |
| 578 | ->text_is('div.notify', 'Unknown client with xxxx==.') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 579 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 580 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 581 | ->header_is('Pragma','no-cache') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 582 | ; |
| 583 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 584 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/unregister' => form => { |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 585 | 'client-name' => 'MyApp', |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 586 | 'csrf_token' => $csrf |
| 587 | })->status_is(302) |
| 588 | ->content_is('') |
| 589 | ->header_is('Location' => '/settings/oauth') |
| 590 | ; |
| 591 | |
| 592 | $t->get_ok('/settings/oauth') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 593 | ->text_is('.form-table legend', 'Register new client application') |
| 594 | ->attr_is('.oauth-register','action', '/settings/oauth/register') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 595 | ->element_exists_not('ul.client-list > li') |
| 596 | ->text_is('div.notify-success', 'Successfully deleted MyApp') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 597 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 598 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 599 | ->header_is('Pragma','no-cache') |
Akron | 1a9d5be | 2020-03-19 17:28:33 +0100 | [diff] [blame] | 600 | ; |
| 601 | |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 602 | $t->post_ok('/settings/oauth/register' => form => { |
| 603 | name => 'MyApp2', |
| 604 | type => 'PUBLIC', |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 605 | desc => 'This is my plugin application', |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 606 | csrf_token => $csrf |
| 607 | })->status_is(200) |
| 608 | ->element_exists('div.notify-success') |
| 609 | ->text_is('legend', 'Client Credentials') |
| 610 | ->text_is('label[for=client_id]', 'ID of the client application') |
| 611 | ->element_exists('input[name=client_id][readonly][value]') |
| 612 | ->element_exists_not('input[name=client_secret][readonly][value]') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 613 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 614 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 615 | ->header_is('Pragma','no-cache') |
Akron | b6b156e | 2022-03-31 14:57:49 +0200 | [diff] [blame] | 616 | ->element_exists('.client-issue-token') |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 617 | ; |
| 618 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 619 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 620 | ->text_is('.client-name', 'MyApp2') |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 621 | ->text_is('.client-desc', 'This is my plugin application') |
Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 622 | ->text_is('.client-issue-token', 'Issue new token') |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 623 | ->attr_is('.client-issue-token', 'href', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?name=MyApp2') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 624 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 625 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 626 | ->header_is('Pragma','no-cache') |
Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 627 | ->text_is('ul.token-list label[for=token]', 'Access Token') |
| 628 | ->text_is('p[name=created]', 'Created at ') |
| 629 | ->text_is('p[name=expires]', 'Expires in 31533851 seconds.') |
Akron | b6b156e | 2022-03-31 14:57:49 +0200 | [diff] [blame] | 630 | ->element_exists('.client-issue-token') |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 631 | ; |
| 632 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 633 | $csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?name=MyApp2') |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 634 | ->status_is(200) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 635 | ->attr_is('#issue-token','action', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token') |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 636 | ->attr_is('input[name=client-id]', 'value', 'fCBbQkA2NDA3MzM1Yw==') |
| 637 | ->attr_is('input[name=name]', 'value', 'MyApp2') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 638 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 639 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 640 | ->header_is('Pragma','no-cache') |
Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 641 | ->text_is('a.button-abort', 'Abort') |
| 642 | ->attr_is('#issue-token input[type=submit]', 'value', 'Issue new token') |
| 643 | ->content_like(qr!Issue a new token for!) |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 644 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 645 | ->attr('value') |
| 646 | ; |
| 647 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 648 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token' => form => { |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 649 | csrf_token => $csrf, |
| 650 | name => 'MyApp2', |
| 651 | 'client-id' => 'fCBbQkA2NDA3MzM1Yw==' |
| 652 | }) |
Akron | bc94a9c | 2021-04-15 00:07:35 +0200 | [diff] [blame] | 653 | ->status_is(302) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 654 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | bc94a9c | 2021-04-15 00:07:35 +0200 | [diff] [blame] | 655 | ; |
| 656 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 657 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
| 658 | ->status_is(200) |
Akron | bc94a9c | 2021-04-15 00:07:35 +0200 | [diff] [blame] | 659 | ->text_is('div.notify-success', 'New access token created') |
Akron | ad011bb | 2021-06-10 12:16:36 +0200 | [diff] [blame] | 660 | ->status_is(200) |
| 661 | ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate') |
| 662 | ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT') |
| 663 | ->header_is('Pragma','no-cache') |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 664 | ; |
| 665 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 666 | $csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 667 | ->status_is(200) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 668 | ->attr_is('form.token-revoke', 'action', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token/revoke') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 669 | ->attr_is('form.token-revoke input[name=token]', 'value', 'jhkhkjhk_hjgjsfz67i') |
| 670 | ->attr_is('form.token-revoke input[name=name]', 'value', 'MyApp2') |
| 671 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 672 | ->attr('value') |
| 673 | ; |
| 674 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 675 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token/revoke' => form => { |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 676 | csrf_token => $csrf, |
| 677 | name => 'MyApp2', |
| 678 | token => 'jhkhkjhk_hjgjsfz67i' |
| 679 | }) |
| 680 | ->status_is(200) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 681 | ->attr_is('form#revoke-token','action','/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 682 | ->attr_is('form#revoke-token','method','POST') |
| 683 | ->attr_is('form#revoke-token input[name=token]','value','jhkhkjhk_hjgjsfz67i') |
Akron | e997bb5 | 2021-06-11 16:44:06 +0200 | [diff] [blame] | 684 | ->text_is('a.button-abort', 'Abort') |
| 685 | ->attr_is('#revoke-token input[type=submit]', 'value', 'Revoke') |
| 686 | ->content_like(qr!Revoke a token for!) |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 687 | ; |
| 688 | |
| 689 | |
| 690 | # CSRF missing |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 691 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE' => form => { |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 692 | name => 'MyApp2', |
| 693 | token => 'jhkhkjhk_hjgjsfz67i' |
| 694 | })->status_is(302) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 695 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 696 | ; |
| 697 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 698 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 699 | ->element_exists_not('div.notify-success') |
| 700 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 701 | ; |
| 702 | |
| 703 | # Token missing |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 704 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE' => form => { |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 705 | name => 'MyApp2', |
| 706 | csrf_token => $csrf, |
| 707 | })->status_is(302) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 708 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 709 | ; |
| 710 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 711 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 712 | ->element_exists_not('div.notify-success') |
| 713 | ->text_is('div.notify-error', 'Some fields are invalid') |
| 714 | ; |
| 715 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 716 | $t->post_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE' => form => { |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 717 | name => 'MyApp2', |
| 718 | csrf_token => $csrf, |
| 719 | token => 'jhkhkjhk_hjgjsfz67i' |
| 720 | })->status_is(302) |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 721 | ->header_is('Location','/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 722 | ; |
| 723 | |
Akron | 041ca4d | 2021-06-10 11:52:51 +0200 | [diff] [blame] | 724 | $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==') |
Akron | c1aaf93 | 2021-06-09 12:19:15 +0200 | [diff] [blame] | 725 | ->element_exists_not('div.notify-error') |
| 726 | ->text_is('div.notify-success', 'Token was revoked successfully') |
| 727 | ; |
Akron | 83209f7 | 2021-01-29 17:54:15 +0100 | [diff] [blame] | 728 | |
Akron | b6b156e | 2022-03-31 14:57:49 +0200 | [diff] [blame] | 729 | $t->app->routes->get('/x/redirect-target')->to( |
| 730 | cb => sub { |
| 731 | my $c = shift; |
| 732 | return $c->render(text => 'redirected'); |
| 733 | } |
| 734 | ); |
| 735 | |
| 736 | $csrf = $t->post_ok('/settings/oauth/register' => form => { |
| 737 | name => 'MyConfApp', |
| 738 | type => 'CONFIDENTIAL', |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 739 | desc => 'This is my plugin application', |
Akron | b6b156e | 2022-03-31 14:57:49 +0200 | [diff] [blame] | 740 | }) |
| 741 | ->text_is('div.notify-error', 'Bad CSRF token') |
| 742 | ->tx->res->dom->at('input[name="csrf_token"]') |
| 743 | ->attr('value') |
| 744 | ; |
| 745 | |
| 746 | $t->post_ok('/settings/oauth/register' => form => { |
| 747 | name => 'MyConfApp', |
| 748 | type => 'CONFIDENTIAL', |
| 749 | desc => 'This is my confidential application', |
| 750 | csrf_token => $csrf, |
| 751 | redirect_uri => 'http://localhost/redirect-target' |
| 752 | }) |
| 753 | ->text_is('div.notify-error', undef) |
| 754 | ->text_is('li.client span.client-name', 'MyConfApp') |
| 755 | ->text_is('li.client p.client-desc', 'This is my confidential application') |
| 756 | ->text_is('li.client .client-redirect-uri tt', 'http://localhost/redirect-target') |
| 757 | ->text_is('li.client .client-type tt', 'CONFIDENTIAL') |
| 758 | ->element_exists_not('.client-issue-token') |
| 759 | ; |
| 760 | |
| 761 | $t->post_ok('/settings/oauth/register' => form => { |
| 762 | name => 'MyConfApp2', |
| 763 | type => 'CONFIDENTIAL', |
| 764 | desc => 'This is my second confidential application', |
| 765 | csrf_token => $csrf, |
| 766 | redirect_uri => 'http://localhost/FAIL' |
| 767 | }) |
| 768 | ->status_is(302) |
| 769 | ->header_is('location','/settings/oauth/') |
| 770 | ; |
| 771 | |
| 772 | $t->get_ok('/settings/oauth/') |
| 773 | ->text_is('div.notify-error', 'invalid_request: http://localhost/FAIL is invalid.') |
| 774 | ; |
| 775 | |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 776 | # OAuth client authorization flow |
| 777 | $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')) |
| 778 | ->status_is(302) |
Akron | 5ea0f5d | 2023-01-20 11:51:43 +0100 | [diff] [blame] | 779 | ->header_is('location','/settings/oauth') |
| 780 | ; |
| 781 | |
| 782 | $t->get_ok('/settings/oauth/') |
Akron | 2c142ab | 2023-01-30 13:21:57 +0100 | [diff] [blame] | 783 | ->text_is('div.notify-error', 'Client ID required') |
| 784 | ; |
| 785 | |
| 786 | $t->get_ok(Mojo::URL->new('/settings/oauth/authorize?client_id=xyz')) |
| 787 | ->status_is(302) |
| 788 | ->header_is('location','/settings/oauth') |
| 789 | ; |
| 790 | |
| 791 | $t->get_ok('/settings/oauth/') |
| 792 | ->text_is('div.notify-error', 'Scope required') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 793 | ; |
| 794 | |
Akron | db1f467 | 2023-01-24 12:05:07 +0100 | [diff] [blame] | 795 | # OAuth client authorization flow |
| 796 | $t->get_ok(Mojo::URL->new('/settings/oauth/authorize?client_id=abc')) |
| 797 | ->status_is(302) |
| 798 | ->header_is('location','/settings/oauth') |
| 799 | ; |
| 800 | |
| 801 | $t->get_ok('/settings/oauth/') |
Akron | 2c142ab | 2023-01-30 13:21:57 +0100 | [diff] [blame] | 802 | ->text_is('div.notify-error', 'Scope required') |
| 803 | ; |
| 804 | |
| 805 | # OAuth client authorization flow |
| 806 | $t->get_ok(Mojo::URL->new('/settings/oauth/authorize?client_id=abc&scope=match')) |
| 807 | ->status_is(302) |
| 808 | ->header_is('location','/settings/oauth') |
| 809 | ; |
| 810 | |
| 811 | $t->get_ok('/settings/oauth/') |
Akron | db1f467 | 2023-01-24 12:05:07 +0100 | [diff] [blame] | 812 | ->text_is('div.notify-error', 'Unknown client with abc.') |
| 813 | ; |
| 814 | |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 815 | # Logout |
| 816 | $t->get_ok('/x/expired-with-wrong-refresh'); |
| 817 | |
| 818 | $t->get_ok('/user/logout') |
| 819 | ->status_is(302) |
| 820 | ->session_hasnt('/auth') |
| 821 | ->session_hasnt('/auth_r') |
| 822 | ->session_hasnt('/user') |
| 823 | ->header_is('Location' => '/'); |
| 824 | |
Akron | 001dcd2 | 2023-02-07 08:38:11 +0100 | [diff] [blame] | 825 | $t->get_ok('/') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 826 | ->status_is(200) |
| 827 | ->element_exists_not('div.notify-error') |
| 828 | ->element_exists('div.notify-success') |
| 829 | ->text_is('div.notify-success', 'Logout successful') |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 830 | ->element_exists("input[name=handle_or_email]") |
Akron | 001dcd2 | 2023-02-07 08:38:11 +0100 | [diff] [blame] | 831 | ; |
| 832 | |
| 833 | # OAuth client authorization flow - but user not logged in |
| 834 | $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')) |
| 835 | ->status_is(302) |
| 836 | ->header_is('location','/') |
| 837 | ; |
| 838 | |
| 839 | $csrf = $t->get_ok('/') |
| 840 | ->status_is(200) |
| 841 | ->element_exists('div.notify-error') |
| 842 | ->element_exists_not('div.notify-success') |
| 843 | ->text_is('div.notify-error', 'Client ID required') |
| 844 | ->element_exists("input[name=handle_or_email]") |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 845 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 846 | ; |
| 847 | |
Akron | 408bc7c | 2022-04-28 15:46:43 +0200 | [diff] [blame] | 848 | $fake_backend_app->add_client({ |
| 849 | "client_id" => 'xyz', |
| 850 | "client_name" => 'New added client', |
| 851 | "client_description" => 'This is a new client', |
| 852 | "client_url" => 'http://example.com', |
| 853 | "client_type" => 'CONFIDENTIAL' |
| 854 | # "client_redirect_uri" => $redirect_uri |
| 855 | }); |
| 856 | |
Helge | 278fbca | 2022-11-29 18:49:15 +0100 | [diff] [blame^] | 857 | |
Akron | 9d82690 | 2023-01-25 10:20:52 +0100 | [diff] [blame] | 858 | $fake_backend_app->add_client({ |
| 859 | "client_id" => 'xyz2', |
| 860 | "client_name" => 'New added client', |
| 861 | "client_description" => 'This is a new client', |
| 862 | "client_url" => 'http://example.com', |
| 863 | "client_type" => 'CONFIDENTIAL', |
| 864 | "client_redirect_uri" => 'http://redirect.url/' |
| 865 | }); |
| 866 | |
| 867 | $fwd = $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 868 | client_id => 'xyz2', |
| 869 | scope => 'search match', |
| 870 | redirect_uri => 'http://test.com/', |
| 871 | })) |
| 872 | ->status_is(200) |
| 873 | ->text_is('div.notify-warn', 'redirect_uri host differs from registered host') |
| 874 | ->element_exists_not('div.notify-error') |
| 875 | ->element_exists_not('div.notify-success') |
| 876 | ->element_exists("input[name=handle_or_email]") |
| 877 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 878 | ; |
| 879 | |
| 880 | $fwd = $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 881 | client_id => 'xyz2', |
| 882 | scope => 'search match', |
| 883 | redirect_uri => 'http://redirect.url:9000/', |
| 884 | })) |
| 885 | ->status_is(200) |
| 886 | ->text_is('div.notify-warn', 'redirect_uri port differs from registered port') |
| 887 | ->element_exists_not('div.notify-error') |
| 888 | ->element_exists_not('div.notify-success') |
| 889 | ->element_exists("input[name=handle_or_email]") |
| 890 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 891 | ; |
| 892 | |
Helge | 278fbca | 2022-11-29 18:49:15 +0100 | [diff] [blame^] | 893 | |
| 894 | $fake_backend_app->add_plugin({ |
| 895 | "source" => {"key1" => 'wert1', "key2" => 'wert2'}, |
| 896 | "client_id" => "52abc", |
| 897 | "permitted" => 'true', |
| 898 | "client_id" => '52abc', |
| 899 | "client_name" => 'Plugin 1', |
| 900 | "client_type" => 'CONFIDENTIAL', |
| 901 | "client_description" =>"Description Plugin 1", |
| 902 | "client_url" => "http://example.client.de", |
| 903 | "registration_date" => "2022-05-31T14:30:09+02:00[Europe/Berlin]", |
| 904 | "registered_by" => "system" |
| 905 | }); |
| 906 | |
| 907 | |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 908 | $fwd = $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 909 | client_id => 'xyz', |
| 910 | state => 'abcde', |
| 911 | scope => 'search match', |
| 912 | redirect_uri => 'http://test.com/', |
| 913 | })) |
| 914 | ->status_is(200) |
| 915 | ->attr_is('input[name=client_id]','value','xyz') |
| 916 | ->attr_is('input[name=state]','value','abcde') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 917 | ->attr_like('input[name=fwd]','value',qr!test\.com!) |
Akron | 408bc7c | 2022-04-28 15:46:43 +0200 | [diff] [blame] | 918 | ->text_is('span.client-name','New added client') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 919 | ->text_is('div.intro p:nth-child(2)', 'Please log in!') |
| 920 | ->tx->res->dom->at('input[name=fwd]')->attr('value') |
| 921 | ; |
| 922 | |
| 923 | $fwd = $t->post_ok(Mojo::URL->new('/user/login')->query({ |
| 924 | csrf_token => $csrf, |
| 925 | client_id => 'xyz', |
| 926 | state => 'abcde', |
| 927 | scope => 'search match', |
| 928 | redirect_uri => 'http://test.com/', |
Akron | 9fa7cc5 | 2022-05-12 11:17:20 +0200 | [diff] [blame] | 929 | handle_or_email => 'test', |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 930 | pwd => 'pass', |
| 931 | fwd => $fwd |
| 932 | })) |
| 933 | ->status_is(302) |
| 934 | ->header_like('location', qr!/settings/oauth/authorize!) |
| 935 | ->tx->res->headers->header('location') |
| 936 | ; |
| 937 | |
| 938 | $t->get_ok($fwd) |
| 939 | ->status_is(200) |
| 940 | ->attr_is('input[name=client_id]','value','xyz') |
| 941 | ->attr_is('input[name=state]','value','abcde') |
Akron | 9d82690 | 2023-01-25 10:20:52 +0100 | [diff] [blame] | 942 | ->attr_like('input[name=redirect_uri]','value', qr!^http://test\.com\/\?crto=.{3,}!) |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 943 | ->text_is('ul#scopes li:nth-child(1)','search') |
| 944 | ->text_is('ul#scopes li:nth-child(2)','match') |
Akron | 408bc7c | 2022-04-28 15:46:43 +0200 | [diff] [blame] | 945 | ->text_is('span.client-name','New added client') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 946 | ->attr_is('a.form-button','href','http://test.com/') |
| 947 | ->attr_is('a.embedded-link', 'href', '/doc/korap/kalamar') |
Akron | 9d82690 | 2023-01-25 10:20:52 +0100 | [diff] [blame] | 948 | ->element_exists_not('div.notify-error') |
| 949 | ->element_exists_not('div.notify-warn') |
| 950 | ->element_exists_not('blockquote.warning') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 951 | ; |
| 952 | |
Helge | 278fbca | 2022-11-29 18:49:15 +0100 | [diff] [blame^] | 953 | $t->get_ok('/settings/marketplace') |
| 954 | ->status_is(200) |
| 955 | ->text_is('html head title' => 'Marketplace') |
| 956 | ->element_exists('ul.plugin-list') |
| 957 | ->element_exists('ul.plugin-list > li') |
| 958 | ->element_exists('p.registration_date') |
| 959 | ->element_exists('p.registered_by') |
| 960 | ->text_is('span.client-name','Plugin 1') |
| 961 | ->text_is('p.plugin-desc','Description Plugin 1') |
| 962 | ; |
| 963 | |
| 964 | $fake_backend_app->add_plugin({ |
| 965 | "source" => {"one" => '1', "two" => '2'}, |
| 966 | "permitted" => 'false', |
| 967 | "client_id" => '53abc', |
| 968 | "client_name" => 'Plugin 2', |
| 969 | "client_type" => 'CONFIDENTIAL', |
| 970 | "client_description" =>'Description Plugin 2' |
| 971 | }); |
| 972 | |
| 973 | $fake_backend_app->add_plugin({ |
| 974 | "source" => {"answer" => '42', "hello" => 'world'}, |
| 975 | "permitted" => 'true', |
| 976 | "client_id" => '54abc', |
| 977 | "client_name" => 'Plugin 3', |
| 978 | "client_type" => 'CONFIDENTIAL', |
| 979 | "client_description" =>'Description Plugin 3' |
| 980 | }); |
| 981 | |
| 982 | $t->get_ok('/settings/marketplace') |
| 983 | ->status_is(200) |
| 984 | ->element_exists('ul.plugin-list') |
| 985 | ->element_exists('ul.plugin-list > li') |
| 986 | ->text_is('span.client-name','Plugin 1') |
| 987 | ->text_is('p.plugin-desc','Description Plugin 1') |
| 988 | ->element_exists('ul.plugin-list > li + li') |
| 989 | ->text_isnt('ul.plugin-list > li + li >span.client-name','Plugin 2') |
| 990 | ->text_isnt('ul.plugin-list > li + li >p.plugin-desc','Description Plugin 2') |
| 991 | ->text_is('ul.plugin-list > li + li >span.client-name','Plugin 3') |
| 992 | ->text_is('ul.plugin-list > li + li >p.plugin-desc','Description Plugin 3') |
| 993 | ; |
| 994 | |
| 995 | |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 996 | $t->get_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 997 | client_id => 'xyz', |
| 998 | state => 'abcde', |
| 999 | scope => 'search match', |
| 1000 | redirect_uri => 'http://test.com/' |
| 1001 | })) |
| 1002 | ->status_is(200) |
| 1003 | ->attr_is('input[name=client_id]','value','xyz') |
| 1004 | ->attr_is('input[name=state]','value','abcde') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1005 | ->text_is('ul#scopes li:nth-child(1)','search') |
| 1006 | ->text_is('ul#scopes li:nth-child(2)','match') |
Akron | 408bc7c | 2022-04-28 15:46:43 +0200 | [diff] [blame] | 1007 | ->text_is('span.client-name','New added client') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1008 | ->attr_is('a.form-button','href','http://test.com/') |
| 1009 | ->attr_is('a.embedded-link', 'href', '/doc/korap/kalamar') |
| 1010 | ; |
| 1011 | |
| 1012 | $t->post_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 1013 | client_id => 'xyz', |
| 1014 | state => 'abcde', |
| 1015 | scope => 'search match', |
| 1016 | redirect_uri => 'http://test.com/' |
| 1017 | })) |
| 1018 | ->status_is(302) |
Akron | 9d82690 | 2023-01-25 10:20:52 +0100 | [diff] [blame] | 1019 | ->header_is('location', '/settings/oauth?error_description=Bad+CSRF+token') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1020 | ; |
| 1021 | |
| 1022 | $fwd = $t->post_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 1023 | client_id => 'xyz', |
| 1024 | state => 'abcde', |
| 1025 | scope => 'search match', |
| 1026 | redirect_uri_server => 'http://example.com/', |
| 1027 | redirect_uri => $fake_backend_app->url_for('return_uri')->to_abs, |
| 1028 | csrf_token => $csrf, |
| 1029 | })) |
| 1030 | ->status_is(302) |
| 1031 | ->header_like('location', qr!/realapi/fakeclient/return!) |
| 1032 | ->tx->res->headers->header('location') |
| 1033 | ; |
| 1034 | |
| 1035 | $t->get_ok($fwd) |
| 1036 | ->status_is(200) |
| 1037 | ->content_like(qr'welcome back! \[(.+?)\]') |
| 1038 | ; |
| 1039 | |
| 1040 | $t->post_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 1041 | client_id => 'xyz', |
Akron | 9ccf69a | 2023-01-31 14:21:37 +0100 | [diff] [blame] | 1042 | state => 'abcde', |
| 1043 | scope => 'search match', |
| 1044 | redirect_uri_server => 'http://example.com/', |
| 1045 | redirect_uri => $t->app->close_redirect_to('http://wrong'), |
| 1046 | csrf_token => $csrf, |
| 1047 | })) |
| 1048 | ->status_is(302) |
| 1049 | ->header_is('location', '/settings/oauth') |
| 1050 | ->tx->res->headers->header('location') |
| 1051 | ; |
| 1052 | |
| 1053 | $t->get_ok('/settings/oauth') |
| 1054 | ->text_is('div.notify-error', 'Invalid redirect URI') |
| 1055 | ; |
| 1056 | |
| 1057 | $t->post_ok(Mojo::URL->new('/settings/oauth/authorize')->query({ |
| 1058 | client_id => 'xyz', |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1059 | state => 'fail', |
| 1060 | scope => 'search match', |
Akron | 9d82690 | 2023-01-25 10:20:52 +0100 | [diff] [blame] | 1061 | # redirect_uri_server => 'http://example.com/', |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1062 | redirect_uri => $fake_backend_app->url_for('return_uri')->to_abs, |
| 1063 | csrf_token => $csrf, |
| 1064 | })) |
| 1065 | ->status_is(302) |
Akron | 9d82690 | 2023-01-25 10:20:52 +0100 | [diff] [blame] | 1066 | ->header_is('location', '/realapi/fakeclient/return?error_description=FAIL') |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1067 | ; |
| 1068 | |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 1069 | my $json_post = { |
| 1070 | name => 'Funny', |
| 1071 | type => 'PUBLIC', |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 1072 | desc => 'This is my plugin application 2', |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 1073 | csrf_token => $csrf, |
| 1074 | src => 'hMMM' |
| 1075 | }; |
| 1076 | |
| 1077 | $t->post_ok('/settings/oauth/register' => form => $json_post) |
| 1078 | ->status_is(200) |
| 1079 | ->element_exists('div.notify-error') |
Akron | 99968a9 | 2022-06-03 12:32:07 +0200 | [diff] [blame] | 1080 | ->text_is('div.notify-error', 'Plugin declarations need to be json files') |
| 1081 | ; |
| 1082 | |
| 1083 | $json_post->{src} = { |
| 1084 | content => 'jjjjjj', |
| 1085 | filename => 'fun.txt' |
| 1086 | }; |
| 1087 | |
| 1088 | $t->post_ok('/settings/oauth/register' => form => $json_post) |
| 1089 | ->status_is(200) |
| 1090 | ->element_exists('div.notify-error') |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 1091 | ->text_is('div.notify-error', 'Plugins need to be confidential') |
| 1092 | ; |
| 1093 | |
| 1094 | $json_post->{type} = 'CONFIDENTIAL'; |
| 1095 | |
Akron | 99968a9 | 2022-06-03 12:32:07 +0200 | [diff] [blame] | 1096 | # This somehow gets removed in the last form send ... |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 1097 | $json_post->{src} = { |
| 1098 | content => 'jjjjjj', |
| 1099 | filename => 'fun.txt' |
| 1100 | }; |
| 1101 | |
| 1102 | $t->post_ok('/settings/oauth/register' => form => $json_post) |
| 1103 | ->status_is(200) |
| 1104 | ->element_exists('div.notify-error') |
| 1105 | ->text_is('div.notify-error', 'Plugin declarations need to be json files') |
| 1106 | ; |
| 1107 | |
| 1108 | $json_post->{src} = { |
| 1109 | content => '{"name":"example"}', |
| 1110 | filename => 'fun.txt' |
| 1111 | }; |
| 1112 | |
| 1113 | $t->post_ok('/settings/oauth/register' => form => $json_post) |
| 1114 | ->status_is(200) |
| 1115 | ->element_exists_not('div.notify-error') |
| 1116 | ->element_exists('div.notify-success') |
| 1117 | ->text_is('div.notify-success', 'Registration successful') |
| 1118 | ; |
| 1119 | |
Akron | 6b75d12 | 2022-05-12 17:39:05 +0200 | [diff] [blame] | 1120 | $t->get_ok('/settings/oauth/jh0gfjhjbfdsgzjghj==') |
| 1121 | ->status_is(200) |
| 1122 | ->text_is('div.notify-error', undef) |
| 1123 | ->text_is('li.client #client_source', '{"name":"example"}') |
| 1124 | ->text_is('li.client span.client-name', 'Funny') |
| 1125 | ->text_is('li.client p.client-desc', 'This is my plugin application 2') |
| 1126 | ->element_exists_not('li.client .client-redirect-uri tt') |
| 1127 | ->text_is('li.client .client-type tt', 'CONFIDENTIAL') |
| 1128 | ; |
Akron | 9f2ad34 | 2022-05-04 16:16:40 +0200 | [diff] [blame] | 1129 | |
Akron | b6b156e | 2022-03-31 14:57:49 +0200 | [diff] [blame] | 1130 | |
Akron | 66ef3b5 | 2022-11-22 14:25:15 +0100 | [diff] [blame] | 1131 | # Retest client with super_client_file |
| 1132 | my $client_file = tempfile; |
| 1133 | |
| 1134 | $client_file->spurt( |
| 1135 | '{"client_id":"2","client_secret":"k414m4r-s3cr3t"}' |
| 1136 | ); |
| 1137 | |
| 1138 | $t = Test::Mojo::WithRoles->new('Kalamar' => { |
| 1139 | Kalamar => { |
| 1140 | plugins => ['Auth'] |
| 1141 | }, |
| 1142 | 'Kalamar-Auth' => { |
| 1143 | client_file => $client_file, |
| 1144 | oauth2 => 1 |
| 1145 | } |
| 1146 | }); |
| 1147 | |
| 1148 | $t->app->plugin( |
| 1149 | Mount => { |
| 1150 | $mount_point => |
| 1151 | $fixtures_path->child('mock.pl') |
| 1152 | } |
| 1153 | ); |
| 1154 | |
| 1155 | $csrf = $t->get_ok('/') |
| 1156 | ->status_is(200) |
| 1157 | ->element_exists_not('div.button.top a') |
| 1158 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 1159 | ; |
| 1160 | |
| 1161 | $t->post_ok('/user/login' => form => { |
| 1162 | handle_or_email => 'test', |
| 1163 | pwd => 'pass', |
| 1164 | csrf_token => $csrf |
| 1165 | }) |
| 1166 | ->status_is(302) |
| 1167 | ->header_is('Location' => '/') |
| 1168 | ->content_is(''); |
| 1169 | |
| 1170 | $t->get_ok('/') |
| 1171 | ->status_is(200) |
| 1172 | ->element_exists_not('div.notify-error') |
| 1173 | ->element_exists('div.notify-success') |
| 1174 | ->text_is('div.notify-success', 'Login successful') |
| 1175 | ->element_exists_not('aside.off') |
| 1176 | ->element_exists_not('aside.active') |
| 1177 | ->element_exists('aside.settings') |
| 1178 | ; |
| 1179 | |
Akron | 53a171e | 2022-12-05 18:22:58 +0100 | [diff] [blame] | 1180 | $main::ENV{KALAMAR_CLIENT_FILE} = $client_file; |
| 1181 | |
| 1182 | $t = Test::Mojo::WithRoles->new('Kalamar' => { |
| 1183 | Kalamar => { |
| 1184 | plugins => ['Auth'] |
| 1185 | }, |
| 1186 | 'Kalamar-Auth' => { |
| 1187 | oauth2 => 1, |
| 1188 | # client_file => $client_file, |
| 1189 | } |
| 1190 | }); |
| 1191 | |
| 1192 | $t->app->plugin( |
| 1193 | Mount => { |
| 1194 | $mount_point => |
| 1195 | $fixtures_path->child('mock.pl') |
| 1196 | } |
| 1197 | ); |
| 1198 | |
| 1199 | $csrf = $t->get_ok('/') |
| 1200 | ->status_is(200) |
| 1201 | ->element_exists_not('div.button.top a') |
| 1202 | ->tx->res->dom->at('input[name=csrf_token]')->attr('value') |
| 1203 | ; |
| 1204 | |
| 1205 | $t->post_ok('/user/login' => form => { |
| 1206 | handle_or_email => 'test', |
| 1207 | pwd => 'pass', |
| 1208 | csrf_token => $csrf |
| 1209 | }) |
| 1210 | ->status_is(302) |
| 1211 | ->header_is('Location' => '/') |
| 1212 | ->content_is(''); |
| 1213 | |
| 1214 | $t->get_ok('/') |
| 1215 | ->status_is(200) |
| 1216 | ->element_exists_not('div.notify-error') |
| 1217 | ->element_exists('div.notify-success') |
| 1218 | ->text_is('div.notify-success', 'Login successful') |
| 1219 | ->element_exists_not('aside.off') |
| 1220 | ->element_exists_not('aside.active') |
| 1221 | ->element_exists('aside.settings') |
| 1222 | ; |
| 1223 | |
Akron | 66ef3b5 | 2022-11-22 14:25:15 +0100 | [diff] [blame] | 1224 | |
Akron | 33f5c67 | 2019-06-24 19:40:47 +0200 | [diff] [blame] | 1225 | done_testing; |
| 1226 | __END__ |
Akron | a8efaa9 | 2022-04-09 14:45:43 +0200 | [diff] [blame] | 1227 | |
| 1228 | |