Skip to content

Commit

Permalink
Fix validation for Gumroad licenses
Browse files Browse the repository at this point in the history
Fixes an issue where JWT license validation caused Gumroad
tokens to fail validation.

Fixes: #137

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Jul 31, 2021
1 parent add7da2 commit bda30ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ func (c InletsProConfig) GetLicenseKey() (string, error) {
return "", fmt.Errorf("--license or --license-key is required for inlets PRO")
}

if total := strings.Count(val, "."); total >= 2 {
if dots := strings.Count(val, "."); dots >= 2 {
return strings.TrimSpace(val), nil
}

return "", fmt.Errorf("inlets PRO license may be invalid")
if dashes := strings.Count(val, "-"); dashes == 3 {
return strings.TrimSpace(val), nil
}

return "", fmt.Errorf("inlets license may be invalid")
}
19 changes: 18 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Test_GetLicenseKey_FromFile(t *testing.T) {
}
}

func Test_GetLicenseKey_FromFileTrimsWhitespace(t *testing.T) {
func Test_GetLicenseKey_FromFileTrimsWhitespace_JWT(t *testing.T) {
want := `static.key.text`

tmp := os.TempDir()
Expand Down Expand Up @@ -84,3 +84,20 @@ func Test_GetLicenseKey_FromFileTrimsWhitespace(t *testing.T) {
t.Fatalf("want %q but got %q", want, key)
}
}

func Test_GetLicenseKey_FromLiteral_WithDashes(t *testing.T) {
want := `static-dashes-key-text`

c := InletsProConfig{
License: want,
}

key, err := c.GetLicenseKey()
if err != nil {
t.Fatalf("no error wanted for a valid key")
}

if want != key {
t.Fatalf("want %q but got %q", want, key)
}
}

0 comments on commit bda30ae

Please sign in to comment.