From 69388968268cfb88162181ef5bf2a5d7bc87c85c Mon Sep 17 00:00:00 2001 From: James Dalphond Date: Thu, 6 Aug 2026 12:24:16 -0400 Subject: [PATCH] Updating postman tests to also run through legacy endpoints --- ...-services-registry.postman_collection.json | 432 +++++++++++++++++- 1 file changed, 431 insertions(+), 1 deletion(-) diff --git a/src/scripts/test_data/postman/cve-services-registry.postman_collection.json b/src/scripts/test_data/postman/cve-services-registry.postman_collection.json index b99b7dd41..e79e30e80 100644 --- a/src/scripts/test_data/postman/cve-services-registry.postman_collection.json +++ b/src/scripts/test_data/postman/cve-services-registry.postman_collection.json @@ -1388,7 +1388,8 @@ "script": { "type": "text/javascript", "exec": [ - "postman.setNextRequest(null)", + "pm.collectionVariables.set('registryFlowCompleted', 'true')", + "postman.setNextRequest(pm.collectionVariables.get('legacyFlowCompleted') ? null : 'Create Legacy Org')", "", "pm.test('status is 403', () => {", " pm.response.to.have.status(403)", @@ -1443,6 +1444,435 @@ }, "description": "Verifies the created admin cannot reserve CVE-IDs for another organization." } + }, + { + "name": "Legacy Org and User Format Contract", + "item": [ + { + "name": "Create Legacy Org", + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "pm.collectionVariables.unset('legacyFlowCompleted')", + "pm.collectionVariables.unset('registryFlowCompleted')", + "const id = `${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`", + "pm.collectionVariables.set('legacyOrgShortName', `plegacy_${id}`.slice(0,32))", + "pm.collectionVariables.set('legacyOrgName', `Postman Legacy CNA ${id}`)", + "pm.collectionVariables.set('legacyUsername', `user_${id}@postman-legacy.example`)", + "pm.collectionVariables.set('legacyUsernameEncoded', encodeURIComponent(pm.collectionVariables.get('legacyUsername')))", + "pm.collectionVariables.set('legacyOrgUuid', '')" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.created && body.created.UUID && body.created.name && !body.created.long_name)", + "postman.setNextRequest(ok ? 'Get Legacy Org' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.created && body.created.UUID && body.created.name && !body.created.long_name", + "})" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org", + "body": { + "mode": "raw", + "raw": "{\"short_name\":\"{{legacyOrgShortName}}\",\"name\":\"{{legacyOrgName}}\",\"authority\":{\"active_roles\":[\"CNA\"]},\"policies\":{\"id_quota\":500}}" + } + } + }, + { + "name": "Get Legacy Org", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.name === pm.collectionVariables.get('legacyOrgName') && body.policies && body.policies.id_quota === 500 && !body.long_name)", + "postman.setNextRequest(ok ? 'Create Legacy User' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.name === pm.collectionVariables.get('legacyOrgName') && body.policies && body.policies.id_quota === 500 && !body.long_name", + "})" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}" + } + }, + { + "name": "Create Legacy User", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.created && body.created.username === pm.collectionVariables.get('legacyUsername') && body.created.org_UUID && !body.created.status)", + "postman.setNextRequest(ok ? 'Get Legacy User' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.created && body.created.username === pm.collectionVariables.get('legacyUsername') && body.created.org_UUID && !body.created.status", + "})" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/user", + "body": { + "mode": "raw", + "raw": "{\"username\":\"{{legacyUsername}}\",\"name\":{\"first\":\"Legacy\",\"last\":\"User\"},\"authority\":{\"active_roles\":[\"ADMIN\"]}}" + } + } + }, + { + "name": "Get Legacy User", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.username === pm.collectionVariables.get('legacyUsername') && body.org_UUID && !body.status && !body.secret)", + "postman.setNextRequest(ok ? 'List Legacy Users' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.username === pm.collectionVariables.get('legacyUsername') && body.org_UUID && !body.status && !body.secret", + "})" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/user/{{legacyUsernameEncoded}}" + } + }, + { + "name": "List Legacy Users", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (Array.isArray(body.users) && body.users.some((x) => x.username === pm.collectionVariables.get('legacyUsername') && x.org_UUID && !x.status))", + "postman.setNextRequest(ok ? 'Get Legacy Org Quota' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " Array.isArray(body.users) && body.users.some((x) => x.username === pm.collectionVariables.get('legacyUsername') && x.org_UUID && !x.status)", + "})" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/users" + } + }, + { + "name": "Get Legacy Org Quota", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.id_quota === 500)", + "postman.setNextRequest(ok ? 'Update Legacy Org' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.id_quota === 500", + "})" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/id_quota" + } + }, + { + "name": "Update Legacy Org", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.updated && body.updated.name && body.updated.policies && body.updated.policies.id_quota === 500 && !body.updated.long_name)", + "postman.setNextRequest(ok ? 'Update Legacy User' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.updated && body.updated.name && body.updated.policies && body.updated.policies.id_quota === 500 && !body.updated.long_name", + "})" + ] + } + } + ], + "request": { + "method": "PUT", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}?name={{legacyOrgName}}" + } + }, + { + "name": "Update Legacy User", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.updated && body.updated.name && body.updated.name.first === 'LegacyUpdated' && !body.updated.status)", + "postman.setNextRequest(ok ? 'Reset Legacy User Secret' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.updated && body.updated.name && body.updated.name.first === 'LegacyUpdated' && !body.updated.status", + "})" + ] + } + } + ], + "request": { + "method": "PUT", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/user/{{legacyUsernameEncoded}}?name.first=LegacyUpdated" + } + }, + { + "name": "Reset Legacy User Secret", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (typeof body['API-secret'] === 'string' && body['API-secret'].length > 0)", + "postman.setNextRequest(ok ? 'Authenticate Legacy User with Reset Secret' : null)", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " typeof body['API-secret'] === 'string' && body['API-secret'].length > 0", + "if (ok) pm.collectionVariables.set('legacyUserApiKey', body['API-secret'])", + "})" + ] + } + } + ], + "request": { + "method": "PUT", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{apiUser}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{apiOrg}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{apiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/user/{{legacyUsernameEncoded}}/reset_secret" + } + }, + { + "name": "Authenticate Legacy User with Reset Secret", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "let body = {}", + "try { body = pm.response.json() } catch (error) {}", + "const ok = pm.response.code === 200 && (body.username === pm.collectionVariables.get('legacyUsername') && !body.status)", + "pm.collectionVariables.set('legacyFlowCompleted', 'true')", + "postman.setNextRequest(pm.collectionVariables.get('registryFlowCompleted') ? null : 'Create Registry Org')", + "pm.test('legacy format contract', () => {", + " pm.expect(ok).to.equal(true)", + " body.username === pm.collectionVariables.get('legacyUsername') && !body.status", + "})" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "CVE-API-USER", + "value": "{{legacyUsername}}" + }, + { + "key": "CVE-API-ORG", + "value": "{{legacyOrgShortName}}" + }, + { + "key": "CVE-API-KEY", + "value": "{{legacyUserApiKey}}" + } + ], + "url": "{{baseUrl}}/api/org/{{legacyOrgShortName}}/user/{{legacyUsernameEncoded}}" + } + } + ] } ], "variable": [