public void TestAddAuthenticator() { var mock = new SteamWebMock(); mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkHasPhone)(new object[] { "{has_phone: true}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.GeneralFailure, response); }); // Should try and add phone Assert.AreEqual(1, mock.CallCount("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/AddAuthenticator/v0001", "POST", this.checkAddAuthenticator)); var mockB = (SteamWebMock)mock.Clone(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/AddAuthenticator/v0001", "POST", this.checkAddAuthenticator)(new object[] { "{}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.GeneralFailure, response); }); mockB.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/AddAuthenticator/v0001", "POST", this.checkAddAuthenticator)(new object[] { "{response: {status: 0}}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mockB, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.GeneralFailure, response); }); }
public void TestAuthenticatorPresent() { var mock = new SteamWebMock(); mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkHasPhone)(new object[] { "{has_phone: true}", HttpStatusCode.OK }); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/AddAuthenticator/v0001", "POST", this.checkAddAuthenticator)(new object[] { "{response: {status: 29}}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.AuthenticatorPresent, response); }); }
public void TestAlignTime() { // This test method is dependent on callbacks being called syncronously when possible // Will need to be rewritten if this ever changes long testTime = Util.GetSystemUnixTime() + new Random().Next(); var mock = new SteamWebMock(); // Makes steamweb request, fails TimeAligner.AlignTime(mock, Assert.IsFalse); Assert.AreEqual(1, mock.CallCount("Request")); // No alignment yet, makes another failed request // Should still call the callback var called = false; TimeAligner.GetSteamTime(mock, time => { called = true; }); Assert.IsTrue(called); Assert.AreEqual(2, mock.CallCount("Request")); // Steamweb will now respond with a time mock.WithArgs("Request", ApiEndpoints.TWO_FACTOR_TIME_QUERY, "POST")(new object[] { "{response: {server_time: " + testTime + "}}", HttpStatusCode.OK }); // No alignment yet, makes successful request // Should call the callback with an aligned time called = false; TimeAligner.GetSteamTime(mock, time => { called = true; long diff = Math.Abs(time - testTime); Assert.IsTrue(diff <= 3); Assert.AreEqual(3, mock.CallCount("Request")); }); Assert.IsTrue(called); // Has been aligned already, won't call request again // But should still call the callback with the current time // Assumes this test takes less than 3 seconds to run called = false; TimeAligner.GetSteamTime(mock, time => { called = true; long diff = Math.Abs(time - testTime); Assert.IsTrue(diff <= 3); Assert.AreEqual(3, mock.CallCount("Request")); }); Assert.IsTrue(called); }
public void TestRemovePhone() { this.linker.PhoneNumber = TestPhone; var mock = new SteamWebMock(); mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkHasPhone)(new object[] { "{has_phone: true}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.MustRemovePhoneNumber, response); }); }
public void TestErrorCodes() { var mock = new SteamWebMock(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/FinalizeAddAuthenticator/v0001", "POST", this.checkFinalize)(new object[] { "{response: {server_time: 0, status: 89, want_more: false, success: false}}", HttpStatusCode.OK }); var guardMock = new SteamGuardAccountMock(); guardMock.WithArgs("GenerateSteamGuardCode")(TestSteamGuardCode); this.linker.LinkedAccount = guardMock; this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.BadSMSCode, response); }); mock = new SteamWebMock(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/FinalizeAddAuthenticator/v0001", "POST", this.checkFinalize)(new object[] { "{response: {server_time: 0, status: 0, want_more: true, success: false}}", HttpStatusCode.OK }); this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.GeneralFailure, response); }); mock = new SteamWebMock(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/FinalizeAddAuthenticator/v0001", "POST", this.checkFinalize)(new object[] { "{response: {server_time: 0, status: 88, want_more: true, success: false}}", HttpStatusCode.OK }); this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.GeneralFailure, response); }); mock = new SteamWebMock(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/FinalizeAddAuthenticator/v0001", "POST", this.checkFinalize)(new object[] { "{response: {server_time: 0, status: 0, want_more: true, success: true}}", HttpStatusCode.OK }); this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.GeneralFailure, response); }); mock = new SteamWebMock(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/FinalizeAddAuthenticator/v0001", "POST", this.checkFinalize)(new object[] { "{response: {server_time: 0, status: 88, want_more: true, success: true}}", HttpStatusCode.OK }); this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes, response); }); }
public void TestAwaitingFinalization() { long testTime = Util.GetSystemUnixTime(); var mock = new SteamWebMock(); mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkHasPhone)(new object[] { "{has_phone: true}", HttpStatusCode.OK }); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/AddAuthenticator/v0001", "POST", this.checkAddAuthenticator) (new object[] { "{response: {status: 1, shared_secret: \"test-sharedsecret\", serial_number: \"test-serialnum\", revocation_code: \"test-revcode\", uri: \"test-uri\", server_time: " + testTime + ", " + "account_name: \"test-accountname\", token_gid: \"test-tokengid\", identity_secret: \"test-identsecret\", secret_1: \"test-secret1\", " + "device_id: \"test-deviceid\", fully_enrolled: true}}", HttpStatusCode.OK }); // Rogue values, should be ignored this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.AwaitingFinalization, response); Assert.AreEqual(this.sessionData, this.linker.LinkedAccount.Session); Assert.IsTrue(this.linker.LinkedAccount.DeviceID.Length > 0); // I assume this is used for restoring from storage and is never part of the response Assert.AreNotEqual("test-deviceid", this.linker.LinkedAccount.DeviceID); Assert.IsFalse(this.linker.LinkedAccount.FullyEnrolled); Assert.AreEqual("test-sharedsecret", this.linker.LinkedAccount.SharedSecret); Assert.AreEqual("test-serialnum", this.linker.LinkedAccount.SerialNumber); Assert.AreEqual("test-revcode", this.linker.LinkedAccount.RevocationCode); Assert.AreEqual("test-uri", this.linker.LinkedAccount.URI); Assert.AreEqual("test-accountname", this.linker.LinkedAccount.AccountName); Assert.AreEqual("test-tokengid", this.linker.LinkedAccount.TokenGID); Assert.AreEqual("test-identsecret", this.linker.LinkedAccount.IdentitySecret); Assert.AreEqual("test-secret1", this.linker.LinkedAccount.Secret1); Assert.AreEqual(testTime, this.linker.LinkedAccount.ServerTime); Assert.AreEqual(1, this.linker.LinkedAccount.Status); }); }
public void TestSmsCheck() { this.linker.PhoneNumber = "test-phone"; var mock = new SteamWebMock(); mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkSmsCode)(new object[] { "{success: false}", HttpStatusCode.OK }); this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.BadSMSCode, response); }); Assert.AreEqual(1, mock.CallCount("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkSmsCode)); }
public void TestAddPhone() { this.linker.PhoneNumber = TestPhone; var mock = new SteamWebMock(); mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkHasPhone)(new object[] { "{has_phone: false}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.GeneralFailure, response); }); // Should try and add phone Assert.AreEqual(1, mock.CallCount("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkAddPhone)); }
public void TestHasPhone() { var mock = new SteamWebMock(); // Use matcher instead of passing dictionary directly because .Equals won't work mock.WithArgs("Request", ApiEndpoints.COMMUNITY_BASE + "/steamguard/phoneajax", "POST", this.checkHasPhone)(new object[] { "{has_phone: false}", HttpStatusCode.OK }); this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.MustProvidePhoneNumber, response); }); this.linker.PhoneNumber = ""; this.linker.AddAuthenticator(mock, response => { Assert.AreEqual(AuthenticatorLinker.LinkResult.MustProvidePhoneNumber, response); }); }
public void TestLinkAuth() { var mock = new SteamWebMock(); mock.WithArgs("MobileLoginRequest", ApiEndpoints.STEAMAPI_BASE + "/ITwoFactorService/FinalizeAddAuthenticator/v0001", "POST", this.checkFinalize)(new object[] { "{response: {server_time: 0, status: 1, want_more: false, success: true}}", HttpStatusCode.OK }); var guardMock = new SteamGuardAccountMock(); guardMock.WithArgs("GenerateSteamGuardCode")(TestSteamGuardCode); this.linker.LinkedAccount = guardMock; this.linker.FinalizeAddAuthenticator(mock, TestSmsCode, response => { Assert.AreEqual(AuthenticatorLinker.FinalizeResult.Success, response); }); Assert.IsTrue(this.linker.LinkedAccount.FullyEnrolled); }