Skip to content

Commit

Permalink
#27782 Using JWT in Postman Test / Improve response message
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyDOTCMS committed Aug 30, 2024
1 parent b58fca0 commit 914c301
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 100 deletions.
2 changes: 1 addition & 1 deletion dotCMS/src/main/java/com/dotcms/rest/BundleResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private static Response buildResponseToDeleteEndpoint(final DeleteBundlesByIdent

if (!notExistingBundles.isEmpty()) {
message.append(String.format(
"The following bundles was not deleted because it does not exist: %s",
"The following bundles were not deleted because they don't exist: %s",
notExistingBundles.stream().collect(Collectors.joining(", ")))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\");",
"});",
""
],
Expand All @@ -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"
}
]
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -802,7 +784,8 @@
"exec": [
""
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
Expand All @@ -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"
}
]
Expand Down Expand Up @@ -882,7 +861,8 @@
"exec": [
""
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
Expand All @@ -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"
}
]
Expand Down Expand Up @@ -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\");",
"});",
""
],
Expand All @@ -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"
}
]
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 914c301

Please sign in to comment.