aboutsummaryrefslogtreecommitdiff
path: root/pkg/stryder/stryder_test.go
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-11 23:42:49 -0400
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-11 23:42:49 -0400
commit89752de10dce921da2a50ad647ece8adbe28eae1 (patch)
tree942d728d2d94c64b79d9511f1e2c1ab338bdadd0 /pkg/stryder/stryder_test.go
parent25d1b93ee7aa562df436e3ad49afd0f5148161d6 (diff)
downloadAtlas-89752de10dce921da2a50ad647ece8adbe28eae1.tar.gz
Atlas-89752de10dce921da2a50ad647ece8adbe28eae1.zip
pkg/stryder: Implement stryder auth
Diffstat (limited to 'pkg/stryder/stryder_test.go')
-rw-r--r--pkg/stryder/stryder_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/stryder/stryder_test.go b/pkg/stryder/stryder_test.go
new file mode 100644
index 0000000..23ce717
--- /dev/null
+++ b/pkg/stryder/stryder_test.go
@@ -0,0 +1,42 @@
+package stryder
+
+import (
+ "bytes"
+ "errors"
+ "io"
+ "net/http"
+ "strings"
+ "testing"
+)
+
+func TestNucleusAuth(t *testing.T) {
+ testNucleusAuth(t, "Success", `{"token":"...","hasOnlineAccess":"1","expiry":"14399","storeUri":"https://www.origin.com/store/titanfall/titanfall-2/standard-edition"}`, nil)
+ testNucleusAuth(t, "NoMultiplayer", `{"token":"...","hasOnlineAccess":"0","expiry":"14399","storeUri":"https://www.origin.com/store/titanfall/titanfall-2/standard-edition"}`, ErrMultiplayerNotAllowed)
+ testNucleusAuth(t, "InvalidToken", `{"success": false, "status": "400", "error": "{"error":"invalid_grant","error_description":"code is invalid","code":100100}"}`, ErrInvalidToken)
+ testNucleusAuth(t, "StryderBadRequest", `{"success": false, "status": "400", "error": "{"error":"invalid_request","error_description":"code is not issued to this environment","code":100119}"}`, ErrStryder)
+ testNucleusAuth(t, "StryderBadEndpoint", ``, ErrStryder)
+ testNucleusAuth(t, "StryderGoAway", "Go away.\n", ErrStryder)
+ testNucleusAuth(t, "InvalidGame", `{"token":"...","hasOnlineAccess":"1","expiry":"1234","storeUri":"https://www.origin.com/store/titanfall/titanfall-3/future-edition"}`, ErrInvalidGame) // never seen this, but test it
+}
+
+func testNucleusAuth(t *testing.T, name, resp string, res error) {
+ t.Run(name, func(t *testing.T) {
+ buf, err := nucleusAuth(&http.Response{
+ Status: "200 OK",
+ StatusCode: 200,
+ Body: io.NopCloser(strings.NewReader(resp)),
+ })
+ if !bytes.Equal(buf, bytes.TrimSpace([]byte(resp))) {
+ t.Errorf("returned response %q doesn't match original response %q", string(buf), string(resp))
+ }
+ if res == nil {
+ if err != nil {
+ t.Errorf("unexpected error (resp %q): %v", resp, err)
+ }
+ } else {
+ if !errors.Is(err, res) {
+ t.Errorf("expected error %q, got %q", res, err)
+ }
+ }
+ })
+}