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