Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-140: integration tests on ci #263

Merged
merged 34 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
eda57a2
chore: initial try at workflow change
as-herzog Apr 23, 2021
c057136
chore: add env vars
as-herzog Apr 23, 2021
0b33221
chore: remove path
as-herzog Apr 23, 2021
a8b99b8
chore: add mocks
as-herzog Apr 23, 2021
5b04287
chore: try build before integration
as-herzog Apr 26, 2021
5267a1d
chore: revert
as-herzog Apr 26, 2021
5452a69
chore: build all platforms
as-herzog Apr 26, 2021
6ce685e
test: fix
as-herzog Apr 26, 2021
46c0731
test: run with verbose
as-herzog Apr 26, 2021
8d9d409
Merge branch 'main' into cli-140-integration-on-ci
as-herzog Apr 26, 2021
16384bd
test: skipped
as-herzog Apr 26, 2021
54b319c
Merge branch 'main' into cli-140-integration-on-ci
Widcket Apr 27, 2021
7736d2d
test: remove verbose
as-herzog Apr 30, 2021
e6b3aa2
chore: Merge branch 'cli-140-integration-on-ci' of github.com:auth0/a…
as-herzog Apr 30, 2021
946d02a
test: echo path
as-herzog Apr 30, 2021
ca0c543
test: add verbose flag back
as-herzog Apr 30, 2021
c2e8fbb
test: build before integration
as-herzog May 3, 2021
4ca5642
test: try bash
as-herzog May 3, 2021
977317d
test: switch order
as-herzog May 3, 2021
1e4a362
test: remove redundant build
as-herzog May 3, 2021
2dcb9f2
test: add to path
as-herzog May 3, 2021
1621e67
Merge branch 'main' into cli-140-integration-on-ci
as-herzog May 3, 2021
70a768b
fix: config generator include scopes
jfatta May 7, 2021
5e0632e
Merge branch 'main' into cli-140-integration-on-ci
jfatta May 7, 2021
46b13a0
fix makefile
jfatta May 7, 2021
74697e1
fix: config gen tenant name
jfatta May 7, 2021
268c5a9
fix: config generated token
jfatta May 7, 2021
0c5e51b
test: remove verbose
as-herzog May 7, 2021
b76d343
test: failure
as-herzog May 7, 2021
a650818
fix: revert fialure
as-herzog May 7, 2021
cac083a
test: cleanup even with failure
as-herzog May 7, 2021
f2f54ba
test: use bash
as-herzog May 7, 2021
c2400f1
test: cleanup
as-herzog May 7, 2021
c55da52
fix: test
as-herzog May 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ jobs:

- name: ci
run: PATH=$(go env GOPATH)/bin:$PATH make ci

- name: integration
# skip running this action if the PR is coming from a fork:
if: github.event.pull_request.head.repo.full_name == github.repository
shell: bash
run: PATH=$(go env GOPATH)/bin:$PATH make integration
env:
AUTH0_CLI_CLIENT_NAME: ${{ secrets.AUTH0_CLI_CLIENT_NAME }}
AUTH0_CLI_CLIENT_DOMAIN: ${{ secrets.AUTH0_CLI_CLIENT_DOMAIN }}
AUTH0_CLI_CLIENT_ID: ${{ secrets.AUTH0_CLI_CLIENT_ID }}
AUTH0_CLI_CLIENT_SECRET: ${{ secrets.AUTH0_CLI_CLIENT_SECRET }}
AUTH0_CLI_REUSE_CONFIG: ${{ secrets.AUTH0_CLI_REUSE_CONFIG }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need AUTH0_CLI_REUSE_CONFIG on the secrets. It should be always false on CI if understood the code correctly; there's no config file to reuse here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we tweak the CLI codebase to look for all those ENV vars and skip the config file completely if the vars are present?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, we don't want to support client id/secret auth mechanism on the code base. In any case, it could look for an ENV var with the access token and skip config file, but that has nothing to do with this PR.

AUTH0_CLI_OVERWRITE: ${{ secrets.AUTH0_CLI_OVERWRITE }}
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ lint:

# Build for the native platform
build:
go build -ldflags "$(CTIMEVAR)" -o auth0 cmd/auth0/main.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. bad resolved merge conflict I guess 🤦🏼

.PHONY: build

# Build for the native platform
build:
go build -ldflags "$(CTIMEVAR)" -o $(GOBIN)/auth0 cmd/auth0/main.go
.PHONY: build

# Build a beta version of auth0-cli for all supported platforms
Expand Down Expand Up @@ -78,5 +74,9 @@ integration-cleanup:
./integration/test-cleanup.sh
.PHONY: integration-cleanup

integration: $(GOBIN)/auth0-cli-config-generator $(GOBIN)/commander run-integration integration-cleanup
integration: build $(GOBIN)/auth0-cli-config-generator $(GOBIN)/commander
$(MAKE) run-integration; \
ret=$$?; \
$(MAKE) integration-cleanup; \
exit $$ret
.PHONY: integration
3 changes: 2 additions & 1 deletion integration/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ for app in $( echo "${apps}" | jq -r '.[] | @base64' ); do

clientid=$(_jq '.ClientID')
name=$(_jq '.Name')

# TODO(jfatta): should remove only those
# created during the same test session
if [[ $name = integration-test-* ]]
then
echo deleting "$name"
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] --description <descriptio
if err := ansi.Waiting(func() error {
return cli.api.Client.Create(a)
}); err != nil {
return fmt.Errorf("Unable to create application: %w", err)
return fmt.Errorf("Unable to create application: %v", err)
}

if err := cli.setDefaultAppID(a.GetClientID()); err != nil {
Expand Down
48 changes: 33 additions & 15 deletions pkg/auth0-cli-config-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"time"

"github.com/lestrrat-go/jwx/jwt"
Expand All @@ -21,17 +22,23 @@ import (

type params struct {
filePath string
clientName string
clientDomain string
clientID string
clientSecret string
}

func (p params) validate() error {
if p.clientName == "" {
return fmt.Errorf("Missing client name")
}
var requiredScopes = []string{
// "openid",
// "offline_access", // <-- to get a refresh token.
"create:clients", "delete:clients", "read:clients", "update:clients",
"create:resource_servers", "delete:resource_servers", "read:resource_servers", "update:resource_servers",
"create:rules", "delete:rules", "read:rules", "update:rules",
"read:users", "update:users",
"read:branding", "update:branding",
"read:client_keys", "read:logs", "read:tenant_settings", "read:custom_domains",
}

func (p params) validate() error {
if p.clientDomain == "" {
return fmt.Errorf("Missing client domain")
}
Expand Down Expand Up @@ -65,6 +72,7 @@ type tenant struct {
Domain string `json:"domain"`
AccessToken string `json:"access_token,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
Scopes []string `json:"scopes,omitempty"`
}

func isLoggedIn(filePath string) bool {
Expand Down Expand Up @@ -133,7 +141,6 @@ func main() {
reuseConfig := viper.GetBool("REUSE_CONFIG")
overwrite := viper.GetBool("OVERWRITE")
filePath := viper.GetString("FILEPATH")
clientName := viper.GetString("CLIENT_NAME")
clientDomain := viper.GetString("CLIENT_DOMAIN")
clientID := viper.GetString("CLIENT_ID")
clientSecret := viper.GetString("CLIENT_SECRET")
Expand All @@ -146,7 +153,7 @@ func main() {
return nil
}

p := params{filePath, clientName, clientDomain, clientID, clientSecret}
p := params{filePath, clientDomain, clientID, clientSecret}
if err := p.validate(); err != nil {
return err
}
Expand All @@ -157,20 +164,33 @@ func main() {
}

c := &clientcredentials.Config{
ClientID: p.clientID,
ClientSecret: p.clientSecret,
TokenURL: u.String() + "/oauth/token",
EndpointParams: url.Values{"audience": {u.String() + "/api/v2/"}},
ClientID: p.clientID,
ClientSecret: p.clientSecret,
TokenURL: u.String() + "/oauth/token",
EndpointParams: url.Values{
"client_id": {p.clientID},
"scope": {strings.Join(requiredScopes, " ")},
"audience": {u.String() + "/api/v2/"},
},
}

token, err := c.Token(context.Background())
if err != nil {
return err
}

t := tenant{p.clientName, p.clientDomain, token.AccessToken, token.Expiry}
t := tenant{
Name: p.clientDomain,
Domain: p.clientDomain,
AccessToken: token.AccessToken,
ExpiresAt: token.Expiry,
Scopes: append([]string{"openid", "offline_access"}, requiredScopes...),
}

cfg := config{p.clientName, map[string]tenant{p.clientName: t}}
cfg := config{
DefaultTenant: p.clientDomain,
Tenants: map[string]tenant{p.clientDomain: t},
}
if err := persistConfig(p.filePath, cfg, overwrite); err != nil {
return err
}
Expand All @@ -185,8 +205,6 @@ func main() {
flags := cmd.Flags()
flags.String("filepath", path.Join(os.Getenv("HOME"), ".config", "auth0", "config.json"), "Filepath for the auth0 cli config")
_ = viper.BindPFlag("FILEPATH", flags.Lookup("filepath"))
flags.String("client-name", "", "Client name to set within config")
_ = viper.BindPFlag("CLIENT_NAME", flags.Lookup("client-name"))
flags.String("client-id", "", "Client ID to set within config")
_ = viper.BindPFlag("CLIENT_ID", flags.Lookup("client-id"))
flags.String("client-secret", "", "Client secret to use to generate token which is set within config")
Expand Down