From 7f578d80257bde52edd687b92b029f98780b2646 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 30 Jul 2021 12:54:16 -0300 Subject: [PATCH] Add rule integration tests [CLI-163] (#340) * Add rules integration tests * Fix tests * Fix tests * Rename file * Update command output * Fix exit code * Fix enabled value * Add cleanup logic * Move rules cleanup code above roles fro troubleshooting * Fix typo --- commander.yaml | 69 +++++++++++++++++++++++++++ integration/fixtures/create-rule.json | 12 +++++ integration/get-rule-id.sh | 8 ++++ integration/test-cleanup.sh | 18 +++++++ 4 files changed, 107 insertions(+) create mode 100644 integration/fixtures/create-rule.json create mode 100755 integration/get-rule-id.sh diff --git a/commander.yaml b/commander.yaml index 80081f11c..cdb71d75e 100644 --- a/commander.yaml +++ b/commander.yaml @@ -502,3 +502,72 @@ tests: json: description: betterDescription exit-code: 0 + + # Test 'rules create' + rules create and check data: + command: cat ./integration/fixtures/create-rule.json | jq '.[0]' | auth0 rules create --format json + stdout: + json: + name: integration-test-rule-new1 + enabled: "true" + order: "1" + script: "function(user, context, cb) {\n cb(null, user, context);\n}\n" + exit-code: 0 + + rules create and check output: + command: cat ./integration/fixtures/create-rule.json | jq '.[1]' | auth0 rules create + stdout: + contains: + - NAME integration-test-rule-new2 + - ENABLED ✗ + - ORDER 2 + - SCRIPT function(user, context, cb) { + exit-code: 0 + + # Test 'rules show' + rules create test rule: + command: ./integration/get-rule-id.sh + exit-code: 0 + + rules show json: + command: auth0 rules show $(cat ./integration/identifiers/rule-id) --format json + stdout: + json: + name: integration-test-rule-newRule + enabled: "true" + order: "3" + exit-code: 0 + + rules show: + command: auth0 rules show $(cat ./integration/identifiers/rule-id) + stdout: + contains: + - NAME integration-test-rule-newRule + - ENABLED ✓ + - ORDER 3 + exit-code: 0 + + # Test 'rules update' + rules update: + command: cat ./integration/fixtures/update-rule.json | auth0 rules update --format json + stdout: + json: + name: integration-test-rule-betterName + enabled: "false" + exit-code: 0 + + # Test 'rules enable' + rules enable: + command: auth0 rules enable $(cat ./integration/identifiers/rule-id) --format json + stdout: + json: + enabled: "true" + exit-code: 0 + + # Test 'rules disable' + rules disable: + command: auth0 rules disable $(cat ./integration/identifiers/rule-id) --format json + stdout: + json: + enabled: "false" + exit-code: 0 diff --git a/integration/fixtures/create-rule.json b/integration/fixtures/create-rule.json new file mode 100644 index 000000000..f10078e98 --- /dev/null +++ b/integration/fixtures/create-rule.json @@ -0,0 +1,12 @@ +[ + { + "name": "integration-test-rule-new1", + "script": "function(user, context, cb) {\n cb(null, user, context);\n}\n", + "enabled": true + }, + { + "name": "integration-test-rule-new2", + "script": "function(user, context, cb) {\n cb(null, user, context);\n}\n", + "enabled": false + } +] \ No newline at end of file diff --git a/integration/get-rule-id.sh b/integration/get-rule-id.sh new file mode 100755 index 000000000..9738699d4 --- /dev/null +++ b/integration/get-rule-id.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +json='{"name":"integration-test-rule-newRule","script":"function(user, context, cb) {\n cb(null, user, context);\n}\n","enabled":false}' +rule=$( echo "$json" | auth0 rules create --format json ) + +mkdir -p ./integration/identifiers +echo "$rule" | jq -r '.["id"]' > ./integration/identifiers/rule-id +echo "$rule" | jq '.name = "integration-test-rule-betterName"' | jq '.enabled = false' > ./integration/fixtures/update-rule.json diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index 9770bc878..2d4192aff 100755 --- a/integration/test-cleanup.sh +++ b/integration/test-cleanup.sh @@ -70,3 +70,21 @@ for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do $( auth0 roles delete "$id") fi done + +rules=$( auth0 rules list --format json --no-input ) + +for rule in $( echo "${rules}" | jq -r '.[] | @base64' ); do + _jq() { + echo "${rule}" | 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-rule-* ]] + then + echo deleting "$name" + $( auth0 rules delete "$id") + fi +done