Skip to content

Commit

Permalink
Fixed linitng issues
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Jul 29, 2024
1 parent cbd9031 commit f5d40d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
8 changes: 4 additions & 4 deletions internal/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func loginCmd(cli *cli) *cobra.Command {
}
}

//If additional scopes are passed we mark shouldLoginAsUser flag to be true
// If additional scopes are passed we mark shouldLoginAsUser flag to be true.
if inputs.isLoggingInWithAdditionalScopes() {
shouldLoginAsUser = true
}
Expand Down Expand Up @@ -209,16 +209,16 @@ func ensureAuth0URL(input string) (string, error) {
input = strings.TrimPrefix(input, "https://")
input = strings.TrimSuffix(input, "/api/v2")

// Check if the input ends with auth0.com
// Check if the input ends with auth0.com .
if !strings.HasSuffix(input, "auth0.com") {
return "", fmt.Errorf("not a valid auth0.com domain")
}

// Extract the domain part without any path
// Extract the domain part without any path.
domainParts := strings.Split(input, "/")
domain := domainParts[0]

// Return the formatted URL
// Return the formatted URL.
return fmt.Sprintf("https://%s/api/v2/", domain), nil
}

Expand Down
14 changes: 2 additions & 12 deletions internal/cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package cli

import (
"bytes"
"github.com/auth0/auth0-cli/internal/display"
"testing"

"github.com/auth0/auth0-cli/internal/display"

"github.com/stretchr/testify/assert"
)

func TestLoginCommand(t *testing.T) {
t.Run("Negative Test: it returns an error since client-id, client-secret and domain must be passed together", func(t *testing.T) {

cli := &cli{}
cli.noInput = true

cmd := loginCmd(cli)
cmd.SetArgs([]string{"--client-id", "t3dbMFeTokYBguVu1Ty88gqntUXELSn9"})
err := cmd.Execute()
Expand All @@ -24,44 +23,36 @@ func TestLoginCommand(t *testing.T) {
t.Run("Negative Test: it returns an error since client-id, client-secret and domain must be passed together", func(t *testing.T) {
cli := &cli{}
cli.noInput = true

cmd := loginCmd(cli)
cmd.SetArgs([]string{"--client-secret", "3OAzE7j2HTnGOPeCRFX3Hg-0sipaEnodzQK8xpwsRiTkqdjjwEFT04rgCjfslianfs"})
err := cmd.Execute()

assert.EqualError(t, err, "flags client-id, client-secret and domain are required together")
})

t.Run("Negative Test: it returns an error since client-id, client-secret and domain must be passed together", func(t *testing.T) {
cli := &cli{}
cli.noInput = true

cmd := loginCmd(cli)
cmd.SetArgs([]string{"--client-id", "t3dbMFeTokYBguVu1Ty88gqntUXELSn9", "--client-secret", "3OAzE7j2HTnGOPeCRFX3Hg-0sipaEnodzQK8xpkqdjjwEFT0EFT04rgCp4PZL4Z"})
err := cmd.Execute()

assert.EqualError(t, err, "flags client-id, client-secret and domain are required together")
})

t.Run("Negative Test: it returns an error since client-id, client-secret and domain must be passed together", func(t *testing.T) {
cli := &cli{}
cli.noInput = true

cmd := loginCmd(cli)
cmd.SetArgs([]string{"--client-id", "t3dbMFeTokYBguVu1Ty88gqntUXELSn9", "--domain", "duedares.us.auth0.com"})
err := cmd.Execute()

assert.EqualError(t, err, "flags client-id, client-secret and domain are required together")
})

t.Run("Negative Test: it returns an error since client-id, client-secret and domain must be passed together", func(t *testing.T) {
cli := &cli{}
cli.noInput = true

cmd := loginCmd(cli)
cmd.SetArgs([]string{"--client-secret", "3OAzE7j2HTnGOPeCRFX3Hg-0sipaEnodzQK8xpkqdjjwEFT0EFT04rgCp4PZL4Z", "--domain", "duedares.us.auth0.com"})
err := cmd.Execute()

assert.EqualError(t, err, "flags client-id, client-secret and domain are required together")
})

Expand All @@ -79,7 +70,6 @@ func TestLoginCommand(t *testing.T) {
cmd := loginCmd(cli)
cmd.SetArgs([]string{"--client-id", "t3dbMFeTokYBguVu1Ty88gqntUXELSn9", "--client-secret", "3OAzE7j2HTnGOPeCRFX3Hg-0sipaEnodzQK8xpwsRiTkqdjjwEFT04rgCp4PZL4Z", "--domain", "duedares.us.auth0.com"})
err := cmd.Execute()

assert.NoError(t, err)
assert.Contains(t, message.String(), "Successfully logged in.")
})
Expand Down

0 comments on commit f5d40d2

Please sign in to comment.