Skip to content

Commit

Permalink
Return a better error if an api key is not configured (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-stripe committed Sep 17, 2019
1 parent 526f51b commit 98385f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/validators/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func CallNonEmpty(validator ArgValidator, value string) error {

// APIKey validates that a string looks like an API key.
func APIKey(input string) error {
if len(input) < 12 {
return errors.New("API key is too short, must be at least 12 characters long")
if len(input) == 0 {
return errors.New("you have not configured API keys yet. To do so, run `stripe login` which will configure your API keys from Stripe")
} else if len(input) < 12 {
return errors.New("the API key provided is too short, it must be at least 12 characters long")
}

keyParts := strings.Split(input, "_")
Expand Down
10 changes: 10 additions & 0 deletions pkg/validators/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
"github.com/stretchr/testify/require"
)

func TestNoKey(t *testing.T) {
err := APIKey("")
require.EqualError(t, err, "you have not configured API keys yet. To do so, run `stripe login` which will configure your API keys from Stripe")
}

func TestKeyTooShort(t *testing.T) {
err := APIKey("123")
require.EqualError(t, err, "the API key provided is too short, it must be at least 12 characters long")
}

func TestLegacyAPIKeys(t *testing.T) {
err := APIKey("sk_123457890abcdef")
require.EqualError(t, err, "you are using a legacy-style API key which is unsupported by the CLI. Please generate a new test mode API key")
Expand Down

0 comments on commit 98385f9

Please sign in to comment.