diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/Auth/AuthManagerTests.cs b/src/Packages/Passport/Tests/Runtime/Scripts/Auth/AuthManagerTests.cs index d6e2903f..cc3e24a2 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/Auth/AuthManagerTests.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/Auth/AuthManagerTests.cs @@ -22,22 +22,22 @@ public class AuthManagerTests internal const string ACCESS_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9." + "eyJlbWFpbCI6ImRvbWluaWMubXVycmF5QGltbXV0YWJsZS5jb20iLCJvcmciOiJhNTdiMWYzZC1mYTU3LTRiNzgtODZkYy05ZDEyZDM1YjlhNj" + "giLCJldGhlcl9rZXkiOiIweGRlMDYzYmViNmNmNDhlNGMxOTcxYzc3N2M0OGY0NTU3MTA1MjU5ZWMiLCJzdGFya19rZXkiOiIweGM1NTYxZGU3" + - "Nzg4NTUxOTY0ZWQxMjI0Yzc2ZjQ5ZDk5ZmVjODkyOGQ1OWVkNTcwZTExZGIwYzk3ZGYwMTFmIiwidXNlcl9hZG1pbl9rZXkiOiIweGY4MjY4OT" + - "I0MWU3NTM1YjYyNTgyMmI4M2I1OWMxZDM3ZWUwOTBiZGMiLCJpc3MiOiJodHRwczovL2F1dGguaW1tdXRhYmxlLmNvbS8iLCJzdWIiOiJlbWFp" + - "bHw2NDJiN2Q0YWI5N2IzYWMyNDg3NzBlNTEiLCJhdWQiOlsicGxhdGZvcm1fYXBpIiwiaHR0cHM6Ly9wcm9kLmltbXV0YWJsZS5hdXRoMGFwcC" + + "Nzg4NTUxOTY0ZWQxMjI0Yzc2ZjQ5ZDk5ZmVjODkyOGQ1OWVkNTcwZTExZGIwYzk3ZGYwMTFmIiwidXNlcl9hZG1pbl9rZXkiOiIweGY4MjY4OT" + + "I0MWU3NTM1YjYyNTgyMmI4M2I1OWMxZDM3ZWUwOTBiZGMiLCJpc3MiOiJodHRwczovL2F1dGguaW1tdXRhYmxlLmNvbS8iLCJzdWIiOiJlbWFp" + + "bHw2NDJiN2Q0YWI5N2IzYWMyNDg3NzBlNTEiLCJhdWQiOlsicGxhdGZvcm1fYXBpIiwiaHR0cHM6Ly9wcm9kLmltbXV0YWJsZS5hdXRoMGFwcC" + "5jb20vdXNlcmluZm8iXSwiaWF0IjoxNjg2ODg5MDgwLCJleHAiOjE2ODY5NzU0ODAsImF6cCI6IlpKTDdKdmV0Y0RGQk5EbGdSczVvSm94dUFV" + "VWw2dVFqIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCB0cmFuc2FjdCBvZmZsaW5lX2FjY2VzcyJ9.aqFem4Pp0k91YWdYuxBo1wfCr" + "YAHy1Y1zIqof2GMQXd_mwhGBkHotUlgFAsOIQmvO6lQG5m3cHLR9zlEsFJ_2AJuJg3NTNnF0dEx12H5hx24_aN4qDga8Q9KNDdGc3x4LAxv48P" + "H-P6OcdMnpWekCUPAI3zZ9qWC1YWU9HaouQuBJNbUV8ujyooFGOP4YzejQf2Uyxz9wmzDiMS-e70BSmY8IPRR2A3QjOEo7oI3enqM_jylfbDo8" + "BsDRouDbwbZrMeX-rcJ_HBY5iZEdagVpcvOmfZCaad55MI_WJcXHrDMzmLqck1fd15Oklo7fajQtiG0ByINxTmm9_0YnEy02w"; internal const string REFRESH_TOKEN = "v1.NOQCr0kkmy0Cky_Doia8VgJdclSKOOOrkicjZ4NFeabS5J7xNct-oRwO2H65ua0mPOhzWfIf8lhxlM1sIUBqLoc"; - internal const string ID_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9.eyJk" + + internal const string ID_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9.eyJk" + "ZXZlbG9wZXJfaHViIjp7ImFjdGl2YXRlZCI6dHJ1ZSwib3JnYW5pemF0aW9uIjp7ImlkIjoiYTU3YjFmM2QtZmE1Ny00Yjc4LTg2ZGMtOWQxMm" + - "QzNWI5YTY4In0sInJlc3BvbnNlSWQiOiI4MzhiangzOG1maG15cWs3bjgzOGJqeGZrMjdhZXQxMCIsInJlc3BvbnNlcyI6eyJmdW5kaW5nIjoi" + - "UHJlZmVyIG5vdCB0byBzYXkiLCJoYXZlTWludGVkTmZ0c0JlZm9yZSI6Ik5vIiwicGVvcGxlIjoiSnVzdCBtZSIsInByb2plY3RTdGFnZSI6Ik" + + "QzNWI5YTY4In0sInJlc3BvbnNlSWQiOiI4MzhiangzOG1maG15cWs3bjgzOGJqeGZrMjdhZXQxMCIsInJlc3BvbnNlcyI6eyJmdW5kaW5nIjoi" + + "UHJlZmVyIG5vdCB0byBzYXkiLCJoYXZlTWludGVkTmZ0c0JlZm9yZSI6Ik5vIiwicGVvcGxlIjoiSnVzdCBtZSIsInByb2plY3RTdGFnZSI6Ik" + "NvbmNlcHQiLCJwcm9qZWN0VHlwZSI6Ik90aGVyIiwicm9sZSI6Ik90aGVyIn0sInJvbGVzIjpbXSwidXNlck1ldGFkYXRhIjp7InJlY2VpdmVN" + - "YXJrZXRpbmdFbWFpbHNDb25zZW50Ijp7ImNvbnNlbnRlZCI6ZmFsc2UsImRhdGUiOiIyMDIzLTA0LTIwVDAxOjA2OjI2LjgwOFoiLCJ2ZXJzaW" + - "9uIjoxfX19LCJwYXNzcG9ydCI6eyJldGhlcl9rZXkiOiIweGRlMDYzYmViNmNmNDhlNGMxOTcxYzc3N2M0OGY0NTU3MTA1MjU5ZWMiLCJzdGFy" + + "YXJrZXRpbmdFbWFpbHNDb25zZW50Ijp7ImNvbnNlbnRlZCI6ZmFsc2UsImRhdGUiOiIyMDIzLTA0LTIwVDAxOjA2OjI2LjgwOFoiLCJ2ZXJzaW" + + "9uIjoxfX19LCJwYXNzcG9ydCI6eyJldGhlcl9rZXkiOiIweGRlMDYzYmViNmNmNDhlNGMxOTcxYzc3N2M0OGY0NTU3MTA1MjU5ZWMiLCJzdGFy" + "a19rZXkiOiIweGM1NTYxZGU3Nzg4NTUxOTY0ZWQxMjI0Yzc2ZjQ5ZDk5ZmVjODkyOGQ1OWVkNTcwZTExZGIwYzk3ZGYwMTFmIiwidXNlcl9hZG" + "1pbl9rZXkiOiIweGY4MjY4OTI0MWU3NTM1YjYyNTgyMmI4M2I1OWMxZDM3ZWUwOTBiZGMifSwibmlja25hbWUiOiJkb21pbmljLm11cnJheSIs" + "Im5hbWUiOiJkb21pbmljLm11cnJheUBpbW11dGFibGUuY29tIiwicGljdHVyZSI6Imh0dHBzOi8vcy5ncmF2YXRhci5jb20vYXZhdGFyL2NkOT" + @@ -58,25 +58,27 @@ public class AuthManagerTests #pragma warning disable CS8618 private AuthManager manager; private MockHttpMessageHandler httpMock; - private MockCredentialsManager credentialsManager; + private MockCredentialsManager credentialsManager; #pragma warning restore CS8618 - - [SetUp] + + [SetUp] public void Init() - { + { httpMock = new MockHttpMessageHandler(); credentialsManager = new MockCredentialsManager(); manager = new AuthManager(httpMock.ToHttpClient(), credentialsManager); } - private async void PrepareForConfirmCode() { + private async void PrepareForConfirmCode() + { credentialsManager.hasValidCredentials = false; credentialsManager.token = null; AddDeviceCodeResponse(); _ = await manager.Login(); } - private void AddDeviceCodeResponse() { + private void AddDeviceCodeResponse() + { var deviceCodeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@$"{{""{KEY_DEVICE_CODE}"": ""{DEVICE_CODE}"",""user_code"": ""{USER_CODE}""," + @@ -134,8 +136,8 @@ public async Task Login_Success_UsingRefreshToken() Assert.AreEqual(request.Method, HttpMethod.Post); string stringContent = await request.Content.ReadAsStringAsync(); Assert.True(stringContent.Contains($"{KEY_REFRESH_TOKEN}={REFRESH_TOKEN}")); - } - + } + [Test] public async Task Login_Failed_GetDeviceCode() { @@ -144,9 +146,12 @@ public async Task Login_Failed_GetDeviceCode() var deviceCodeResponse = new HttpResponseMessage(HttpStatusCode.NotAcceptable); httpMock.Responses.Add(deviceCodeResponse); Exception? e = null; - try { + try + { var result = await manager.Login(); - } catch (Exception exception) { + } + catch (Exception exception) + { e = exception; } Assert.NotNull(e); @@ -225,9 +230,12 @@ public async Task ConfirmCode_Failed_PendingAndExpired() Assert.Null(manager.GetUser()); Exception? e = null; - try { + try + { var result = await manager.ConfirmCode(); - } catch (Exception exception) { + } + catch (Exception exception) + { e = exception; Debug.Log("Exception: " + e); } @@ -255,9 +263,12 @@ public async Task ConfirmCode_Failed_SlowDownAndAccessDenied() Assert.Null(manager.GetUser()); Exception? e = null; - try { + try + { var result = await manager.ConfirmCode(); - } catch (Exception exception) { + } + catch (Exception exception) + { e = exception; Debug.Log("Exception: " + e); } @@ -279,9 +290,12 @@ public async Task ConfirmCode_Failed_UnexpectedErrorCode() Assert.Null(manager.GetUser()); Exception? e = null; - try { + try + { var result = await manager.ConfirmCode(); - } catch (Exception exception) { + } + catch (Exception exception) + { e = exception; Debug.Log("Exception: " + e); } @@ -302,9 +316,12 @@ public async Task ConfirmCode_Failed_UnexpectedResponse() Assert.Null(manager.GetUser()); Exception? e = null; - try { + try + { var result = await manager.ConfirmCode(); - } catch (Exception exception) { + } + catch (Exception exception) + { e = exception; Debug.Log("Exception: " + e); } @@ -317,7 +334,8 @@ public void HasCredentialsSavedTest() { Assert.False(manager.HasCredentialsSaved()); - credentialsManager.token = new TokenResponse() { + credentialsManager.token = new TokenResponse() + { access_token = AuthManagerTests.ACCESS_TOKEN, refresh_token = AuthManagerTests.REFRESH_TOKEN, id_token = AuthManagerTests.ID_TOKEN, @@ -333,23 +351,28 @@ private string CreateErrorJsonString(string error) } } - internal class MockCredentialsManager : ICredentialsManager { + internal class MockCredentialsManager : ICredentialsManager + { public bool hasValidCredentials = false; public TokenResponse? token = null; - public void SaveCredentials(TokenResponse tokenResponse) { + public void SaveCredentials(TokenResponse tokenResponse) + { token = tokenResponse; } - public TokenResponse? GetCredentials() { + public TokenResponse? GetCredentials() + { return token; } - public bool HasValidCredentials() { + public bool HasValidCredentials() + { return hasValidCredentials; } - public void ClearCredentials() { + public void ClearCredentials() + { } } diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/Core/BrowserCommunicationsManagerTests.cs b/src/Packages/Passport/Tests/Runtime/Scripts/Core/BrowserCommunicationsManagerTests.cs index 5a23ab8c..2c4f6223 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/Core/BrowserCommunicationsManagerTests.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/Core/BrowserCommunicationsManagerTests.cs @@ -24,12 +24,12 @@ public class BrowserCommunicationsManagerTests #pragma warning disable CS8618 private BrowserCommunicationsManager manager; - private MockBrowserClient mockClient; + private MockBrowserClient mockClient; #pragma warning restore CS8618 - - [SetUp] + + [SetUp] public void Init() - { + { mockClient = new MockBrowserClient(); manager = new BrowserCommunicationsManager(mockClient); } @@ -73,9 +73,12 @@ public async Task CallAndResponse_Failed_NoRequestId() mockClient.setRequestId = false; Exception? e = null; - try { + try + { string response = await manager.Call(FUNCTION_NAME); - } catch (PassportException exception) { + } + catch (PassportException exception) + { e = exception; } @@ -94,12 +97,15 @@ public async Task CallAndResponse_Failed_ClientError_WithType() }; PassportException? e = null; - try { + try + { string response = await manager.Call(FUNCTION_NAME); - } catch (PassportException exception) { + } + catch (PassportException exception) + { e = exception; - } - + } + Assert.AreEqual(PassportErrorType.WALLET_CONNECTION_ERROR, e?.Type); } @@ -114,12 +120,15 @@ public async Task CallAndResponse_Failed_ClientError_NoType() }; PassportException? e = null; - try { + try + { string response = await manager.Call(FUNCTION_NAME); - } catch (PassportException exception) { + } + catch (PassportException exception) + { e = exception; - } - + } + Assert.Null(e?.Type); Assert.AreEqual(ERROR, e?.Message); } @@ -128,7 +137,8 @@ public async Task CallAndResponse_Failed_ClientError_NoType() [Test] public void CallAndResponse_Success_BrowserReady() { - Response browserResponse = new() { + Response browserResponse = new() + { responseFor = BrowserCommunicationsManager.INIT, requestId = BrowserCommunicationsManager.INIT_REQUEST_ID, success = true @@ -143,7 +153,8 @@ public void CallAndResponse_Success_BrowserReady() } } - internal class MockBrowserClient : IWebBrowserClient { + internal class MockBrowserClient : IWebBrowserClient + { public event OnUnityPostMessageDelegate? OnUnityPostMessage; public Request? request = null; public Response? browserResponse = null; diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs b/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs index e6619323..f0dd9b0f 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs @@ -20,7 +20,7 @@ namespace Immutable.Passport public class PassportImplTests { internal static string DEVICE_CODE = "deviceCode"; - internal static string ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikp" + + internal static string ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikp" + "vaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjEyM30.kRqQkJudxgI3koJAp9K4ENp6E2ExFQ5VchogaTWx6Fk"; internal static string ACCESS_TOKEN_KEY = "accessToken"; internal static string REFRESH_TOKEN = "refreshToken"; @@ -37,9 +37,9 @@ public class PassportImplTests private PassportImpl passport; #pragma warning restore CS8618 - [SetUp] + [SetUp] public void Init() - { + { communicationsManager = new MockBrowserCommsManager(); auth = new MockAuthManager(); passport = new PassportImpl(auth, communicationsManager); @@ -80,7 +80,7 @@ public async Task Connect_Failed() { Assert.Null(await passport.Connect()); } - catch (InvalidOperationException e) + catch (InvalidOperationException e) { exception = e; } @@ -113,7 +113,7 @@ public async Task ConfirmCode_Failed() { await passport.ConfirmCode(); } - catch (PassportException e) + catch (PassportException e) { exception = e; } @@ -145,8 +145,8 @@ public async Task GetAddress_Failed() Assert.True(String.IsNullOrEmpty(communicationsManager.data)); } - [Test] - + [Test] + public void Logout_Success() { Assert.False(auth.logoutCalled); diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/Storage/CredentialsManagerTests.cs b/src/Packages/Passport/Tests/Runtime/Scripts/Storage/CredentialsManagerTests.cs index c6b5579a..feae1139 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/Storage/CredentialsManagerTests.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/Storage/CredentialsManagerTests.cs @@ -12,12 +12,12 @@ public class CredentialsManagerTests { internal static string ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikp" + "vaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjcyMDB9.zKW_cyLXjQ0Vbc7LsrHGo6fIUfCy9QQhFNdKN5JxlZY"; - internal static string INVALID_ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmF" + + internal static string INVALID_ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmF" + "tZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjB9.JWKPB-5Q8rTYzl-MfhRGpP9WpDpQxC7JkIAGFMDZnpg"; internal static string REFRESH_TOKEN = "refreshToken"; - internal static string ID_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwibmFtZSI6IklEIHRva2VuIiwiZXh" + + internal static string ID_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwibmFtZSI6IklEIHRva2VuIiwiZXh" + "wIjo3MjAwfQ.k4THNItPrrW7g5WmbBhRlpUwW1_dRpg1Zwg6jBVAvnA"; - internal static string INVALID_ID_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwibmFtZSI6IklEIHRva2V" + + internal static string INVALID_ID_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwibmFtZSI6IklEIHRva2V" + "uIiwiZXhwIjowfQ.DHDYnvJ9M8UMNeRD95oBQX91yn_snlMEpdK_qqilDB0"; internal static string TOKEN_TYPE = "Bearer"; internal static int EXPIRES_IN = 86400; @@ -27,27 +27,29 @@ public class CredentialsManagerTests internal static string TOKEN_JSON = $@"{{""access_token"":""{ACCESS_TOKEN}"",""refresh_token"":""{REFRESH_TOKEN}""," + $@"""id_token"":""{ID_TOKEN}"",""token_type"":""{TOKEN_TYPE}"",""expires_in"":{EXPIRES_IN}}}"; - private readonly TokenResponse tokenResponse = new() { + private readonly TokenResponse tokenResponse = new() + { access_token = ACCESS_TOKEN, refresh_token = REFRESH_TOKEN, id_token = ID_TOKEN, token_type = TOKEN_TYPE, expires_in = EXPIRES_IN }; - + private string? playPrefsFunctionCalled = null; private string[]? playPrefsFunctionValues = null; #pragma warning disable CS8618 private TestableCredentialsManager manager; #pragma warning restore CS8618 - [SetUp] + [SetUp] public void Init() - { + { manager = new TestableCredentialsManager(OnPlayerPrefsCalled); } - - private void OnPlayerPrefsCalled(string function, string[] values) { + + private void OnPlayerPrefsCalled(string function, string[] values) + { playPrefsFunctionCalled = function; playPrefsFunctionValues = values; } @@ -58,7 +60,7 @@ public void SaveCredentialsTest() manager.SaveCredentials(tokenResponse); Assert.AreEqual(SET_STRING, playPrefsFunctionCalled); - Assert.AreEqual(new string[]{CredentialsManager.KEY_PREFS_CREDENTIALS, TOKEN_JSON}, playPrefsFunctionValues); + Assert.AreEqual(new string[] { CredentialsManager.KEY_PREFS_CREDENTIALS, TOKEN_JSON }, playPrefsFunctionValues); } [Test] @@ -67,7 +69,7 @@ public void GetCredentialsTest() TokenResponse? actualTokenResponse = manager.GetCredentials(); Assert.AreEqual(GET_STRING, playPrefsFunctionCalled); - Assert.AreEqual(new string[]{CredentialsManager.KEY_PREFS_CREDENTIALS, ""}, playPrefsFunctionValues); + Assert.AreEqual(new string[] { CredentialsManager.KEY_PREFS_CREDENTIALS, "" }, playPrefsFunctionValues); Assert.NotNull(actualTokenResponse); Assert.AreEqual(ACCESS_TOKEN, actualTokenResponse?.access_token); Assert.AreEqual(REFRESH_TOKEN, actualTokenResponse?.refresh_token); @@ -94,7 +96,7 @@ public void ClearCredentialsTest() manager.ClearCredentials(); Assert.AreEqual(DELETE_KEY, playPrefsFunctionCalled); - Assert.AreEqual(new string[]{CredentialsManager.KEY_PREFS_CREDENTIALS}, playPrefsFunctionValues); + Assert.AreEqual(new string[] { CredentialsManager.KEY_PREFS_CREDENTIALS }, playPrefsFunctionValues); } [Test] @@ -117,7 +119,8 @@ public void HasValidCredentialsTest_BothInvalid() public void HasValidCredentialsTest_InvalidAccessToken() { manager.mockCurrentTimeSeconds = 1; - manager.mockToken = new TokenResponse() { + manager.mockToken = new TokenResponse() + { access_token = CredentialsManagerTests.INVALID_ACCESS_TOKEN, refresh_token = CredentialsManagerTests.REFRESH_TOKEN, id_token = CredentialsManagerTests.ID_TOKEN, @@ -131,7 +134,8 @@ public void HasValidCredentialsTest_InvalidAccessToken() public void HasValidCredentialsTest_InvalidIdToken() { manager.mockCurrentTimeSeconds = 1; - manager.mockToken = new TokenResponse() { + manager.mockToken = new TokenResponse() + { access_token = CredentialsManagerTests.ACCESS_TOKEN, refresh_token = CredentialsManagerTests.REFRESH_TOKEN, id_token = CredentialsManagerTests.INVALID_ID_TOKEN, @@ -151,14 +155,16 @@ public void HasValidCredentialsTest_NoCredentials() delegate void PlayerPrefsDelegate(string function, string[] values); - class TestableCredentialsManager : CredentialsManager { + class TestableCredentialsManager : CredentialsManager + { private readonly PlayerPrefsDelegate onPlayerPrefs; public string? mockTokenJson; public TokenResponse? mockToken; public long mockCurrentTimeSeconds = 0; - public TestableCredentialsManager(PlayerPrefsDelegate onPlayerPrefs) { + public TestableCredentialsManager(PlayerPrefsDelegate onPlayerPrefs) + { this.onPlayerPrefs = onPlayerPrefs; } @@ -167,27 +173,32 @@ protected override long GetCurrentTimeSeconds() return mockCurrentTimeSeconds; } - protected override TokenResponse DeserializeTokenResponse(string json) { - return mockToken ?? new TokenResponse() { + protected override TokenResponse DeserializeTokenResponse(string json) + { + return mockToken ?? new TokenResponse() + { access_token = CredentialsManagerTests.ACCESS_TOKEN, refresh_token = CredentialsManagerTests.REFRESH_TOKEN, id_token = CredentialsManagerTests.ID_TOKEN, token_type = CredentialsManagerTests.TOKEN_TYPE, expires_in = CredentialsManagerTests.EXPIRES_IN }; - } + } - protected override void SetStringToPlayerPrefs(string key, string value) { - onPlayerPrefs(CredentialsManagerTests.SET_STRING, new string[]{key, value}); + protected override void SetStringToPlayerPrefs(string key, string value) + { + onPlayerPrefs(CredentialsManagerTests.SET_STRING, new string[] { key, value }); } - protected override string GetStringFromPlayerPrefs(string key, string defaultValue) { - onPlayerPrefs(CredentialsManagerTests.GET_STRING, new string[]{key, defaultValue}); + protected override string GetStringFromPlayerPrefs(string key, string defaultValue) + { + onPlayerPrefs(CredentialsManagerTests.GET_STRING, new string[] { key, defaultValue }); return mockTokenJson ?? CredentialsManagerTests.TOKEN_JSON; } - protected override void DeleteKeyFromPlayerPrefs(string key) { - onPlayerPrefs(CredentialsManagerTests.DELETE_KEY, new string[]{key}); + protected override void DeleteKeyFromPlayerPrefs(string key) + { + onPlayerPrefs(CredentialsManagerTests.DELETE_KEY, new string[] { key }); } } } \ No newline at end of file diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/Utility/JwtUtilityTests.cs b/src/Packages/Passport/Tests/Runtime/Scripts/Utility/JwtUtilityTests.cs index 6a48b088..d0617476 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/Utility/JwtUtilityTests.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/Utility/JwtUtilityTests.cs @@ -8,7 +8,7 @@ public class JwtUtilityTests [Test] public void DecodeJwtTest() { - string jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmF" + + string jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmF" + "tZSI6IkltbXV0YWJsZSIsImlhdCI6MTUxNjIzOTAyMn0.3uo_vJDobJs97abKHJY48qaYaFdUj0o02admvkedyp4"; string? actual = JwtUtility.DecodeJwt(jwt); diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/Utility/MockHttpMessageHandler.cs b/src/Packages/Passport/Tests/Runtime/Scripts/Utility/MockHttpMessageHandler.cs index bb22366c..5080f029 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/Utility/MockHttpMessageHandler.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/Utility/MockHttpMessageHandler.cs @@ -13,15 +13,15 @@ namespace Immutable.Passport.Utility.Tests internal class MockHttpMessageHandler : HttpMessageHandler { // Requests made in order - public List Requests { get; private set; } = new List(); - - // Responses to return matching request order + public List Requests { get; private set; } = new List(); + + // Responses to return matching request order public List Responses { get; private set; } = new List(); public MockHttpMessageHandler() { - } - + } + public HttpClient ToHttpClient() { return new HttpClient(this); @@ -37,7 +37,8 @@ protected override Task SendAsync(HttpRequestMessage reques { // Debug.Log("Request made: " + request.RequestUri); Requests.Add(request); - if (Requests.Count <= Responses.Count) { + if (Requests.Count <= Responses.Count) + { return Task.FromResult(Responses[Requests.Count - 1]); }