Skip to content

Commit bda30ae

Browse files
committed
Fix validation for Gumroad licenses
Fixes an issue where JWT license validation caused Gumroad tokens to fail validation. Fixes: #137 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent add7da2 commit bda30ae

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ func (c InletsProConfig) GetLicenseKey() (string, error) {
5050
return "", fmt.Errorf("--license or --license-key is required for inlets PRO")
5151
}
5252

53-
if total := strings.Count(val, "."); total >= 2 {
53+
if dots := strings.Count(val, "."); dots >= 2 {
5454
return strings.TrimSpace(val), nil
5555
}
5656

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

config_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func Test_GetLicenseKey_FromFile(t *testing.T) {
5353
}
5454
}
5555

56-
func Test_GetLicenseKey_FromFileTrimsWhitespace(t *testing.T) {
56+
func Test_GetLicenseKey_FromFileTrimsWhitespace_JWT(t *testing.T) {
5757
want := `static.key.text`
5858

5959
tmp := os.TempDir()
@@ -84,3 +84,20 @@ func Test_GetLicenseKey_FromFileTrimsWhitespace(t *testing.T) {
8484
t.Fatalf("want %q but got %q", want, key)
8585
}
8686
}
87+
88+
func Test_GetLicenseKey_FromLiteral_WithDashes(t *testing.T) {
89+
want := `static-dashes-key-text`
90+
91+
c := InletsProConfig{
92+
License: want,
93+
}
94+
95+
key, err := c.GetLicenseKey()
96+
if err != nil {
97+
t.Fatalf("no error wanted for a valid key")
98+
}
99+
100+
if want != key {
101+
t.Fatalf("want %q but got %q", want, key)
102+
}
103+
}

0 commit comments

Comments
 (0)