public void AccessApiTest(InvalidTokenType tokenType, ApiType apiType) { var invalidToken = TokenTypeToTokenValueMap[tokenType](); var connection = AuthApiConnection.GetConnectionForCurrentTest(); var validToken = connection.AuthToken; try { if (apiType == ApiType.TokenRefresh) { ApiResponse<object> response = RefreshToken(invalidToken); PrAssert.That(response, PrIs.WithHttpCode(expectedCodes[apiType][tokenType])); } else if (apiType == ApiType.SettingCreate || apiType == ApiType.SettingGet || apiType == ApiType.SettingPut) { ApiResponse<object> response = SettingsPageSetToken(invalidToken, apiType == ApiType.SettingGet ? TestCoreFramework.Enums.HttpMethod.GET : apiType == ApiType.SettingCreate ? TestCoreFramework.Enums.HttpMethod.POST : TestCoreFramework.Enums.HttpMethod.PUT); PrAssert.That(response, PrIs.WithHttpCode(expectedCodes[apiType][tokenType])); } else { if (invalidToken != null) { connection.Authenticate(invalidToken); } else { connection.DeleteAllCookies(); } using (var response = connection.SendAsync(Utils.ApiTypeToDefaultEndpointMap[apiType], System.Net.Http.HttpMethod.Get).Result) { PrAssert.That(response.StatusCode, PrIs.EqualTo(expectedCodes[apiType][tokenType])); if (apiType == ApiType.PHP && tokenType == InvalidTokenType.Expired) { PrAssert.That(connection.GetCookieValue("HRBCAUTH"), Is.Not.EqualTo(invalidToken), "PHP did not update expired token"); } } } } finally { if (tokenType == InvalidTokenType.Duplicated) { connection.DeAuthenticate(); } if (tokenType != InvalidTokenType.Expired && tokenType != InvalidTokenType.ExpiredInv && tokenType != InvalidTokenType.OtherCompany) { connection.Authenticate(validToken); } } }
public InvalidTokenException(InvalidTokenType invalidTokenType, string errorMessage) : base(errorMessage, "The provided token is invalid") { InvalidTokenType = invalidTokenType; ErrorType = nameof(InvalidTokenException); }