From 383439d06213b10f2c1c36dc228e7308ef3f936d Mon Sep 17 00:00:00 2001 From: bright-poku <75628344+bright-poku@users.noreply.github.com> Date: Mon, 7 Jun 2021 20:01:19 -0400 Subject: [PATCH] [CLI-167] integration test for roles (#309) * [CLI-167] integration test for roles * Update integration/get-role-id.sh Co-authored-by: Rita Zerrizuela --- commander.yaml | 56 +++++++++++++++++++++++++++++++++++++ integration/get-role-id.sh | 6 ++++ integration/test-cleanup.sh | 18 ++++++++++++ 3 files changed, 80 insertions(+) create mode 100755 integration/get-role-id.sh diff --git a/commander.yaml b/commander.yaml index f0456f17a..e0b73ff81 100644 --- a/commander.yaml +++ b/commander.yaml @@ -14,6 +14,9 @@ tests: auth0 tenants list: exit-code: 0 + auth0 roles list: + exit-code: 0 + auth0 rules list: exit-code: 0 @@ -426,4 +429,57 @@ tests: stdout: json: Email: betteruser@example.com # Name is not being displayed, hence using email + exit-code: 0 + + # Test 'roles create' + roles create and check data: + command: auth0 roles create --name integration-test-role-new1 --description testRole --format json --no-input + exit-code: 0 + stdout: + json: + Name: integration-test-role-new1 + Description: testRole + + roles create and check output: + command: auth0 roles create --name integration-test-role-new2 --description testRole2 --no-input + stdout: + contains: + - NAME integration-test-role-new2 + - DESCRIPTION testRole2 + exit-code: 0 + + # Test 'roles show' + roles create test role: + command: ./integration/get-role-id.sh + exit-code: 0 + + roles show json: + command: auth0 roles show $(cat ./integration/identifiers/role-id) --format json + stdout: + json: + Name: integration-test-role-newRole + Description: integration-test-role + exit-code: 0 + + roles show: + command: auth0 roles show $(cat ./integration/identifiers/role-id) + stdout: + contains: + - NAME integration-test-role-newRole + - DESCRIPTION integration-test-role + exit-code: 0 + + # Test 'roles update' + roles update name: + command: auth0 roles update $(cat ./integration/identifiers/role-id) --name integration-test-role-betterName --format json + stdout: + json: + Name: integration-test-role-betterName + exit-code: 0 + + roles update description: + command: auth0 roles update $(cat ./integration/identifiers/role-id) --description betterDescription --format json + stdout: + json: + Description: betterDescription exit-code: 0 \ No newline at end of file diff --git a/integration/get-role-id.sh b/integration/get-role-id.sh new file mode 100755 index 000000000..743513e2e --- /dev/null +++ b/integration/get-role-id.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +role=$( auth0 roles create -n integration-test-role-newRole -d integration-test-role --format json --no-input ) + +mkdir -p ./integration/identifiers +echo "$role" | jq -r '.["ID"]' > ./integration/identifiers/role-id diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index d09dc2420..9d2d8ce16 100755 --- a/integration/test-cleanup.sh +++ b/integration/test-cleanup.sh @@ -51,4 +51,22 @@ for user in $( echo "${users}" | jq -r '.[] | @base64' ); do echo deleting "$userid" $( auth0 users delete "$userid") fi +done + +roles=$( auth0 roles list --format json --no-input ) + +for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do + _jq() { + echo "${role}" | base64 --decode | jq -r "${1}" + } + + id=$(_jq '.ID') + name=$(_jq '.Name') + # TODO(jfatta): should remove only those + # created during the same test session + if [[ $name = integration-test-role-* ]] + then + echo deleting "$name" + $( auth0 roles delete "$id") + fi done \ No newline at end of file