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 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 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)); }