|
314 | 314 | "});", |
315 | 315 | "", |
316 | 316 | "const location = pm.response.headers.get('Location');", |
317 | | - "pm.test('Redirect contains JWT token', function() {", |
| 317 | + "pm.test('Redirect contains WebAPI OTC code', function() {", |
318 | 318 | " pm.expect(location).to.not.be.undefined;", |
319 | | - " pm.expect(location).to.include('token=');", |
| 319 | + " pm.expect(location).to.include('code=');", |
320 | 320 | "});", |
321 | 321 | "", |
322 | | - "// Extract JWT from redirect URL", |
| 322 | + "// Extract OTC from redirect URL", |
323 | 323 | "if (location) {", |
324 | | - " const tokenMatch = location.match(/[?&#]token=([^&#]+)/);", |
325 | | - " const token = tokenMatch ? tokenMatch[1] : null;", |
326 | | - " if (token) {", |
327 | | - " pm.collectionVariables.set('oidc_jwt_token', token);", |
328 | | - " pm.test('JWT token is well-formed', function() {", |
329 | | - " pm.expect(token).to.include('.');", |
330 | | - " const parts = token.split('.');", |
331 | | - " pm.expect(parts.length).to.equal(3);", |
| 324 | + " const otcMatch = location.match(/[?&#]code=([^&#]+)/);", |
| 325 | + " const otc = otcMatch ? otcMatch[1] : null;", |
| 326 | + " if (otc) {", |
| 327 | + " pm.collectionVariables.set('oidc_webapi_otc', otc);", |
| 328 | + " pm.test('OTC is well-formed UUID', function() {", |
| 329 | + " const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;", |
| 330 | + " pm.expect(otc).to.match(uuidRegex);", |
332 | 331 | " });", |
333 | 332 | " }", |
334 | 333 | "}" |
|
368 | 367 | } |
369 | 368 | }, |
370 | 369 | { |
371 | | - "name": "4. Get Token via Refresh", |
| 370 | + "name": "4. Redeem OTC Code", |
372 | 371 | "event": [ |
373 | | - { |
374 | | - "listen": "prerequest", |
375 | | - "script": { |
376 | | - "exec": [ |
377 | | - "const token = pm.collectionVariables.get('oidc_jwt_token');", |
378 | | - "if (token) {", |
379 | | - " pm.request.headers.add({", |
380 | | - " key: 'Authorization',", |
381 | | - " value: 'Bearer ' + token", |
382 | | - " });", |
383 | | - "}" |
384 | | - ], |
385 | | - "type": "text/javascript" |
386 | | - } |
387 | | - }, |
388 | 372 | { |
389 | 373 | "listen": "test", |
390 | 374 | "script": { |
391 | 375 | "exec": [ |
392 | | - "const token = pm.collectionVariables.get('oidc_jwt_token');", |
393 | | - "if (!token) {", |
394 | | - " pm.test.skip('No OIDC token available');", |
| 376 | + "const otc = pm.collectionVariables.get('oidc_webapi_otc');", |
| 377 | + "if (!otc) {", |
| 378 | + " pm.test.skip('No OIDC OTC code available');", |
395 | 379 | "} else {", |
396 | | - " pm.test('Refresh returns 200 with new JWT', function() {", |
| 380 | + " pm.test('OTC redemption returns 200', function() {", |
397 | 381 | " pm.response.to.have.status(200);", |
398 | 382 | " });", |
399 | 383 | "", |
400 | 384 | " const jsonData = pm.response.json();", |
401 | | - " pm.test('Refresh response contains login and jwt', function() {", |
| 385 | + " pm.test('Redemption response contains login and jwt', function() {", |
402 | 386 | " pm.expect(jsonData).to.have.property('login');", |
403 | 387 | " pm.expect(jsonData).to.have.property('jwt');", |
404 | 388 | " pm.expect(jsonData.login).to.equal('testuser');", |
405 | 389 | " });", |
406 | 390 | "", |
407 | | - " // Update token for subsequent requests", |
| 391 | + " // Store JWT for subsequent requests", |
408 | 392 | " if (jsonData.jwt) {", |
409 | 393 | " pm.collectionVariables.set('oidc_jwt_token', jsonData.jwt);", |
| 394 | + " pm.test('JWT token is well-formed', function() {", |
| 395 | + " pm.expect(jsonData.jwt).to.include('.');", |
| 396 | + " const parts = jsonData.jwt.split('.');", |
| 397 | + " pm.expect(parts.length).to.equal(3);", |
| 398 | + " });", |
410 | 399 | " }", |
411 | 400 | "}" |
412 | 401 | ], |
|
418 | 407 | "method": "GET", |
419 | 408 | "header": [], |
420 | 409 | "url": { |
421 | | - "raw": "{{base_url}}/user/refresh", |
| 410 | + "raw": "{{base_url}}/user/login/otc?code={{oidc_webapi_otc}}", |
422 | 411 | "host": [ |
423 | 412 | "{{base_url}}" |
424 | 413 | ], |
425 | 414 | "path": [ |
426 | 415 | "user", |
427 | | - "refresh" |
| 416 | + "login", |
| 417 | + "otc" |
| 418 | + ], |
| 419 | + "query": [ |
| 420 | + { |
| 421 | + "key": "code", |
| 422 | + "value": "{{oidc_webapi_otc}}" |
| 423 | + } |
428 | 424 | ] |
429 | 425 | } |
430 | 426 | } |
|
990 | 986 | "key": "oidc_auth_code", |
991 | 987 | "value": "" |
992 | 988 | }, |
| 989 | + { |
| 990 | + "key": "oidc_webapi_otc", |
| 991 | + "value": "" |
| 992 | + }, |
993 | 993 | { |
994 | 994 | "key": "oidc_jwt_token", |
995 | 995 | "value": "" |
|
0 commit comments