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