From 4e01489d66e859f653a18426805febe6ac74afa3 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 19:23:44 -0300 Subject: [PATCH 01/10] Add rules integration tests --- commander.yaml | 68 ++++++++++++++++++++++++++ integration/fixtures/rules-create.json | 12 +++++ integration/get-rule-id.sh | 8 +++ 3 files changed, 88 insertions(+) create mode 100644 integration/fixtures/rules-create.json create mode 100755 integration/get-rule-id.sh diff --git a/commander.yaml b/commander.yaml index 80081f11c..b2fcf139f 100644 --- a/commander.yaml +++ b/commander.yaml @@ -502,3 +502,71 @@ 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 + exit-code: 0 + stdout: + json: + name: integration-test-rule-new1 + enabled: "true" + order: "1" + + 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 false + - ORDER 2 + 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: integration-test-rule + order: "3" + exit-code: 0 + + rules show: + command: auth0 rules show $(cat ./integration/identifiers/rule-id) + stdout: + contains: + - NAME integration-test-rule-newRule + - ENABLED integration-test-rule + - 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" + description: betterDescription + exit-code: 0 diff --git a/integration/fixtures/rules-create.json b/integration/fixtures/rules-create.json new file mode 100644 index 000000000..f10078e98 --- /dev/null +++ b/integration/fixtures/rules-create.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 From 681a1439a0faae76ff899f46e9bb534aa025d764 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 19:32:45 -0300 Subject: [PATCH 02/10] Fix tests --- commander.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/commander.yaml b/commander.yaml index b2fcf139f..c6ad0411d 100644 --- a/commander.yaml +++ b/commander.yaml @@ -532,8 +532,8 @@ tests: stdout: json: name: integration-test-rule-newRule - enabled: integration-test-rule - order: "3" + enabled: "false" + order: "1" exit-code: 0 rules show: @@ -541,8 +541,8 @@ tests: stdout: contains: - NAME integration-test-rule-newRule - - ENABLED integration-test-rule - - ORDER 3 + - ENABLED ✓ + - ORDER 1 exit-code: 0 # Test 'rules update' @@ -568,5 +568,4 @@ tests: stdout: json: enabled: "false" - description: betterDescription exit-code: 0 From 022a4c79c122898bc6d5749a5b55496c6cf5a858 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 19:41:49 -0300 Subject: [PATCH 03/10] Fix tests --- commander.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commander.yaml b/commander.yaml index c6ad0411d..e4ef0fc4e 100644 --- a/commander.yaml +++ b/commander.yaml @@ -505,7 +505,7 @@ tests: # Test 'rules create' rules create and check data: - command: cat integration/fixtures/create-rule.json | jq '.[0]' | auth0 rules create --format json + command: cat ./integration/fixtures/create-rule.json | jq '.[0]' | auth0 rules create --format json exit-code: 0 stdout: json: @@ -514,7 +514,7 @@ tests: order: "1" rules create and check output: - command: cat integration/fixtures/create-rule.json | jq '.[1]' | auth0 rules create + command: cat ./integration/fixtures/create-rule.json | jq '.[1]' | auth0 rules create stdout: contains: - NAME integration-test-rule-new2 @@ -533,7 +533,7 @@ tests: json: name: integration-test-rule-newRule enabled: "false" - order: "1" + order: "3" exit-code: 0 rules show: @@ -542,12 +542,12 @@ tests: contains: - NAME integration-test-rule-newRule - ENABLED ✓ - - ORDER 1 + - ORDER 3 exit-code: 0 # Test 'rules update' rules update: - command: cat integration/fixtures/update-rule.json | auth0 rules update --format json + command: cat ./integration/fixtures/update-rule.json | auth0 rules update --format json stdout: json: name: integration-test-rule-betterName From ea52961bd4d855932720080411c29632d7805e12 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 19:49:20 -0300 Subject: [PATCH 04/10] Rename file --- integration/fixtures/{rules-create.json => create-rule.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename integration/fixtures/{rules-create.json => create-rule.json} (100%) diff --git a/integration/fixtures/rules-create.json b/integration/fixtures/create-rule.json similarity index 100% rename from integration/fixtures/rules-create.json rename to integration/fixtures/create-rule.json From 23a8296216bf3325b3c742e39d84fab86c5751e9 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 19:57:25 -0300 Subject: [PATCH 05/10] Update command output --- commander.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commander.yaml b/commander.yaml index e4ef0fc4e..50abb30cf 100644 --- a/commander.yaml +++ b/commander.yaml @@ -512,14 +512,18 @@ tests: name: integration-test-rule-new1 enabled: "true" order: "1" + script: "function(user, context, cb) {\n cb(null, user, context);\n}\n" 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 false + - ENABLED ✗ - ORDER 2 + - SCRIPT function(user, context, cb) { + cb(null, user, context); + } exit-code: 0 # Test 'rules show' From 6d892e6d94f72695b834414e4808413b79321344 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 20:13:06 -0300 Subject: [PATCH 06/10] Fix exit code --- commander.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/commander.yaml b/commander.yaml index 50abb30cf..02ef480a9 100644 --- a/commander.yaml +++ b/commander.yaml @@ -506,13 +506,13 @@ tests: # Test 'rules create' rules create and check data: command: cat ./integration/fixtures/create-rule.json | jq '.[0]' | auth0 rules create --format json - exit-code: 0 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 @@ -522,8 +522,6 @@ tests: - ENABLED ✗ - ORDER 2 - SCRIPT function(user, context, cb) { - cb(null, user, context); - } exit-code: 0 # Test 'rules show' From 1aee7e19be0d35672be33aee6a0ca22e17ca345d Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 20:23:38 -0300 Subject: [PATCH 07/10] Fix enabled value --- commander.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commander.yaml b/commander.yaml index 02ef480a9..cdb71d75e 100644 --- a/commander.yaml +++ b/commander.yaml @@ -534,7 +534,7 @@ tests: stdout: json: name: integration-test-rule-newRule - enabled: "false" + enabled: "true" order: "3" exit-code: 0 From 3a252ebfe3404172536711ca075b9009c98d6e8f Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Tue, 27 Jul 2021 20:27:22 -0300 Subject: [PATCH 08/10] Add cleanup logic --- integration/test-cleanup.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index 9770bc878..320c70a21 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 rules 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 From f02b150bde9e6400dd0b953d88bd919b3e5820e7 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 30 Jul 2021 12:36:06 -0300 Subject: [PATCH 09/10] Move rules cleanup code above roles fro troubleshooting --- integration/test-cleanup.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index 320c70a21..3616c2df1 100755 --- a/integration/test-cleanup.sh +++ b/integration/test-cleanup.sh @@ -53,38 +53,38 @@ for user in $( echo "${users}" | jq -r '.[] | @base64' ); do fi done -roles=$( auth0 roles list --format json --no-input ) +rules=$( auth0 rules list --format json --no-input ) -for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do +for rules in $( echo "${rules}" | jq -r '.[] | @base64' ); do _jq() { - echo "${role}" | base64 --decode | jq -r "${1}" + 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-role-* ]] + if [[ $name = integration-test-rule-* ]] then echo deleting "$name" - $( auth0 roles delete "$id") + $( auth0 rules delete "$id") fi done -rules=$( auth0 rules list --format json --no-input ) +roles=$( auth0 roles list --format json --no-input ) -for rules in $( echo "${rules}" | jq -r '.[] | @base64' ); do +for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do _jq() { - echo "${rule}" | base64 --decode | jq -r "${1}" + 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-rule-* ]] + if [[ $name = integration-test-role-* ]] then echo deleting "$name" - $( auth0 rules delete "$id") + $( auth0 roles delete "$id") fi done From 2f80e7089ded61354c6f34e1024ffb1f46d44c4a Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 30 Jul 2021 12:50:03 -0300 Subject: [PATCH 10/10] Fix typo --- integration/test-cleanup.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index 3616c2df1..2d4192aff 100755 --- a/integration/test-cleanup.sh +++ b/integration/test-cleanup.sh @@ -53,38 +53,38 @@ for user in $( echo "${users}" | jq -r '.[] | @base64' ); do fi done -rules=$( auth0 rules list --format json --no-input ) +roles=$( auth0 roles list --format json --no-input ) -for rules in $( echo "${rules}" | jq -r '.[] | @base64' ); do +for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do _jq() { - echo "${rule}" | base64 --decode | jq -r "${1}" + 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-rule-* ]] + if [[ $name = integration-test-role-* ]] then echo deleting "$name" - $( auth0 rules delete "$id") + $( auth0 roles delete "$id") fi done -roles=$( auth0 roles list --format json --no-input ) +rules=$( auth0 rules list --format json --no-input ) -for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do +for rule in $( echo "${rules}" | jq -r '.[] | @base64' ); do _jq() { - echo "${role}" | base64 --decode | jq -r "${1}" + 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-role-* ]] + if [[ $name = integration-test-rule-* ]] then echo deleting "$name" - $( auth0 roles delete "$id") + $( auth0 rules delete "$id") fi done