From f54ec5d330572e6db1efd723000f1d101712103d Mon Sep 17 00:00:00 2001 From: BharathwajShankar Date: Fri, 31 May 2024 16:47:28 +0530 Subject: [PATCH] postman pre-requisite script addition --- .../UserOrg_APIs Test.postman_collection.json | 48 ++++++++-- .../UserOrg_APIs.postman_collection.json | 90 +++++++++++++++---- ...rOrg_Environment.postman_environment.json} | 20 ++++- 3 files changed, 132 insertions(+), 26 deletions(-) rename api-tests/Collections/{Lern_Environment.postman_environment.json => UserOrg_Environment.postman_environment.json} (91%) diff --git a/api-tests/Collections/UserOrg_APIs Test.postman_collection.json b/api-tests/Collections/UserOrg_APIs Test.postman_collection.json index 8b3a27b604..f54d6126f9 100644 --- a/api-tests/Collections/UserOrg_APIs Test.postman_collection.json +++ b/api-tests/Collections/UserOrg_APIs Test.postman_collection.json @@ -1,11 +1,11 @@ { "info": { - "_postman_id": "dbb9ef35-6501-41d3-aadf-96dd74f9b906", + "_postman_id": "3bec4286-bb4a-4a19-b81e-75b29644aeb5", "name": "UserOrg_APIs Test", "description": "The User ORG API is a collection of API's for creation and management of User and Org in sunbird platform.", "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json", "_exporter_id": "4875988", - "_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-dbb9ef35-6501-41d3-aadf-96dd74f9b906?action=share&source=collection_link&creator=4875988" + "_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-3bec4286-bb4a-4a19-b81e-75b29644aeb5?action=share&source=collection_link&creator=4875988" }, "item": [ { @@ -4014,7 +4014,8 @@ " pm.expect(jsonResponse.token_type).to.eql('bearer');", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -4046,12 +4047,12 @@ }, { "key": "username", - "value": "{{username}}", + "value": "{{org_admin_username}}", "type": "text" }, { "key": "password", - "value": "{{password}}", + "value": "{{org_admin_password}}", "type": "text" } ] @@ -21973,6 +21974,43 @@ "script": { "type": "text/javascript", "exec": [ + "const requiresHeaders = () => {", + " const requestUrl = pm.request.url.toString();", + "", + " // List of paths to ignore", + " const ignoredPaths = [", + " '/health',", + " '/auth/realms/sunbird/protocol/openid-connect/token',", + " '/auth/v1/refresh/token'", + " ];", + "", + " // Check if the request URL contains any of the ignored paths", + " return !ignoredPaths.some(path => requestUrl.includes(path));", + "};", + "", + "// Function to check if a specific header is present and not empty", + "const isHeaderProvided = (headerName) => {", + " const headers = pm.request.headers;", + " if (!headers) return false; // Check if headers exist", + "", + " // Find the specified header", + " const header = headers.find(h => h.key.toLowerCase() === headerName.toLowerCase());", + "", + " // Check if the header exists and is not disabled and its value is not empty", + " return header && !header.disabled && header.value.trim() !== '';", + "};", + "", + "// Check if the current endpoint requires headers", + "if (requiresHeaders()) {", + " // Check if Authorization header is provided", + " if (!isHeaderProvided('Authorization')) {", + " // If Authorization header is missing or empty, throw an error", + " throw new Error('Authorization header is missing or empty. Please provide a valid Authorization header.');", + " }", + "} else {", + " console.log('Skipping header checks for this endpoint.');", + "}", + "", "const getRandomName = () => {", "const firstNames = [\"Aarav\", \"Aarya\", \"Advait\", \"Aishwarya\", \"Akshay\", \"Ananya\", \"Aaradhya\", \"Ayush\", \"Deepika\", \"Ishaan\"];", "const lastNames = [\"Sharma\", \"Verma\", \"Singh\", \"Patel\", \"Gupta\", \"Kumar\", \"Joshi\", \"Shah\", \"Chopra\", \"Mehra\"];", diff --git a/api-tests/Collections/UserOrg_APIs.postman_collection.json b/api-tests/Collections/UserOrg_APIs.postman_collection.json index 5ac04b5241..0118ad1838 100644 --- a/api-tests/Collections/UserOrg_APIs.postman_collection.json +++ b/api-tests/Collections/UserOrg_APIs.postman_collection.json @@ -1,11 +1,11 @@ { "info": { - "_postman_id": "b3270121-69ca-422c-a273-17edf98135fd", + "_postman_id": "5ed5cbe6-8c1c-4638-a156-acb98d507d31", "name": "UserOrg_APIs", "description": "The User ORG API is a collection of API's for creation and management of User and Org in sunbird platform.", "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json", "_exporter_id": "4875988", - "_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-b3270121-69ca-422c-a273-17edf98135fd?action=share&source=collection_link&creator=4875988" + "_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-5ed5cbe6-8c1c-4638-a156-acb98d507d31?action=share&source=collection_link&creator=4875988" }, "item": [ { @@ -247,7 +247,18 @@ " pm.expect(jsonResponse.responseCode).to.eql(\"OK\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript", + "packages": {} } } ], @@ -255,12 +266,14 @@ "method": "POST", "header": [ { - "key": "Authorization", - "value": "{{kong_api_key}}" + "key": "Content-Type", + "value": "application/json", + "type": "text" }, { - "key": "Content-Type", - "value": "application/json" + "key": "Authorization", + "value": "{{kong_api_key}}", + "type": "text" } ], "body": { @@ -410,24 +423,28 @@ " pm.expect(jsonResponse.responseCode).to.eql(\"OK\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], "request": { "method": "POST", "header": [ - { - "key": "Authorization", - "value": "{{kong_api_key}}" - }, { "key": "X-Authenticated-User-token", - "value": "{{access_token}}" + "value": "{{keycloak_access_token}}", + "type": "text" }, { "key": "Content-Type", - "value": "application/json" + "value": "application/json", + "type": "text" + }, + { + "key": "Authorization", + "value": "{{kong_api_key}}", + "type": "text" } ], "body": { @@ -1951,15 +1968,18 @@ "header": [ { "key": "Authorization", - "value": "{{kong_api_key}}" + "value": "{{kong_api_key}}", + "type": "text" }, { "key": "X-Authenticated-User-token", - "value": "{{keycloak_access_token}}" + "value": "{{keycloak_access_token}}", + "type": "text" }, { "key": "Content-Type", - "value": "application/json" + "value": "application/json", + "type": "text" } ], "body": { @@ -4873,6 +4893,42 @@ "script": { "type": "text/javascript", "exec": [ + "const requiresHeaders = () => {", + " const requestUrl = pm.request.url.toString();", + "", + " // List of paths to ignore", + " const ignoredPaths = [", + " '/health',", + " '/auth/realms/sunbird/protocol/openid-connect/token',", + " '/auth/v1/refresh/token'", + " ];", + "", + " // Check if the request URL contains any of the ignored paths", + " return !ignoredPaths.some(path => requestUrl.includes(path));", + "};", + "", + "// Function to check if a specific header is present and not empty", + "const isHeaderProvided = (headerName) => {", + " const headers = pm.request.headers;", + " if (!headers) return false; // Check if headers exist", + "", + " // Find the specified header", + " const header = headers.find(h => h.key.toLowerCase() === headerName.toLowerCase());", + "", + " // Check if the header exists and is not disabled and its value is not empty", + " return header && !header.disabled && header.value.trim() !== '';", + "};", + "", + "// Check if the current endpoint requires headers", + "if (requiresHeaders()) {", + " // Check if Authorization header is provided", + " if (!isHeaderProvided('Authorization')) {", + " // If Authorization header is missing or empty, throw an error", + " throw new Error('Authorization header is missing or empty. Please provide a valid Authorization header.');", + " }", + "} else {", + " console.log('Skipping header checks for this endpoint.');", + "}", "const getRandomName = () => {", "const firstNames = [\"Aarav\", \"Aarya\", \"Advait\", \"Aishwarya\", \"Akshay\", \"Ananya\", \"Aaradhya\", \"Ayush\", \"Deepika\", \"Ishaan\"];", "const lastNames = [\"Sharma\", \"Verma\", \"Singh\", \"Patel\", \"Gupta\", \"Kumar\", \"Joshi\", \"Shah\", \"Chopra\", \"Mehra\"];", diff --git a/api-tests/Collections/Lern_Environment.postman_environment.json b/api-tests/Collections/UserOrg_Environment.postman_environment.json similarity index 91% rename from api-tests/Collections/Lern_Environment.postman_environment.json rename to api-tests/Collections/UserOrg_Environment.postman_environment.json index 872a58981d..ab43ea4efc 100644 --- a/api-tests/Collections/Lern_Environment.postman_environment.json +++ b/api-tests/Collections/UserOrg_Environment.postman_environment.json @@ -1,6 +1,6 @@ { - "id": "8e9c6ddc-5534-4d67-b85e-67690cade87f", - "name": "Lern_Environment", + "id": "9cb09471-4154-48ca-8b63-1810101f42b6", + "name": "UserOrg_Environment", "values": [ { "key": "kong_api_key", @@ -268,9 +268,21 @@ "value": "", "type": "default", "enabled": true + }, + { + "key": "org_admin_username", + "value": "", + "type": "default", + "enabled": true + }, + { + "key": "org_admin_password", + "value": "", + "type": "default", + "enabled": true } ], "_postman_variable_scope": "environment", - "_postman_exported_at": "2023-08-22T11:20:43.606Z", - "_postman_exported_using": "Postman/10.17.2" + "_postman_exported_at": "2024-05-30T09:55:54.569Z", + "_postman_exported_using": "Postman/10.24.25" } \ No newline at end of file