Skip to content

Commit

Permalink
Enabled e2e tests, added script that will clean test resources in org…
Browse files Browse the repository at this point in the history
… after tests finished.

OKTA-352089
<<<Jenkins Check-In of Tested SHA: 8c38267 for [email protected]>>>
Artifact: okta-sdk-nodejs
  • Loading branch information
KostiantynDrozd-okta authored and eng-prod-CI-bot-okta committed Feb 19, 2021
1 parent 45753aa commit 06a4d8e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 10 deletions.
14 changes: 7 additions & 7 deletions .bacon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ test_suites:
script_name: unit
criteria: MERGE
queue_name: small
# - name: e2e
# script_path: /root/okta/okta-sdk-nodejs/scripts
# sort_order: '1'
# timeout: '10'
# script_name: e2e
# criteria: MERGE
# queue_name: small
- name: e2e
script_path: /root/okta/okta-sdk-nodejs/scripts
sort_order: '1'
timeout: '20'
script_name: e2e
criteria: MERGE
queue_name: small
- name: publish
script_path: /root/okta/okta-sdk-nodejs/scripts
sort_order: '2'
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"predocs": "rimraf ./jsdocs && mkdir jsdocs/ && ./utils/make-jsdoc-readme.js > ./jsdocs/jsdoc-temp.md",
"docs": "./node_modules/.bin/jsdoc src/ -c ./docs/config.json -d ./jsdocs/ -P ./package.json -R ./jsdocs/jsdoc-temp.md -r",
"test:integration": "yarn test:integration:oauth && yarn test:integration:ssws",
"test:integration:ssws": "MOCHA_FILE=./test-reports/it-results.xml OKTA_CLIENT_AUTHORIZATIONMODE=SSWS nyc --reporter=text --reporter=html mocha --reporter=mocha-junit-reporter test/it/*.js --no-timeouts",
"test:integration:ssws": "MOCHA_FILE=./test-reports/it-results.xml OKTA_CLIENT_AUTHORIZATIONMODE=SSWS nyc --reporter=text --reporter=html mocha --reporter=mocha-junit-reporter --reporter-options toConsole=true --retries 2 test/it/*.js --no-timeouts",
"test:integration:oauth": "OKTA_CLIENT_AUTHORIZATIONMODE=PrivateKey nyc --reporter=text --reporter=html mocha test/it/user-get.js --no-timeouts",
"test:unit": "MOCHA_FILE=./test-reports/junit-results.xml nyc --reporter=text --reporter=html mocha --reporter=mocha-junit-reporter test/unit/*.js --no-timeouts",
"test": "npm run eslint && npm run test:unit && npm run test:integration && npm run jest"
"test": "npm run eslint && npm run test:unit && npm run test:integration && npm run jest",
"aftertest": "mocha test/delete-resources.js --no-timeouts"
},
"keywords": [],
"license": "Apache-2.0",
Expand Down
5 changes: 4 additions & 1 deletion scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source ${OKTA_HOME}/${REPO}/scripts/setup.sh
aws s3 --quiet --region us-east-1 cp s3://ci-secret-stash/prod/okta-sdk-nodejs/privateKey.pem ${OKTA_HOME}/${REPO}/scripts/privateKey.pem

export OKTA_CLIENT_ORGURL=https://node-sdk.okta.com
export OKTA_CLIENT_TOKEN="$(aws s3 --quiet --region us-east-1 cp s3://ci-secret-stash/prod/okta-sdk-nodejs/apiKey /dev/stdout)"
get_secret prod/devex/okta-sdk-nodejs_apiKey OKTA_CLIENT_TOKEN
export OKTA_CLIENT_CLIENTID=0oa1jnkiuz6FCTchz4x7
export OKTA_CLIENT_PRIVATEKEY=$(cat ${OKTA_HOME}/${REPO}/scripts/privateKey.pem)

Expand All @@ -14,9 +14,12 @@ export TEST_RESULT_FILE_DIR="${REPO}/test-reports"

if ! yarn test:integration; then
echo "Integration tests failed! Exiting..."
yarn aftertest
exit ${PUBLISH_TYPE_AND_RESULT_DIR_BUT_ALWAYS_FAIL}
fi

yarn aftertest

ls -al ${OKTA_HOME}/${REPO}/test-reports

echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE}
Expand Down
88 changes: 88 additions & 0 deletions test/delete-resources.js
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);
});
}

0 comments on commit 06a4d8e

Please sign in to comment.