From 56c1c5af81ef306913b4cab17390ddf8792df614 Mon Sep 17 00:00:00 2001 From: Ben Watson Date: Wed, 14 Apr 2021 14:47:53 -0400 Subject: [PATCH] fixes a bug with the getDynamicValues query param --- dist/alks.cjs.js | 6 +-- dist/alks.esm.js | 6 +-- dist/alks.min.js | 2 +- dist/alks.umd.js | 6 +-- src/alks.js | 2 +- test/test.js | 110 ++++++++++++++++++++++++++++++++--------------- 6 files changed, 87 insertions(+), 45 deletions(-) diff --git a/dist/alks.cjs.js b/dist/alks.cjs.js index 4b80eed5..b25026df 100644 --- a/dist/alks.cjs.js +++ b/dist/alks.cjs.js @@ -1,6 +1,6 @@ 'use strict'; -var version = "1.11.2"; +var version = "1.11.3"; const Buffer = require('buffer').Buffer; const fetch = require('node-fetch'); @@ -224,7 +224,7 @@ class alks { * }) */ getAllAWSRoleTypes(props) { - const url = props.getDynamicValues ? 'allAwsRoleTypes' : 'allAwsRoleTypes?getDynamicValues=true'; + const url = props.getDynamicValues ? 'allAwsRoleTypes?getDynamicValues=true' : 'allAwsRoleTypes'; return(this._doFetch(url, props, 'GET').then(results => results.roleTypes)) } @@ -835,7 +835,7 @@ class alks { delete opts.sessionToken; } - var responsePromise = opts._fetch(`${opts.baseUrl}/${path}/`, { + var responsePromise = opts._fetch(`${opts.baseUrl}/${path}`, { method, headers, body: method == 'GET' ? undefined : JSON.stringify(opts) }); diff --git a/dist/alks.esm.js b/dist/alks.esm.js index 14ee7653..c0db426d 100644 --- a/dist/alks.esm.js +++ b/dist/alks.esm.js @@ -1,4 +1,4 @@ -var version = "1.11.2"; +var version = "1.11.3"; const fetch = window.fetch.bind(window); @@ -221,7 +221,7 @@ class alks { * }) */ getAllAWSRoleTypes(props) { - const url = props.getDynamicValues ? 'allAwsRoleTypes' : 'allAwsRoleTypes?getDynamicValues=true'; + const url = props.getDynamicValues ? 'allAwsRoleTypes?getDynamicValues=true' : 'allAwsRoleTypes'; return(this._doFetch(url, props, 'GET').then(results => results.roleTypes)) } @@ -832,7 +832,7 @@ class alks { delete opts.sessionToken; } - var responsePromise = opts._fetch(`${opts.baseUrl}/${path}/`, { + var responsePromise = opts._fetch(`${opts.baseUrl}/${path}`, { method, headers, body: method == 'GET' ? undefined : JSON.stringify(opts) }); diff --git a/dist/alks.min.js b/dist/alks.min.js index c926e328..1d2045f8 100644 --- a/dist/alks.min.js +++ b/dist/alks.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).alks=t()}(this,function(){"use strict";var n=window.fetch.bind(window),t=function(e,t){void 0===t&&(t={}),this.defaults=Object.assign({},t,{_fetch:n},e)};t.prototype._base64Encode=function(e){return void 0===e&&(e=""),btoa(e)},t.prototype.create=function(e){return new t(e,this.defaults)},t.prototype.getAccounts=function(e){return this._doFetch("getAccounts",e).then(function(t){return Object.keys(t.accountListRole).map(function(e){return{account:e,role:t.accountListRole[e][0].role,iamKeyActive:t.accountListRole[e][0].iamKeyActive,maxKeyDuration:t.accountListRole[e][0].maxKeyDuration,skypieaAccount:t.accountListRole[e][0].skypieaAccount}})})},t.prototype.getKeys=function(e){return this._doFetch("getKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getIAMKeys=function(e){return this._doFetch("getIAMKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getAllAWSRoleTypes=function(e){var t=e.getDynamicValues?"allAwsRoleTypes":"allAwsRoleTypes?getDynamicValues=true";return this._doFetch(t,e,"GET").then(function(e){return e.roleTypes})},t.prototype.getAWSRoleTypes=function(e){return this._doFetch("getAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.getNonServiceAWSRoleTypes=function(e){return this._doFetch("getNonServiceAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.createRole=function(e){return this._doFetch("createRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.createNonServiceRole=function(e){return this._doFetch("createNonServiceRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.awsAccountRoles=function(e){return this._doFetch("awsAccountRoles?account="+e.account,e,"GET").then(function(e){return e.awsRoleList})},t.prototype.listAWSAccountRoles=function(e){return this._doFetch("listAWSAccountRoles",e).then(function(e){return JSON.parse(e.jsonAWSRoleList).map(function(e){return e.split("/").slice(-1)[0]})})},t.prototype.getAccountRole=function(t){return this._doFetch("getAccountRole",t).then(function(e){if(!e.roleExists)throw new Error("Role "+t.roleName+" does not exist in this account");return e.roleARN})},t.prototype.deleteRole=function(e){return this._doFetch("deleteRole",e).then(function(){return!0})},t.prototype.addRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e).then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.deleteRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e,"DELETE").then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.getUserAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/"+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserAccessByRole=function(e){var t=e.accountId;return this._doFetch("reports/users-by-role?accountId="+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserRoleAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/roles/"+t,e).then(function(e){return e.roles})},t.prototype.getAccountOwners=function(e){var t=e.accountId;return this._doFetch("userAccess/owners/"+t,e,"GET").then(function(e){return e.accountOwners})},t.prototype.createAccessKeys=function(e){return this._doFetch("accessKeys",e).then(function(e){return o(e,["iamUserArn","accessKey","secretKey","addedIAMUserToGroup"])})},t.prototype.deleteIAMUser=function(e){return this._doFetch("IAMUser",e,"DELETE").then(function(){return!0})},t.prototype.version=function(e){return this._doFetch("version",e,"GET").then(function(e){return o(e,["version"])})},t.prototype.getLoginRole=function(e){var t=e.accountId,n=e.role;return this._doFetch("loginRoles/id/"+t+"/"+n,null).then(function(e){return o(e,["account","role","iamKeyActive","maxKeyDuration"])})},t.prototype.getAccessToken=function(e){return this._doFetch("accessToken",e).then(function(e){return o(e,["accessToken","expiresIn"])})},t.prototype.getRefreshTokens=function(e){return this._doFetch("refreshTokens",e,"GET").then(function(e){return e.refreshTokens.map(function(e){return o(e,["clientId","id","userId","value"])})})},t.prototype.revoke=function(e){return this._doFetch("revoke",e).then(function(e){return"Success"==e.statusMessage})},t.prototype._doFetch=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n="POST");var o=Object.assign({},this.defaults,t),r={"Content-Type":"application/json","User-Agent":"AlksJS/1.11.2"};if(o.accessToken&&(r.Authorization="Bearer "+o.accessToken,delete o.accessToken),o.userid||o.password){console.error("The userid and password properties are deprecated and should be replaced with an access token");var s=this._base64Encode(o.userid+":"+o.password);r.Authorization="Basic "+s,delete o.userid,delete o.password}o.accessKey&&(r["ALKS-STS-Access-Key"]=o.accessKey,delete o.accessKey),o.secretKey&&(r["ALKS-STS-Secret-Key"]=o.secretKey,delete o.secretKey),o.sessionToken&&(r["ALKS-STS-Session-Token"]=o.sessionToken,delete o.sessionToken);var c=o._fetch(o.baseUrl+"/"+e+"/",{method:n,headers:r,body:"GET"==n?void 0:JSON.stringify(o)}),i=c.then(function(e){return e.json()}).catch(function(){});return Promise.all([c,i]).then(function(e){var t=e[0],n=e[1];if(!t.ok)throw new u(t,n);return n})};var o=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})},u=function(r){function e(e,t){var n=Array.isArray(t.errors)?t.errors:[];e.statusText&&n.unshift(e.statusText);var o=n.join("; ");r.call(this,o),this.status=e.status,this.message=o,Object.assign(this,t)}return r&&(e.__proto__=r),(e.prototype=Object.create(r&&r.prototype)).constructor=e}(Error);return new t}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).alks=t()}(this,function(){"use strict";var n=window.fetch.bind(window),t=function(e,t){void 0===t&&(t={}),this.defaults=Object.assign({},t,{_fetch:n},e)};t.prototype._base64Encode=function(e){return void 0===e&&(e=""),btoa(e)},t.prototype.create=function(e){return new t(e,this.defaults)},t.prototype.getAccounts=function(e){return this._doFetch("getAccounts",e).then(function(t){return Object.keys(t.accountListRole).map(function(e){return{account:e,role:t.accountListRole[e][0].role,iamKeyActive:t.accountListRole[e][0].iamKeyActive,maxKeyDuration:t.accountListRole[e][0].maxKeyDuration,skypieaAccount:t.accountListRole[e][0].skypieaAccount}})})},t.prototype.getKeys=function(e){return this._doFetch("getKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getIAMKeys=function(e){return this._doFetch("getIAMKeys",e).then(function(e){return o(e,["accessKey","secretKey","sessionToken","consoleURL"])})},t.prototype.getAllAWSRoleTypes=function(e){var t=e.getDynamicValues?"allAwsRoleTypes?getDynamicValues=true":"allAwsRoleTypes";return this._doFetch(t,e,"GET").then(function(e){return e.roleTypes})},t.prototype.getAWSRoleTypes=function(e){return this._doFetch("getAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.getNonServiceAWSRoleTypes=function(e){return this._doFetch("getNonServiceAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.createRole=function(e){return this._doFetch("createRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.createNonServiceRole=function(e){return this._doFetch("createNonServiceRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),o(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.awsAccountRoles=function(e){return this._doFetch("awsAccountRoles?account="+e.account,e,"GET").then(function(e){return e.awsRoleList})},t.prototype.listAWSAccountRoles=function(e){return this._doFetch("listAWSAccountRoles",e).then(function(e){return JSON.parse(e.jsonAWSRoleList).map(function(e){return e.split("/").slice(-1)[0]})})},t.prototype.getAccountRole=function(t){return this._doFetch("getAccountRole",t).then(function(e){if(!e.roleExists)throw new Error("Role "+t.roleName+" does not exist in this account");return e.roleARN})},t.prototype.deleteRole=function(e){return this._doFetch("deleteRole",e).then(function(){return!0})},t.prototype.addRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e).then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.deleteRoleMachineIdentity=function(e){return this._doFetch("roleMachineIdentity",e,"DELETE").then(function(e){return o(e,["machineIdentityArn"])})},t.prototype.getUserAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/"+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserAccessByRole=function(e){var t=e.accountId;return this._doFetch("reports/users-by-role?accountId="+t,e,"GET").then(function(e){return e.users})},t.prototype.getUserRoleAccess=function(e){var t=e.accountId;return this._doFetch("userAccess/roles/"+t,e).then(function(e){return e.roles})},t.prototype.getAccountOwners=function(e){var t=e.accountId;return this._doFetch("userAccess/owners/"+t,e,"GET").then(function(e){return e.accountOwners})},t.prototype.createAccessKeys=function(e){return this._doFetch("accessKeys",e).then(function(e){return o(e,["iamUserArn","accessKey","secretKey","addedIAMUserToGroup"])})},t.prototype.deleteIAMUser=function(e){return this._doFetch("IAMUser",e,"DELETE").then(function(){return!0})},t.prototype.version=function(e){return this._doFetch("version",e,"GET").then(function(e){return o(e,["version"])})},t.prototype.getLoginRole=function(e){var t=e.accountId,n=e.role;return this._doFetch("loginRoles/id/"+t+"/"+n,null).then(function(e){return o(e,["account","role","iamKeyActive","maxKeyDuration"])})},t.prototype.getAccessToken=function(e){return this._doFetch("accessToken",e).then(function(e){return o(e,["accessToken","expiresIn"])})},t.prototype.getRefreshTokens=function(e){return this._doFetch("refreshTokens",e,"GET").then(function(e){return e.refreshTokens.map(function(e){return o(e,["clientId","id","userId","value"])})})},t.prototype.revoke=function(e){return this._doFetch("revoke",e).then(function(e){return"Success"==e.statusMessage})},t.prototype._doFetch=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n="POST");var o=Object.assign({},this.defaults,t),r={"Content-Type":"application/json","User-Agent":"AlksJS/1.11.3"};if(o.accessToken&&(r.Authorization="Bearer "+o.accessToken,delete o.accessToken),o.userid||o.password){console.error("The userid and password properties are deprecated and should be replaced with an access token");var s=this._base64Encode(o.userid+":"+o.password);r.Authorization="Basic "+s,delete o.userid,delete o.password}o.accessKey&&(r["ALKS-STS-Access-Key"]=o.accessKey,delete o.accessKey),o.secretKey&&(r["ALKS-STS-Secret-Key"]=o.secretKey,delete o.secretKey),o.sessionToken&&(r["ALKS-STS-Session-Token"]=o.sessionToken,delete o.sessionToken);var c=o._fetch(o.baseUrl+"/"+e,{method:n,headers:r,body:"GET"==n?void 0:JSON.stringify(o)}),i=c.then(function(e){return e.json()}).catch(function(){});return Promise.all([c,i]).then(function(e){var t=e[0],n=e[1];if(!t.ok)throw new u(t,n);return n})};var o=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})},u=function(r){function e(e,t){var n=Array.isArray(t.errors)?t.errors:[];e.statusText&&n.unshift(e.statusText);var o=n.join("; ");r.call(this,o),this.status=e.status,this.message=o,Object.assign(this,t)}return r&&(e.__proto__=r),(e.prototype=Object.create(r&&r.prototype)).constructor=e}(Error);return new t}); diff --git a/dist/alks.umd.js b/dist/alks.umd.js index 9d321bf1..0422c4d1 100644 --- a/dist/alks.umd.js +++ b/dist/alks.umd.js @@ -4,7 +4,7 @@ (global = global || self, global.alks = factory()); }(this, function () { 'use strict'; - var version = "1.11.2"; + var version = "1.11.3"; var fetch = window.fetch.bind(window); @@ -227,7 +227,7 @@ * }) */ alks.prototype.getAllAWSRoleTypes = function getAllAWSRoleTypes (props) { - var url = props.getDynamicValues ? 'allAwsRoleTypes' : 'allAwsRoleTypes?getDynamicValues=true'; + var url = props.getDynamicValues ? 'allAwsRoleTypes?getDynamicValues=true' : 'allAwsRoleTypes'; return(this._doFetch(url, props, 'GET').then(function (results) { return results.roleTypes; })) }; @@ -829,7 +829,7 @@ delete opts.sessionToken; } - var responsePromise = opts._fetch(((opts.baseUrl) + "/" + path + "/"), { + var responsePromise = opts._fetch(((opts.baseUrl) + "/" + path), { method: method, headers: headers, body: method == 'GET' ? undefined : JSON.stringify(opts) }); diff --git a/src/alks.js b/src/alks.js index aba80097..1af7ee8f 100755 --- a/src/alks.js +++ b/src/alks.js @@ -834,7 +834,7 @@ class alks { delete opts.sessionToken } - var responsePromise = opts._fetch(`${opts.baseUrl}/${path}/`, { + var responsePromise = opts._fetch(`${opts.baseUrl}/${path}`, { method, headers, body: method == 'GET' ? undefined : JSON.stringify(opts) }) diff --git a/test/test.js b/test/test.js index 9e0844a3..4c4b2763 100755 --- a/test/test.js +++ b/test/test.js @@ -13,7 +13,7 @@ describe('alks.js', function() { describe('getAccounts', () => { it('should return a list of accounts', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccounts/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccounts', { body: { statusMessage: 'Success', accountListRole: { @@ -63,7 +63,7 @@ describe('alks.js', function() { }) it('should return an access key, secret key, session token and console URL', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { accessKey: 'foo', secretKey: 'bar', sessionToken: 'baz', consoleURL: 'https://foo.com', statusMessage: 'Success'}, status: 200 }) @@ -84,7 +84,7 @@ describe('alks.js', function() { const userid = 'joebob123' const password = 'letmein' const base64Credentials = 'am9lYm9iMTIzOmxldG1laW4=' // Base64(username:password) - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { accessKey: 'foo', secretKey: 'bar', sessionToken: 'baz', statusMessage: 'Success'}, status: 200 }) @@ -103,7 +103,7 @@ describe('alks.js', function() { }) it('should send the library version via the User-Agent header', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { accessKey: 'foo', secretKey: 'bar', sessionToken: 'baz', statusMessage: 'Success'}, status: 200 }) @@ -121,7 +121,7 @@ describe('alks.js', function() { }) it('rejects on error with ALKS statusMessage', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { statusMessage: 'this is the statusMessage' }, status: 401 }) @@ -143,7 +143,7 @@ describe('alks.js', function() { }) it('rejects on error with errors array', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { errors: ['this is an error'], statusMessage: null }, status: 401 }) @@ -165,7 +165,7 @@ describe('alks.js', function() { }) it('handles a server error', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { status: 500 }) + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { status: 500 }) const result = alks.getKeys({ baseUrl: 'https://your.alks-host.com', @@ -184,7 +184,7 @@ describe('alks.js', function() { }) it('warns of userid/password deprecation', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { accessKey: 'foo', secretKey: 'bar', sessionToken: 'baz', statusMessage: 'Success'}, status: 200 }) @@ -206,7 +206,7 @@ describe('alks.js', function() { describe('getIAMKeys', () => { it('should return an access key, secret key, session token and console URL', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getIAMKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getIAMKeys', { body: { accessKey: 'foo', secretKey: 'bar', sessionToken: 'baz', consoleURL: 'https://foo.com', statusMessage: 'Success' }, status: 200 }) @@ -263,7 +263,7 @@ describe('alks.js', function() { }, ] - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/allAwsRoleTypes/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/allAwsRoleTypes', { body: { statusMessage: 'Success', requestId: 'reqId', @@ -280,12 +280,54 @@ describe('alks.js', function() { expect(result).to.have.deep.members(roleTypes) }) + + it('should return a list of role types with template fields when the getDynamicValues query param is passed', async () => { + const roleTypes = [ + { + roleTypeName: 'AWS Lambda', + defaultArns: ['0'], + templateVariables: [ + 'ABC', + ], + trustRelationship: { + Version: '2012-10-17', + Statement: [ + { + Action: 'sts:AssumeRole', + Effect: 'Allow', + Principal: { + Service: 'lambda' + } + } + ] + } + }, + ] + + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/allAwsRoleTypes?getDynamicValues=true', { + body: { + statusMessage: 'Success', + requestId: 'reqId', + roleTypes: roleTypes + }, + status: 200 + }) + + const result = await alks.getAllAWSRoleTypes({ + baseUrl: 'https://your.alks-host.com', + accessToken: 'abc123', + getDynamicValues: true, + _fetch + }) + + expect(result).to.have.deep.members(roleTypes) + }) }) describe('getAWSRoleTypes', () => { it('should return a list of role types', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAWSRoleTypes/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAWSRoleTypes', { body: { roleTypes: '["AWS Lambda", "Amazon EC2"]', statusMessage: 'Success'}, status: 200 }) @@ -303,7 +345,7 @@ describe('alks.js', function() { describe('getNonServiceAWSRoleTypes', () => { it('should return a list of role types', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getNonServiceAWSRoleTypes/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getNonServiceAWSRoleTypes', { body: { roleTypes: '["AWS Lambda", "Amazon EC2"]', statusMessage: 'Success'}, status: 200 }) @@ -321,7 +363,7 @@ describe('alks.js', function() { describe('getAccountRole', () => { it('should return the ARN of the account role', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccountRole/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccountRole', { body: { roleARN: 'arn:aws:iam::12391238912383:role/acct-managed/awsRoleName', roleExists: true, @@ -343,7 +385,7 @@ describe('alks.js', function() { }) it('should reject with an error message when the role is not found', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccountRole/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccountRole', { body: { roleARN: null, roleExists: false, statusMessage: 'Success' }, status: 200 }) @@ -364,7 +406,7 @@ describe('alks.js', function() { describe('createRole', () => { it('should return information about the newly created role', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/createRole/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/createRole', { body: { roleArn: 'aRoleArn', denyArns: 'denyArn1,denyArn2', @@ -398,7 +440,7 @@ describe('alks.js', function() { describe('createNonServiceRole', () => { it('should return information about the newly created role', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/createNonServiceRole/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/createNonServiceRole', { body: { roleArn: 'aRoleArn', denyArns: 'denyArn1,denyArn2', @@ -469,7 +511,7 @@ describe('alks.js', function() { } ] - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/awsAccountRoles?account=1234567890/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/awsAccountRoles?account=1234567890', { body: { statusMessage: 'Success', requestId: 'reqId', @@ -492,7 +534,7 @@ describe('alks.js', function() { describe('listAWSAccountRoles', () => { it('should return a list of aws roles', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/listAWSAccountRoles/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/listAWSAccountRoles', { body: { jsonAWSRoleList: '["arn:aws:iam::123:role/acct-managed/arn1","arn:aws:iam::123:role/acct-managed/arn2"]', statusMessage: null @@ -515,7 +557,7 @@ describe('alks.js', function() { describe('deleteRole', () => { it('should return true when successful', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/deleteRole/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/deleteRole', { body: { statusMessage: 'Success' }, status: 200 }) @@ -536,7 +578,7 @@ describe('alks.js', function() { describe('createAccessKeys', () => { it('should return keys and information about the keys', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/accessKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/accessKeys', { body: { iamUserArn: 'anIAMUserArn', accessKey: 'foo', secretKey: 'bar', addedIAMUserToGroup: true }, status: 200 }) @@ -562,7 +604,7 @@ describe('alks.js', function() { describe('deleteIAMUser', () => { it('should return true if successful', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/IAMUser/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/IAMUser', { body: { statusMessage: 'Success' }, status: 200 }, { method: 'DELETE' }) @@ -583,7 +625,7 @@ describe('alks.js', function() { describe('create', () => { it('should return a functional alks object', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getKeys', { body: { accessKey: 'foo', secretKey: 'bar', sessionToken: 'baz', statusMessage: 'Success' }, status: 200 }) @@ -604,7 +646,7 @@ describe('alks.js', function() { }) it('should return a functional alks object without requiring any optional properties', async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccounts/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/getAccounts', { body: { statusMessage: 'Success', accountListRole: { @@ -641,7 +683,7 @@ describe('alks.js', function() { it(`should return ALKS's version`, async () => { - const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/version/', { + const _fetch = fetchMock.sandbox().mock('https://your.alks-host.com/version', { body: { version: '1.2.3.4' }, @@ -672,7 +714,7 @@ describe('alks.js', function() { const iamKeyActive = true const maxKeyDuration = 12 - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/loginRoles/id/${accountId}/${role}/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/loginRoles/id/${accountId}/${role}`, { body: { account, role, @@ -709,7 +751,7 @@ describe('alks.js', function() { const accessToken = 'abcde12345' const expiresIn = 3600 - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/accessToken/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/accessToken`, { body: { accessToken, expiresIn @@ -751,7 +793,7 @@ describe('alks.js', function() { } ] - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/refreshTokens/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/refreshTokens`, { body: { refreshTokens }, @@ -776,7 +818,7 @@ describe('alks.js', function() { const baseUrl = 'https://your.alks-host.com' const tokenId = '01234' - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/revoke/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/revoke`, { body: { statusMessage: 'Success' }, @@ -801,7 +843,7 @@ describe('alks.js', function() { const baseUrl = 'https://your.alks-host.com' const roleARN = 'arn:aws:iam::123:role/acct-managed/awsRoleName' - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/roleMachineIdentity/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/roleMachineIdentity`, { body: { machineIdentityArn: 'arn:aws:iam::123:role/acct-managed/awsRoleName' }, @@ -826,7 +868,7 @@ describe('alks.js', function() { const baseUrl = 'https://your.alks-host.com' const roleARN = 'arn:aws:iam::123:role/acct-managed/awsRoleName' - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/roleMachineIdentity/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/roleMachineIdentity`, { body: { machineIdentityArn: 'arn:aws:iam::123:role/acct-managed/awsRoleName' }, @@ -851,7 +893,7 @@ describe('alks.js', function() { const baseUrl = 'https://your.alks-host.com' const accountId = '012345678910' - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/userAccess/${accountId}/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/userAccess/${accountId}`, { body: { users: [] }, @@ -876,7 +918,7 @@ describe('alks.js', function() { const baseUrl = 'https://your.alks-host.com' const accountId = '012345678910' - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/reports/users-by-role?accountId=${accountId}/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/reports/users-by-role?accountId=${accountId}`, { body: { users: { 'Admin': [] @@ -909,7 +951,7 @@ describe('alks.js', function() { 'LabAdmin' ] - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/userAccess/roles/${accountId}/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/userAccess/roles/${accountId}`, { body: { sAMAccountName: 'bob1', roles: roles @@ -943,7 +985,7 @@ describe('alks.js', function() { title: 'CEO' } - const _fetch = fetchMock.sandbox().mock(`${baseUrl}/userAccess/owners/${accountId}/`, { + const _fetch = fetchMock.sandbox().mock(`${baseUrl}/userAccess/owners/${accountId}`, { body: { accountOwners: [ dummyOwner