forked from okta/okta-sdk-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled e2e tests, added script that will clean test resources in org…
… after tests finished. OKTA-352089 <<<Jenkins Check-In of Tested SHA: 8c38267 for [email protected]>>> Artifact: okta-sdk-nodejs
- Loading branch information
1 parent
45753aa
commit 06a4d8e
Showing
4 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const okta = require('../'); | ||
const utils = require('./utils'); | ||
|
||
let orgUrl = process.env.OKTA_CLIENT_ORGURL; | ||
|
||
if (process.env.OKTA_USE_MOCK) { | ||
orgUrl = `${orgUrl}/application-get-user`; | ||
} | ||
|
||
const client = new okta.Client({ | ||
scopes: ['okta.apps.manage', 'okta.users.manage'], | ||
orgUrl: orgUrl, | ||
token: process.env.OKTA_CLIENT_TOKEN, | ||
requestExecutor: new okta.DefaultRequestExecutor() | ||
}); | ||
|
||
describe('Clean all test resources', () => { | ||
|
||
cleanAuthorizationServers(); | ||
|
||
cleanTestUsers(); | ||
|
||
cleanTestGroups(); | ||
|
||
cleanApplications(); | ||
|
||
cleanInlineHooks(); | ||
|
||
}); | ||
|
||
async function cleanInlineHooks(){ | ||
const collection = await client.listInlineHooks(); | ||
collection.each(async (inlineHook) => { | ||
|
||
await inlineHook.deactivate(); | ||
await inlineHook.delete(); | ||
}) | ||
} | ||
|
||
|
||
function cleanAuthorizationServers() { | ||
client.listAuthorizationServers().each( | ||
authorizationServer => { | ||
authorizationServer.delete(); | ||
} | ||
); | ||
} | ||
|
||
function cleanApplications() { | ||
client.listApplications().each(application =>{ | ||
(application.label === 'Node SDK Service App' || application.label === 'Bacon Service Client') ? | ||
console.log(`Skipped application to remove ${application.label}`) : | ||
utils.removeAppByLabel(client, application.label) | ||
}); | ||
} | ||
|
||
function cleanTestUsers() { | ||
client.listUsers().each(user => { | ||
(user.profile.email.endsWith('okta.com')) ? | ||
console.log(`Skipped user to remove ${user.profile.email}`) : | ||
utils.deleteUser(user) | ||
}); | ||
} | ||
|
||
function cleanTestGroups() { | ||
const url = `${client.baseUrl}/api/v1/groups`; | ||
const request = { | ||
method: 'get', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
} | ||
}; | ||
|
||
return client.http.http(url, request) | ||
.then(responce => responce.text()) | ||
.then(bodyResponce => JSON.parse(bodyResponce)) | ||
.then(user => { | ||
user.forEach(element =>{ | ||
(element.profile.name === 'Everyone') ? | ||
console.log(`Skipped group to remove ${element.profile.name}`) : | ||
utils.cleanupGroup(client, element) | ||
}); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} |