added scripts and postman collections for new build

This commit is contained in:
Philip Ellis
2023-08-31 13:07:19 -05:00
parent 2ba5f25c3b
commit b6cef42870
10 changed files with 283145 additions and 3 deletions

View File

@@ -0,0 +1,10 @@
{
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{accessToken}}",
"type": "string"
}
]
}

View File

@@ -0,0 +1,48 @@
const fs = require('fs');
// Function to recursively delete "auth" key from an object
const deleteAuthKey = (obj) => {
for (const key in obj) {
if (typeof obj[key] === 'object') {
deleteAuthKey(obj[key]); // Recursive call for nested objects
}
if (key === 'auth') {
delete obj[key];
}
}
};
const args = process.argv;
// Read the JSON file
fs.readFile(args[2], 'utf8', (err, data) => {
if (err) {
console.error('Error reading the file:', err);
return;
}
try {
// Parse the JSON content
const jsonObject = JSON.parse(data);
// Delete all occurrences of the key "auth"
deleteAuthKey(jsonObject);
jsonObject.auth = JSON.parse(fs.readFileSync('postman-script/base-auth.json', 'utf8'));
jsonObject.event = JSON.parse(fs.readFileSync('postman-script/pre-script.json', 'utf8'));
jsonObject.variable = JSON.parse(fs.readFileSync('postman-script/variable.json', 'utf8'));
// Write the modified JSON content back to the file
fs.writeFile(args[2], JSON.stringify(jsonObject, null, 2), (writeErr) => {
if (writeErr) {
console.error('Error writing the file:', writeErr);
} else {
console.log('Auth keys deleted and file updated successfully.');
}
});
} catch (parseError) {
console.error('Error parsing JSON:', parseError);
}
});

View File

@@ -0,0 +1,65 @@
[
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"const domain = pm.environment.get('domain') ? pm.environment.get('domain') : pm.collectionVariables.get('domain')",
"const tokenUrl = 'https://' + pm.environment.get('tenant') + '.api.' + domain + '.com/oauth/token';",
"const clientId = pm.environment.get('clientId');",
"const clientSecret = pm.environment.get('clientSecret');",
"",
"const getTokenRequest = {",
" method: 'POST',",
" url: tokenUrl,",
" body: {",
" mode: 'formdata',",
" formdata: [{",
" key: 'grant_type',",
" value: 'client_credentials'",
" },",
" {",
" key: 'client_id',",
" value: clientId",
" },",
" {",
" key: 'client_secret',",
" value: clientSecret",
" }",
" ]",
" }",
"};",
"",
"",
"var moment = require('moment');",
"if (!pm.environment.has('tokenExpTime')) {",
" pm.environment.set('tokenExpTime', moment());",
"}",
"",
"if (moment(pm.environment.get('tokenExpTime')) <= moment() || !pm.environment.get('tokenExpTime') || !pm.environment.get('accessToken')) {",
" var time = moment();",
" time.add(12, 'hours');",
" pm.environment.set('tokenExpTime', time);",
" pm.sendRequest(getTokenRequest, (err, response) => {",
" const jsonResponse = response.json();",
" if (response.code != 200) {",
" throw new Error(`Unable to authenticate: ${JSON.stringify(jsonResponse)}`);",
" }",
" const newAccessToken = jsonResponse.access_token;",
" pm.environment.set('accessToken', newAccessToken);",
" });",
"",
"}"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]

View File

@@ -0,0 +1,12 @@
[
{
"key": "domain",
"value": "identitynow",
"type": "string"
},
{
"key": "baseUrl",
"value": "https://{{tenant}}.api.{{domain}}.com",
"type": "string"
}
]