diff --git a/internal/cli/login.go b/internal/cli/login.go index c3286c3de..e1824ab4c 100644 --- a/internal/cli/login.go +++ b/internal/cli/login.go @@ -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 } @@ -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 } diff --git a/internal/cli/login_test.go b/internal/cli/login_test.go index d4b8a48fa..870bb4cda 100644 --- a/internal/cli/login_test.go +++ b/internal/cli/login_test.go @@ -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() @@ -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") }) @@ -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.") })