|
9307 | 9307 | "type": "text/javascript", |
9308 | 9308 | "exec": [ |
9309 | 9309 | "pm.test(\"Check for collectionVariables\", function () {", |
9310 | | - " let vars = ['managementIP', 'user', 'password'];", |
9311 | | - " vars.forEach(function (item, index, array) {", |
9312 | | - " console.log(item, index);", |
9313 | | - " pm.expect(pm.collectionVariables.get(item), item + \" variable not set\").to.not.be.undefined;", |
9314 | | - " pm.expect(pm.collectionVariables.get(item), item + \" variable not set\").to.not.be.empty; ", |
9315 | | - " });", |
| 9310 | + " let managementIP = pm.collectionVariables.get(\"managementIP\");", |
| 9311 | + " let sessionId = pm.collectionVariables.get(\"sessionId\");", |
| 9312 | + " let user = pm.collectionVariables.get(\"user\");", |
| 9313 | + " let password = pm.collectionVariables.get(\"password\");", |
| 9314 | + " ", |
| 9315 | + " // Auto-detect S1C format: optimized detection and extraction", |
| 9316 | + " if (managementIP?.includes('/')) {", |
| 9317 | + " [managementIP, sessionId] = managementIP.split('/', 2);", |
| 9318 | + " pm.collectionVariables.set(\"sessionId\", sessionId);", |
| 9319 | + " }", |
| 9320 | + " ", |
| 9321 | + " pm.expect(managementIP, \"managementIP variable not set\").to.not.be.undefined;", |
| 9322 | + " pm.expect(managementIP, \"managementIP variable not set\").to.not.be.empty;", |
| 9323 | + " ", |
| 9324 | + " // Prepare login payload based on available credentials", |
| 9325 | + " let loginPayload = { 'session-id': sessionId };", |
| 9326 | + " ", |
| 9327 | + " if (!sessionId?.trim()) {", |
| 9328 | + " pm.expect(user, \"user variable not set\").to.not.be.undefined;", |
| 9329 | + " pm.expect(user, \"user variable not set\").to.not.be.empty;", |
| 9330 | + " pm.expect(password, \"password variable not set\").to.not.be.undefined;", |
| 9331 | + " pm.expect(password, \"password variable not set\").to.not.be.empty;", |
| 9332 | + " loginPayload = { user, password };", |
| 9333 | + " }", |
9316 | 9334 | "", |
9317 | 9335 | " if (!pm.collectionVariables.get(\"session\") || Date.now() > new Date(pm.collectionVariables.get(\"sessionTimeout\") * 1000)) {", |
9318 | 9336 | " pm.sendRequest({", |
9319 | | - " url: 'https://' + pm.collectionVariables.get(\"managementIP\") + '/web_api/v1.8/login',", |
| 9337 | + " url: 'https://${managementip}/web_api/v1.8/login',", |
9320 | 9338 | " method: 'POST',", |
9321 | | - " header: 'Content-Type: application/json', // Set the Content-Type header to application/json", |
| 9339 | + " header: 'Content-Type: application/json',", |
9322 | 9340 | " body: {", |
9323 | | - " mode: 'raw', // Use raw body mode", |
9324 | | - " raw: JSON.stringify({ // Convert the object to JSON string", |
9325 | | - " user: pm.collectionVariables.get(\"user\"),", |
9326 | | - " password: pm.collectionVariables.get(\"password\")", |
9327 | | - " })", |
| 9341 | + " mode: 'raw',", |
| 9342 | + " raw: JSON.stringify(loginPayload)", |
9328 | 9343 | " }", |
9329 | 9344 | " }, function (err, res) {", |
9330 | 9345 | " if (err) {", |
|
0 commit comments