Skip to content

Commit

Permalink
Fix #23603 : Allow users to write code when creating a file - PR2 (#2…
Browse files Browse the repository at this point in the history
…4267)

* Implementing SonarQube feedback.

* #23603 : Allow users to write code when creating a file

* Adding more code changes and Postman tests.

* Fixing other Postman Tests.

* #23603 : Forbid access to Temp File update method for Anonymous Users.

* Implementing SonarQube feedback.

* Implementing SonarQube feedback.

* #23603 : Creating new branch based on master.

* Implementing JS feedback from Manuel Rojas.

* Implementing more JS feedback from Manuel Rojas.
  • Loading branch information
jcastro-dotcms authored Mar 10, 2023
1 parent 124ec30 commit b6f0095
Show file tree
Hide file tree
Showing 7 changed files with 945 additions and 292 deletions.
29 changes: 28 additions & 1 deletion dotCMS/src/curl-test/Content Resource.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "64a156b5-40b4-46ce-8bab-6083e910e48a",
"_postman_id": "50e22041-5236-42d7-8d37-b9a39f0457e3",
"name": "Content Resource",
"description": "Content Resource test",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
Expand Down Expand Up @@ -1763,6 +1763,15 @@
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/UNPUBLISH?inode={{fileInode}}&identifier={{fileId}}",
"host": [
Expand Down Expand Up @@ -1835,6 +1844,15 @@
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/ARCHIVE?inode={{fileInode}}&identifier={{fileId}}",
"host": [
Expand Down Expand Up @@ -1907,6 +1925,15 @@
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/DELETE?inode={{fileInode}}&identifier={{fileId}}",
"host": [
Expand Down
299 changes: 291 additions & 8 deletions dotCMS/src/curl-test/TempAPI.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,279 @@
{
"info": {
"_postman_id": "1faea77b-c035-4129-a215-3608487d19b3",
"_postman_id": "b65639a1-cec6-4b6c-b8b6-ab483db33b5b",
"name": "TempAPI",
"description": "Verifies that the Temp File API is working as expected. It allows users to create temporary files in the dotCMS assets folder.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "11174695"
"_exporter_id": "5403727"
},
"item": [
{
"name": "Temp File As Plain Text",
"item": [
{
"name": "Create Temp File",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"let randomNumber = Math.floor(Math.random() * 100);",
"pm.collectionVariables.set(\"tempFileName\", randomNumber + \"-test-temp-file.txt\");"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Test Temporary File creation HTTP Status must be successful\", function() {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.collectionVariables.set(\"tempFileId\", pm.response.json().tempFiles[0].id);"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "password",
"value": "admin",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Origin",
"value": "localhost",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fileName\": \"{{tempFileName}}\",\n \"fileContent\": \"This is the content of the Temporary File.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/temp/id/new",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"temp",
"id",
"new"
]
}
},
"response": []
},
{
"name": "Update Existing Temp File Content",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Test Temporary File update HTTP Status must be successful\", function() {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"Temporary File ID must be the same\", function() {",
" let tempFileId = pm.collectionVariables.get(\"tempFileId\");",
" pm.expect(pm.response.json().tempFiles[0].id).to.eql(tempFileId, \"An error occurred when checking the temp file ID\");",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "password",
"value": "admin",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Origin",
"value": "localhost",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fileName\": \"{{tempFileName}}\",\n \"fileContent\": \"This is the new content of the Temporary File.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/temp/id/{{tempFileId}}",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"temp",
"id",
"{{tempFileId}}"
]
}
},
"response": []
},
{
"name": "Update Non-Existent Temp File",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Non-Existing Test Temporary File creation HTTP Status must be successful\", function() {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"New Temporary File ID must NOT match the previous one\", function() {",
" let tempFileId = pm.collectionVariables.get(\"tempFileId\");",
" pm.expect(pm.response.json().tempFiles[0].id).to.not.eql(tempFileId, \"An error occurred when checking different temp file IDs\");",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"let randomNumber = Math.floor(Math.random() * 100);",
"pm.collectionVariables.set(\"tempFileName\", \"new-\" + randomNumber + \"-test-temp-file.txt\");"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "password",
"value": "admin",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Origin",
"value": "localhost",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fileName\": \"{{tempFileName}}\",\n \"fileContent\": \"Here is some test content.\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/temp/id/non-existent-id",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"temp",
"id",
"non-existent-id"
]
}
},
"response": []
}
],
"description": "This request collection creates Temporary Files provided as plain text instead of binary files."
},
{
"name": "Upload Multiple with one wrong file",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = pm.response.json();",
"pm.test(\"Checking file names and operation status code\", function () {",
" var jsonData = pm.response.json();",
" let found = false;",
" jsonData.tempFiles.forEach((item) => {",
"",
"pm.test(\"File name check\", function () {",
" pm.expect(jsonData.tempFiles[0].fileName).to.eql('Landscape_2009_romantic_country_garden.jpeg');",
" pm.expect(jsonData.tempFiles[1].fileName).to.eql('16475687531_eac8a30914_b.jpeg');",
" pm.expect(jsonData.tempFiles[2].errorCode).to.eql('400');",
"});",
" if (item.fileName == \"Landscape_2009_romantic_country_garden.jpeg\") {",
" found = true;",
" }",
"",
" });",
" pm.expect(found).to.eq(true, \"Expected image 'Landscape_2009_romantic_country_garden.jpeg' was not found.\")",
" found = false;",
" jsonData.tempFiles.forEach((item) => {",
"",
" if (item.fileName == \"16475687531_eac8a30914_b.jpeg\") {",
" found = true;",
" }",
"",
" });",
" pm.expect(found).to.eq(true, \"Expected image '16475687531_eac8a30914_b.jpeg' was not found.\")",
" found = false;",
" jsonData.tempFiles.forEach((item) => {",
"",
" if (item.errorCode == \"400\") {",
" found = true;",
" }",
"",
" });",
" pm.expect(found).to.eq(true, \"Expected error code '400' not found.\")",
"});",
""
],
"type": "text/javascript"
Expand Down Expand Up @@ -157,5 +410,35 @@
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "tempFileName",
"value": ""
},
{
"key": "tempFileId",
"value": ""
}
]
}
Loading

0 comments on commit b6f0095

Please sign in to comment.