-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package gumroad | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
@@ -14,6 +15,8 @@ import ( | |
"time" | ||
) | ||
|
||
const license = "DEADBEEF-CAFE1234-5678DEAD-BEEFCAFE" | ||
|
||
func TestIntegrationInvalidLicense(t *testing.T) { | ||
t.Parallel() | ||
expected := "license: invalid license: That license does not exist for the provided product." | ||
|
@@ -71,6 +74,47 @@ func TestErrors(t *testing.T) { | |
} | ||
} | ||
|
||
func Test5xx(t *testing.T) { | ||
t.Parallel() | ||
|
||
calls := 0 | ||
|
||
// server will stand in for GumRoad, and assume that any license it sees is invalid | ||
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
calls++ | ||
t.Log("try", calls) | ||
if calls == 3 { | ||
bts, _ := json.Marshal(GumroadResponse{ | ||
Success: true, | ||
Purchase: Purchase{ | ||
SaleTimestamp: time.Now(), | ||
Email: "[email protected]", | ||
}, | ||
}) | ||
_, _ = w.Write(bts) | ||
return | ||
} | ||
w.WriteHeader(http.StatusInternalServerError) | ||
_, _ = w.Write([]byte(`some error`)) | ||
})) | ||
t.Cleanup(server.Close) | ||
|
||
p, err := NewProduct("product") | ||
if err != nil { | ||
t.Errorf("unexpected error %v", err) | ||
} | ||
p.API = server.URL | ||
p.Client = server.Client() | ||
|
||
err = p.Verify(license) | ||
if err != nil { | ||
t.Fatal("expected no error") | ||
} | ||
if calls != 3 { | ||
t.Errorf("should have called the api 3 times, but called %d", calls) | ||
} | ||
} | ||
|
||
func TestMITM(t *testing.T) { | ||
t.Parallel() | ||
license := "DEADBEEF-CAFE1234-5678DEAD-BEEFCAFE" | ||
|
@@ -136,7 +180,7 @@ func TestMITM(t *testing.T) { | |
})) | ||
t.Cleanup(mitm.Close) | ||
// Throw away the log message from http.Server.go complaining about the invalid TLS cert | ||
mitm.Config.ErrorLog = log.New(ioutil.Discard, "", 0) | ||
mitm.Config.ErrorLog = log.New(io.Discard, "", 0) | ||
|
||
p.API = mitm.URL | ||
// Set the client back to the default, which doesn't trust the test certificate used by mitm | ||
|