From 323c894d86988a3c397825a7061021b15f38e642 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Sat, 8 May 2021 15:09:39 -0300 Subject: [PATCH 1/8] Add APIs integration tests --- .gitignore | 3 +- commander.yaml | 203 ++++++++++++++++++++++++++++------- docs/ci.md | 2 +- integration/get-api-id.sh | 5 + integration/get-app-id.sh | 5 + integration/get-client-id.sh | 5 - integration/test-cleanup.sh | 22 +++- internal/cli/apis.go | 14 ++- 8 files changed, 204 insertions(+), 55 deletions(-) create mode 100755 integration/get-api-id.sh create mode 100755 integration/get-app-id.sh delete mode 100755 integration/get-client-id.sh diff --git a/.gitignore b/.gitignore index df6080f5b..73452f9b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # project artifacts /auth0 -integration/client-id +/integration/identifiers # Swap [._]*.s[a-v][a-z] @@ -26,4 +26,3 @@ tags # misc .vscode .DS_Store - diff --git a/commander.yaml b/commander.yaml index e06b9d63c..434067ed7 100644 --- a/commander.yaml +++ b/commander.yaml @@ -22,71 +22,71 @@ tests: # Test 'apps create' --type flag apps create type native and check data: - command: auth0 apps create --name integration-test-nativeapp1 --type native --description NativeApp1 --format json + command: auth0 apps create --name integration-test-app-nativeapp1 --type native --description NativeApp1 --format json exit-code: 0 stdout: json: - name: integration-test-nativeapp1 + name: integration-test-app-nativeapp1 description: NativeApp1 app_type: native apps create type native and check output: - command: auth0 apps create --name integration-test-nativeapp1 --type native --description NativeApp1 + command: auth0 apps create --name integration-test-app-nativeapp1 --type native --description NativeApp1 exit-code: 0 stdout: contains: - - NAME integration-test-nativeapp1 + - NAME integration-test-app-nativeapp1 - DESCRIPTION NativeApp1 - TYPE Native apps create type spa: - command: auth0 apps create --name integration-test-spaapp1 --type spa --description SpaApp1 --format json + command: auth0 apps create --name integration-test-app-spaapp1 --type spa --description SpaApp1 --format json exit-code: 0 stdout: json: - name: integration-test-spaapp1 + name: integration-test-app-spaapp1 description: SpaApp1 app_type: spa apps create type regular: - command: auth0 apps create --name integration-test-regapp1 --type regular --description RegApp1 --format json + command: auth0 apps create --name integration-test-app-regapp1 --type regular --description RegApp1 --format json exit-code: 0 stdout: json: - name: integration-test-regapp1 + name: integration-test-app-regapp1 description: RegApp1 app_type: regular_web apps create type m2m: - command: auth0 apps create --name integration-test-m2mapp1 --type m2m --description M2mApp1 --format json + command: auth0 apps create --name integration-test-app-m2mapp1 --type m2m --description M2mApp1 --format json exit-code: 0 stdout: json: - name: integration-test-m2mapp1 + name: integration-test-app-m2mapp1 description: M2mApp1 app_type: non_interactive # Test 'apps create' --auth-method flag apps create type spa auth method none: - command: auth0 apps create --name integration-test-spaapp2 --type spa --description SpaApp2 --auth-method None --format json + command: auth0 apps create --name integration-test-app-spaapp2 --type spa --description SpaApp2 --auth-method None --format json stdout: json: token_endpoint_auth_method: none exit-code: 0 apps create type m2m auth method none fails: - command: auth0 apps create --name integration-test-m2mapp2 --type m2m --description M2mApp2 --auth-method None + command: auth0 apps create --name integration-test-app-m2mapp2 --type m2m --description M2mApp2 --auth-method None exit-code: 1 apps create type regular auth method post: - command: auth0 apps create --name integration-test-regapp2 --type regular --description RegApp2 --auth-method Post --format json + command: auth0 apps create --name integration-test-app-regapp2 --type regular --description RegApp2 --auth-method Post --format json stdout: json: token_endpoint_auth_method: client_secret_post exit-code: 0 apps create type regular auth method basic: - command: auth0 apps create --name integration-test-regapp3 --type regular --description RegApp3 --auth-method Basic --format json + command: auth0 apps create --name integration-test-app-regapp3 --type regular --description RegApp3 --auth-method Basic --format json stdout: json: token_endpoint_auth_method: client_secret_basic @@ -94,14 +94,14 @@ tests: # Test 'apps create' --callbacks flag apps create type m2m callbacks: - command: auth0 apps create --name integration-test-m2mapp3 --type m2m --description M2mApp3 --callbacks https://example.com + command: auth0 apps create --name integration-test-app-m2mapp3 --type m2m --description M2mApp3 --callbacks https://example.com stdout: contains: - CALLBACKS https://example.com exit-code: 0 apps create type regular callbacks list: - command: auth0 apps create --name integration-test-regapp4 --type regular --description RegApp4 --callbacks https://example.com,https://google.com --format json + command: auth0 apps create --name integration-test-app-regapp4 --type regular --description RegApp4 --callbacks https://example.com,https://google.com --format json stdout: json: callbacks: "[https://example.com https://google.com]" @@ -109,33 +109,33 @@ tests: # Test 'apps create' --grants flag apps create type regular grants: - command: auth0 apps create --name integration-test-regapp5 --type regular --description RegApp4 --grants credentials,password + command: auth0 apps create --name integration-test-app-regapp5 --type regular --description RegApp4 --grants credentials,password stdout: contains: - GRANTS client_credentials, password exit-code: 0 apps create type spa grants: - command: auth0 apps create --name integration-test-spaapp3 --type spa --description SpaApp3 --grants refresh-token --format json + command: auth0 apps create --name integration-test-app-spaapp3 --type spa --description SpaApp3 --grants refresh-token --format json stdout: json: grant_types: "[refresh_token]" exit-code: 0 apps create type native grants: - command: auth0 apps create --name integration-test-nativeapp2 --type native --description NativeApp2 --grants refresh-token,code --format json + command: auth0 apps create --name integration-test-app-nativeapp2 --type native --description NativeApp2 --grants refresh-token,code --format json stdout: json: grant_types: "[refresh_token authorization_code]" exit-code: 0 apps create type m2m grants fails: - command: auth0 apps create --name integration-test-m2mapp4 --type m2m --description M2mApp4 --grants credentials,device-code + command: auth0 apps create --name integration-test-app-m2mapp4 --type m2m --description M2mApp4 --grants credentials,device-code exit-code: 1 # Test 'apps create' --logout-urls flag apps create type regular logout urls: - command: auth0 apps create --name integration-test-regapp6 --type native --description RegularApp --logout-urls https://*.example.com/logout,https://example.com/logout --format json + command: auth0 apps create --name integration-test-app-regapp6 --type native --description RegularApp --logout-urls https://*.example.com/logout,https://example.com/logout --format json stdout: json: allowed_logout_urls: "[https://*.example.com/logout https://example.com/logout]" @@ -143,7 +143,7 @@ tests: # Test 'apps create' --origins flag apps create type regular origins: - command: auth0 apps create --name integration-test-regapp7 --type native --description RegularApp --origins https://*.example.com,https://example.com --format json + command: auth0 apps create --name integration-test-app-regapp7 --type native --description RegularApp --origins https://*.example.com,https://example.com --format json stdout: json: allowed_origins: "[https://*.example.com https://example.com]" @@ -151,103 +151,226 @@ tests: # Test 'apps create' --web-origins flag apps create type native web origins: - command: auth0 apps create --name integration-test-spaapp4 --type native --description SpaApp4 --web-origins https://example.com --format json + command: auth0 apps create --name integration-test-app-spaapp4 --type native --description SpaApp4 --web-origins https://example.com --format json stdout: json: web_origins: "[https://example.com]" exit-code: 0 # Test 'apps show' - apps create test app: # create an app and capture a client id - command: ./integration/get-client-id.sh + apps create test app: # create an app and capture its client id + command: ./integration/get-app-id.sh exit-code: 0 apps show json: - command: auth0 apps show $(cat ./integration/client-id) --format json # depends on "apps create test app" test + command: auth0 apps show $(cat ./integration/identifiers/app-id) --format json # depends on "apps create test app" test stdout: json: - name: integration-test-newapp + name: integration-test-app-newapp description: NewApp app_type: native exit-code: 0 apps show: - command: auth0 apps show $(cat ./integration/client-id) # depends on "apps create test app" test + command: auth0 apps show $(cat ./integration/identifiers/app-id) # depends on "apps create test app" test stdout: contains: - - NAME integration-test-newapp + - NAME integration-test-app-newapp - DESCRIPTION NewApp - TYPE Native exit-code: 0 # Test 'apps update'; all tests depend on "apps create test app" test apps update auth method: - command: auth0 apps update $(cat ./integration/client-id) --auth-method Basic --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --auth-method Basic --format json stdout: json: token_endpoint_auth_method: client_secret_basic exit-code: 0 apps update callbacks: - command: auth0 apps update $(cat ./integration/client-id) --callbacks https://example.com --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --callbacks https://example.com --format json stdout: json: callbacks: "[https://example.com]" exit-code: 0 apps update description: - command: auth0 apps update $(cat ./integration/client-id) --description "A better description" --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --description "A better description" --format json stdout: json: description: A better description exit-code: 0 apps update grants: - command: auth0 apps update $(cat ./integration/client-id) --grants code --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --grants code --format json stdout: json: grant_types: "[authorization_code]" exit-code: 0 apps update logout urls: - command: auth0 apps update $(cat ./integration/client-id) --logout-urls https://example.com --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --logout-urls https://example.com --format json stdout: json: allowed_logout_urls: "[https://example.com]" exit-code: 0 apps update name: - command: auth0 apps update $(cat ./integration/client-id) --name integration-test-betterAppName --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --name integration-test-app-betterAppName --format json stdout: json: - name: integration-test-betterAppName + name: integration-test-app-betterAppName exit-code: 0 apps update origins: - command: auth0 apps update $(cat ./integration/client-id) --origins https://example.com --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --origins https://example.com --format json stdout: json: allowed_origins: "[https://example.com]" exit-code: 0 apps update type: - command: auth0 apps update $(cat ./integration/client-id) --type spa --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --type spa --format json stdout: json: app_type: spa exit-code: 0 apps update web origins: - command: auth0 apps update $(cat ./integration/client-id) --web-origins https://example.com --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --web-origins https://example.com --format json stdout: json: web_origins: "[https://example.com]" exit-code: 0 apps update multiple updates: - command: auth0 apps update $(cat ./integration/client-id) --web-origins https://examples.com --type native --format json + command: auth0 apps update $(cat ./integration/identifiers/app-id) --web-origins https://examples.com --type native --format json stdout: json: app_type: native web_origins: "[https://examples.com]" exit-code: 0 + + # Test 'apis create' + apis create and check data: + command: auth0 apis create --name integration-test-api-def1 --identifier http://integration-test-api-def1 --scopes read:todos,write:todos --format json + exit-code: 0 + stdout: + json: + name: integration-test-api-def1 + identifier: http://integration-test-api-def1 + scopes: "[map[value:read:todos] map[value:write:todos]]" + token_lifetime: "86400" + allow_offline_access: "false" + + apis create and check output: + command: auth0 apis create --name integration-test-api-def2 --identifier http://integration-test-api-def2 --scopes read:todos,write:todos + exit-code: 0 + stdout: + contains: + - NAME integration-test-api-def2 + - IDENTIFIER http://integration-test-api-def2 + - SCOPES read:todos write:todos + - TOKEN LIFETIME 86400 + - ALLOW OFFLINE ACCESS false + + # Test 'apis create' --token-lifetime flag + apis create token lifetime 1000 and check data: + command: auth0 apis create --name integration-test-api-toklif1 --identifier http://integration-test-api-toklif1 --scopes read:todos --token-lifetime 1000 --format json + exit-code: 0 + stdout: + json: + token_lifetime: "1000" + + apis create token lifetime 1000 and check output: + command: auth0 apis create --name integration-test-api-toklif2 --identifier http://integration-test-api-toklif2 --scopes read:todos --token-lifetime 1000 + exit-code: 0 + stdout: + contains: + - TOKEN LIFETIME 1000 + + # Test 'apis create' --offline-access flag + apis create offline access true and check data: + command: auth0 apis create --name integration-test-api-offacc1 --identifier http://integration-test-api-offacc1 --scopes read:todos --offline-access --format json + exit-code: 0 + stdout: + json: + allow_offline_access: "true" + + apis create offline access true and check output: + command: auth0 apis create --name integration-test-api-offacc2 --identifier http://integration-test-api-offacc2 --scopes read:todos --offline-access + exit-code: 0 + stdout: + contains: + - ALLOW OFFLINE ACCESS true + + apis create offline access false and check data: + command: auth0 apis create --name integration-test-api-offacc3 --identifier http://integration-test-api-offacc3 --scopes read:todos --offline-access=false --format json + exit-code: 0 + stdout: + json: + allow_offline_access: "false" + + # Test 'apps show' + apis create test api: # create an api and capture its id + command: ./integration/get-api-id.sh + exit-code: 0 + + apis show json: + command: auth0 apis show $(cat ./integration/identifiers/api-id) --format json # depends on "apps create test app" test + stdout: + json: + name: integration-test-api-newapi + identifier: http://integration-test-api-newapi + scopes: "[map[value:read:todos]]" + token_lifetime: "86400" + allow_offline_access: "false" + exit-code: 0 + + apis show: + command: auth0 apis show $(cat ./integration/identifiers/api-id) # depends on "apps create test app" test + stdout: + contains: + - NAME integration-test-api-newapi + - IDENTIFIER http://integration-test-api-newapi + - SCOPES read:todos + - TOKEN LIFETIME 86400 + - ALLOW OFFLINE ACCESS false + exit-code: 0 + + # Test 'apis update'; all tests depend on "apis create test api" test + apis update name: + command: auth0 apis update $(cat ./integration/identifiers/api-id) --name integration-test-api-betterApiName --format json + stdout: + json: + name: integration-test-api-betterApiName + exit-code: 0 + + apis update scopes: + command: auth0 apis update $(cat ./integration/identifiers/api-id) --scopes read:todos,write:todos --format json + stdout: + json: + scopes: "[map[value:read:todos] map[value:write:todos]]" + exit-code: 0 + + apis update token lifetime: + command: auth0 apis update $(cat ./integration/identifiers/api-id) --token-lifetime 1000 --format json + stdout: + json: + token_lifetime: "1000" + exit-code: 0 + + apis update offline access true: + command: auth0 apis update $(cat ./integration/identifiers/api-id) --offline-access --format json + stdout: + json: + allow_offline_access: "true" + exit-code: 0 + + apis update offline access false: + command: auth0 apis update $(cat ./integration/identifiers/api-id) --offline-access=false --format json + stdout: + json: + allow_offline_access: "false" + exit-code: 0 diff --git a/docs/ci.md b/docs/ci.md index c979ba1e6..c43353fa4 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -11,7 +11,7 @@ make integration `make integration` will then use [commander](https://github.com/commander-cli/commander) to run tests defined in [commander.yaml](./commander.yaml) -The apps created during integration tests will be cleaned afterwards by the script `integration/test-cleanup.sh`. Apps with the prefix `integration-test-` will be deleted. +The apps created during integration tests will be cleaned afterwards by the script `integration/test-cleanup.sh`. Apps with the prefix `integration-test-app-` will be deleted. To run integration tests as part of a CI pipeline, several environment variables need to be exported first. When these variables are set, `auth0-cli-config-generator` will generate a valid auth0-cli config file being retrieving a token for the client, removing the need to run `auth0 login`: ```bash diff --git a/integration/get-api-id.sh b/integration/get-api-id.sh new file mode 100755 index 000000000..7065d7ac2 --- /dev/null +++ b/integration/get-api-id.sh @@ -0,0 +1,5 @@ +#! /bin/bash + +api=$( auth0 apis create --name integration-test-api-newapi --identifier http://integration-test-api-newapi --scopes read:todos --format json --no-input ) + +echo "$api" | jq -r '.["id"]' > ./integration/identifiers/api-id diff --git a/integration/get-app-id.sh b/integration/get-app-id.sh new file mode 100755 index 000000000..3f83dacda --- /dev/null +++ b/integration/get-app-id.sh @@ -0,0 +1,5 @@ +#! /bin/bash + +app=$( auth0 apps create -n integration-test-app-newapp -t native --description NewApp --format json --no-input ) + +echo "$app" | jq -r '.["client_id"]' > ./integration/identifiers/app-id \ No newline at end of file diff --git a/integration/get-client-id.sh b/integration/get-client-id.sh deleted file mode 100755 index bdcf8d159..000000000 --- a/integration/get-client-id.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/bash - -app=$( auth0 apps create -n integration-test-newapp -t native --description NewApp --format json --no-input ) - -echo "$app" | jq -r '.["client_id"]' > ./integration/client-id diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index 691f62829..499b17be2 100755 --- a/integration/test-cleanup.sh +++ b/integration/test-cleanup.sh @@ -1,6 +1,6 @@ #! /bin/bash -apps=$( auth0 apps list --format json --no-input) +apps=$( auth0 apps list --format json --no-input ) for app in $( echo "${apps}" | jq -r '.[] | @base64' ); do _jq() { @@ -11,9 +11,27 @@ for app in $( echo "${apps}" | jq -r '.[] | @base64' ); do name=$(_jq '.Name') # TODO(jfatta): should remove only those # created during the same test session - if [[ $name = integration-test-* ]] + if [[ $name = integration-test-app-* ]] then echo deleting "$name" $( auth0 apps delete "$clientid") fi done + +apis=$( auth0 apis list --format json --no-input ) + +for api in $( echo "${apis}" | jq -r '.[] | @base64' ); do + _jq() { + echo "${api}" | 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-api-* ]] + then + echo deleting "$name" + $( auth0 apis delete "$id") + fi +done diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 1aa35cc8c..29dbc4b9d 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -185,8 +185,10 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, return err } - if err := apiScopes.AskMany(cmd, &inputs.Scopes, nil); err != nil { - return err + if !apiScopes.IsSet(cmd) { + if err := apiScopes.AskMany(cmd, &inputs.Scopes, nil); err != nil { + return err + } } if err := apiTokenLifetime.Ask(cmd, &inputs.TokenLifetime, auth0.String("86400")); err != nil { @@ -223,7 +225,7 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, apiIdentifier.RegisterString(cmd, &inputs.Identifier, "") apiScopes.RegisterStringSlice(cmd, &inputs.Scopes, nil) apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) - apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 0) + apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 86400) return cmd } @@ -271,8 +273,10 @@ auth0 apis update -n myapi -e 6100 --offline-access=true`, return err } - if err := apiScopes.AskManyU(cmd, &inputs.Scopes, nil); err != nil { - return err + if !apiScopes.IsSet(cmd) { + if err := apiScopes.AskManyU(cmd, &inputs.Scopes, nil); err != nil { + return err + } } currentTokenLifetime := strconv.Itoa(auth0.IntValue(current.TokenLifetime)) From 6bfba862e9adc2b55c420515d1e1ce6ed93caab5 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Sat, 8 May 2021 15:18:00 -0300 Subject: [PATCH 2/8] Add missing newline --- integration/get-app-id.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/get-app-id.sh b/integration/get-app-id.sh index 3f83dacda..4883ea3fa 100755 --- a/integration/get-app-id.sh +++ b/integration/get-app-id.sh @@ -2,4 +2,4 @@ app=$( auth0 apps create -n integration-test-app-newapp -t native --description NewApp --format json --no-input ) -echo "$app" | jq -r '.["client_id"]' > ./integration/identifiers/app-id \ No newline at end of file +echo "$app" | jq -r '.["client_id"]' > ./integration/identifiers/app-id From eb92c0dfeed3676480f59c9ce21f560fe3966093 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Sat, 8 May 2021 15:21:51 -0300 Subject: [PATCH 3/8] Add comments --- internal/cli/apis.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 29dbc4b9d..66a8e50e9 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -224,8 +224,8 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, apiName.RegisterString(cmd, &inputs.Name, "") apiIdentifier.RegisterString(cmd, &inputs.Identifier, "") apiScopes.RegisterStringSlice(cmd, &inputs.Scopes, nil) - apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) - apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 86400) + apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) // Needs default because it has Always Prompt set to true + apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 86400) // Needs default because it has Always Prompt set to true return cmd } From 0c3266108047594fc0c61872ca2efe172e8ebd92 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Sat, 8 May 2021 15:23:23 -0300 Subject: [PATCH 4/8] Correct comment --- internal/cli/apis.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 66a8e50e9..803e0a18f 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -224,8 +224,8 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, apiName.RegisterString(cmd, &inputs.Name, "") apiIdentifier.RegisterString(cmd, &inputs.Identifier, "") apiScopes.RegisterStringSlice(cmd, &inputs.Scopes, nil) - apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) // Needs default because it has Always Prompt set to true - apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 86400) // Needs default because it has Always Prompt set to true + apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) // Needs default because it's not required + apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 86400) // Needs default because it's not required return cmd } From de4f9f26a5ef8defd68c2d188891e84e0d73465f Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Sun, 9 May 2021 08:56:15 -0300 Subject: [PATCH 5/8] Add default value via a function --- internal/cli/apis.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 803e0a18f..4d0102019 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -191,7 +191,8 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, } } - if err := apiTokenLifetime.Ask(cmd, &inputs.TokenLifetime, auth0.String("86400")); err != nil { + defaultTokenLifetime := strconv.Itoa(apiDefaultTokenLifetime()) + if err := apiTokenLifetime.Ask(cmd, &inputs.TokenLifetime, &defaultTokenLifetime); err != nil { return err } @@ -210,6 +211,13 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, api.Scopes = apiScopesFor(inputs.Scopes) } + // Set token lifetime + if inputs.TokenLifetime <= 0 { + api.TokenLifetime = auth0.Int(apiDefaultTokenLifetime()) + } else { + api.TokenLifetime = auth0.Int(inputs.TokenLifetime) + } + if err := ansi.Waiting(func() error { return cli.api.ResourceServer.Create(api) }); err != nil { @@ -224,8 +232,8 @@ auth0 apis create -n myapi -e 6100 --offline-access=true`, apiName.RegisterString(cmd, &inputs.Name, "") apiIdentifier.RegisterString(cmd, &inputs.Identifier, "") apiScopes.RegisterStringSlice(cmd, &inputs.Scopes, nil) - apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) // Needs default because it's not required - apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 86400) // Needs default because it's not required + apiOfflineAccess.RegisterBool(cmd, &inputs.AllowOfflineAccess, false) + apiTokenLifetime.RegisterInt(cmd, &inputs.TokenLifetime, 0) return cmd } @@ -484,6 +492,10 @@ func apiScopesFor(scopes []string) []*management.ResourceServerScope { return models } +func apiDefaultTokenLifetime() int { + return 86400 +} + func (c *cli) apiPickerOptions() (pickerOptions, error) { list, err := c.api.ResourceServer.List() if err != nil { From 5ef2044727d3e9644d2e85122d52accf9470bafc Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Sun, 9 May 2021 09:27:37 -0300 Subject: [PATCH 6/8] Add mkdir -p --- integration/get-api-id.sh | 1 + integration/get-app-id.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/integration/get-api-id.sh b/integration/get-api-id.sh index 7065d7ac2..8a60dce47 100755 --- a/integration/get-api-id.sh +++ b/integration/get-api-id.sh @@ -2,4 +2,5 @@ api=$( auth0 apis create --name integration-test-api-newapi --identifier http://integration-test-api-newapi --scopes read:todos --format json --no-input ) +mkdir -p ./integration/identifiers echo "$api" | jq -r '.["id"]' > ./integration/identifiers/api-id diff --git a/integration/get-app-id.sh b/integration/get-app-id.sh index 4883ea3fa..d348c6485 100755 --- a/integration/get-app-id.sh +++ b/integration/get-app-id.sh @@ -2,4 +2,5 @@ app=$( auth0 apps create -n integration-test-app-newapp -t native --description NewApp --format json --no-input ) +mkdir -p ./integration/identifiers echo "$app" | jq -r '.["client_id"]' > ./integration/identifiers/app-id From 0ba3fe61c3ff057f3c334c6ea144cbc9fae3a3ed Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Mon, 10 May 2021 14:22:48 -0300 Subject: [PATCH 7/8] Update ci.md --- docs/ci.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ci.md b/docs/ci.md index c43353fa4..d54589427 100644 --- a/docs/ci.md +++ b/docs/ci.md @@ -11,7 +11,7 @@ make integration `make integration` will then use [commander](https://github.com/commander-cli/commander) to run tests defined in [commander.yaml](./commander.yaml) -The apps created during integration tests will be cleaned afterwards by the script `integration/test-cleanup.sh`. Apps with the prefix `integration-test-app-` will be deleted. +The entities created during integration tests will be cleaned afterwards by the script `integration/test-cleanup.sh`. All the entities prefixed `integration-test-` will be deleted. To run integration tests as part of a CI pipeline, several environment variables need to be exported first. When these variables are set, `auth0-cli-config-generator` will generate a valid auth0-cli config file being retrieving a token for the client, removing the need to run `auth0 login`: ```bash From 232d3678763880ad96bdea141fcdd8779c82b818 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Mon, 10 May 2021 14:26:18 -0300 Subject: [PATCH 8/8] Fix typos --- commander.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commander.yaml b/commander.yaml index 434067ed7..2c96c66ce 100644 --- a/commander.yaml +++ b/commander.yaml @@ -318,7 +318,7 @@ tests: exit-code: 0 apis show json: - command: auth0 apis show $(cat ./integration/identifiers/api-id) --format json # depends on "apps create test app" test + command: auth0 apis show $(cat ./integration/identifiers/api-id) --format json # depends on "apis create test app" test stdout: json: name: integration-test-api-newapi @@ -329,7 +329,7 @@ tests: exit-code: 0 apis show: - command: auth0 apis show $(cat ./integration/identifiers/api-id) # depends on "apps create test app" test + command: auth0 apis show $(cat ./integration/identifiers/api-id) # depends on "apis create test app" test stdout: contains: - NAME integration-test-api-newapi