-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#27782 Using JWT in Postman Test / Improve response message
- Loading branch information
1 parent
b58fca0
commit 914c301
Showing
2 changed files
with
118 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ | |
"});", | ||
"", | ||
"pm.test(\"Valid response\", function () {", | ||
" pm.expect(pm.response.text()).to.include(\"The following bundles was not deleted because it does not exist: n0ex1st-18c1-4eb0-815e-981619635532\");", | ||
" pm.expect(pm.response.text()).to.include(\"The following bundles were not deleted because they don't exist: n0ex1st-18c1-4eb0-815e-981619635532\");", | ||
"});", | ||
"" | ||
], | ||
|
@@ -94,16 +94,11 @@ | |
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -635,22 +630,18 @@ | |
"", | ||
"" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
} | ||
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -684,16 +675,11 @@ | |
"name": "Add Field to Content Type", | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -744,22 +730,18 @@ | |
"", | ||
"" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
} | ||
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -802,7 +784,8 @@ | |
"exec": [ | ||
"" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
}, | ||
{ | ||
|
@@ -816,22 +799,18 @@ | |
" pm.collectionVariables.set(\"bundleId\", jsonData[\"bundleId\"]);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
} | ||
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"type": "string" | ||
}, | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -882,7 +861,8 @@ | |
"exec": [ | ||
"" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
}, | ||
{ | ||
|
@@ -893,22 +873,18 @@ | |
" pm.response.to.have.status(200);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
} | ||
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -964,7 +940,7 @@ | |
"var bundleId = pm.collectionVariables.get(\"bundleId\");", | ||
"", | ||
"pm.test(\"Valid response\", function () {", | ||
" pm.expect(pm.response.text()).to.include('Removing the follow bundles in a separated process, the result of the operation will be notified: ' + bundleId + ', The following bundles was not deleted because it does not exist: n0ex1st-18c1-4eb0-815e-981619635532');", | ||
" pm.expect(pm.response.text()).to.include('Removing the follow bundles in a separated process, the result of the operation will be notified: ' + bundleId + \", The following bundles were not deleted because they don't exist: n0ex1st-18c1-4eb0-815e-981619635532\");", | ||
"});", | ||
"" | ||
], | ||
|
@@ -975,16 +951,11 @@ | |
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -1048,22 +1019,18 @@ | |
"}", | ||
"" | ||
], | ||
"type": "text/javascript" | ||
"type": "text/javascript", | ||
"packages": {} | ||
} | ||
} | ||
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"type": "string" | ||
}, | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -1113,16 +1080,11 @@ | |
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"type": "string" | ||
}, | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -1181,16 +1143,11 @@ | |
], | ||
"request": { | ||
"auth": { | ||
"type": "basic", | ||
"basic": [ | ||
{ | ||
"key": "username", | ||
"value": "[email protected]", | ||
"type": "string" | ||
}, | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "password", | ||
"value": "admin", | ||
"key": "token", | ||
"value": "{{jwt}}", | ||
"type": "string" | ||
} | ||
] | ||
|
@@ -2976,6 +2933,67 @@ | |
] | ||
} | ||
], | ||
"event": [ | ||
{ | ||
"listen": "prerequest", | ||
"script": { | ||
"type": "text/javascript", | ||
"packages": {}, | ||
"exec": [ | ||
" const serverURL = pm.environment.get('serverURL'); // Get the server URL from the environment variable", | ||
" const apiUrl = `${serverURL}/api/v1/apitoken`; // Construct the full API URL", | ||
"", | ||
"// If we are unable to get the JWT we need to generate a new one", | ||
" if (!pm.environment.get('jwt')) {", | ||
" const username = pm.environment.get(\"user\");", | ||
" const password = pm.environment.get(\"password\");", | ||
" const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');", | ||
"", | ||
"", | ||
" const requestOptions = {", | ||
" url: apiUrl,", | ||
" method: \"POST\",", | ||
" header: {", | ||
" \"accept\": \"*/*\",", | ||
" \"content-type\": \"application/json\",", | ||
" \"Authorization\": `Basic ${basicAuth}`", | ||
" },", | ||
" body: {", | ||
" mode: \"raw\",", | ||
" raw: JSON.stringify({", | ||
" \"expirationSeconds\": 7200,", | ||
" \"userId\": \"dotcms.org.1\",", | ||
" \"network\": \"0.0.0.0/0\",", | ||
" \"claims\": {\"label\": \"postman-tests\"}", | ||
" })", | ||
" }", | ||
" };", | ||
"", | ||
"", | ||
" pm.sendRequest(requestOptions, function (err, response) {", | ||
" if (err) {", | ||
" console.log(err);", | ||
" } else {", | ||
" const jwt = response.json().entity.jwt;", | ||
" pm.environment.set('jwt', jwt);", | ||
" console.log(jwt);", | ||
" }", | ||
" });", | ||
" }" | ||
] | ||
} | ||
}, | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"type": "text/javascript", | ||
"packages": {}, | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
} | ||
], | ||
"variable": [ | ||
{ | ||
"key": "bundleName", | ||
|