public void ValidateEncodedCredentialsTest() { var session = new Api.Session(Username, Password); var base64DecodedCredentials = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(session.CredentialsEncoded)); Assert.AreEqual(base64DecodedCredentials, $"{Username}:{Password}", "Base64 Credential Decoding failed"); }
public async Task AuthenticateSuccessTest() { var session = new Api.Session(Username, Password); var authResult = await session.Authenticate(); Assert.IsFalse(string.IsNullOrEmpty(authResult.Profile.AuthenticationToken), "Failed to authenticate"); }
public async Task GetDoorbotsHistoryTest() { var session = new Api.Session(Username, Password); await session.Authenticate(); var doorbotHistory = await session.GetDoorbotsHistory(); Assert.IsTrue(doorbotHistory.Count > 0, "No doorbot history items returned"); }
public async Task GetDevicesTest() { var session = new Api.Session(Username, Password); await session.Authenticate(); var devices = await session.GetRingDevices(); Assert.IsTrue(devices.Chimes.Count > 0 && devices.Doorbots.Count > 0, "No doorbots and/or chimes returned"); }
public async Task AuthenticateWithRefreshTokenSuccessTest() { // Authenticate normally the first time in order to get a refresh token to test var session = new Api.Session(Username, Password); await session.Authenticate(); // Request a new authenticated session based on the RefreshToken var refreshedSession = await Api.Session.GetSessionByRefreshToken(session.OAuthToken.RefreshToken); Assert.IsTrue(refreshedSession.IsAuthenticated, "Failed to authenticate using refresh token"); }
public async Task GetDoorbotsHistoryWithLimitTest() { var limit = 50; var session = new Api.Session(Username, Password); await session.Authenticate(); var doorbotHistory = await session.GetDoorbotsHistory(limit); Assert.IsTrue(doorbotHistory.Count > 0, "No doorbot history items returned"); Assert.IsTrue(doorbotHistory.Count == limit, $"{doorbotHistory.Count} doorbot history items returned while {limit} were expected"); }
public async Task GetDoorbotsHistoryRecordingByInstanceTest() { var session = new Api.Session(Username, Password); await session.Authenticate(); var doorbotHistory = await session.GetDoorbotsHistory(); Assert.IsTrue(doorbotHistory.Count > 0, "No doorbot history events were found"); var tempFilePath = Path.GetTempFileName(); await session.GetDoorbotHistoryRecording(doorbotHistory[0], tempFilePath); File.Delete(tempFilePath); }
public static async Task TestInitialize(TestContext testContext) { // Check if we have a refresh token to authenticate to Ring with if (string.IsNullOrEmpty(RefreshToken)) { // No refresh token available, try to authenticate with the credentials from the config file session = new Api.Session(Username, Password); Api.Entities.Session authResult = null; try { authResult = await session.Authenticate(twoFactorAuthCode : TwoFactorAuthenticationToken); if (!string.IsNullOrEmpty(TwoFactorAuthenticationToken)) { // Clear the configured two factor authentication code in the configuration file after we've used it once as it won't be valid anymore next time TwoFactorAuthenticationToken = string.Empty; } } catch (Api.Exceptions.TwoFactorAuthenticationRequiredException) { Assert.Fail("Ring account requires two factor authentication. Add the token received through text message to the config file as 'TwoFactorAuthenticationToken' and run the test again."); } catch (Api.Exceptions.TwoFactorAuthenticationIncorrectException) { Assert.Fail("The two factor authentication token provided in the config file as 'TwoFactorAuthenticationToken' is invalid or has expired."); } Assert.IsFalse(authResult == null || string.IsNullOrEmpty(authResult.Profile.AuthenticationToken), "Failed to authenticate"); // Store the refresh token for subsequent runs RefreshToken = session.OAuthToken.RefreshToken; } else { // Use the refresh token to set up a new session with Ring so we don't have to deal with the two factor authentication anymore session = await Api.Session.GetSessionByRefreshToken(RefreshToken); Assert.IsFalse(session == null || session.OAuthToken == null || string.IsNullOrEmpty(session.OAuthToken.AccessToken), "Failed to authenticate using refresh token"); } }
public async Task GetDevicesUnauthenticatedTest() { var session = new Api.Session(Username, Password); await session.GetRingDevices(); }
public async Task AuthenticateFailTest() { var session = new Api.Session("*****@*****.**", "someinvalidpassword"); await session.Authenticate(); }
public async Task GetDevicesUnauthenticatedTest() { var session = new Api.Session("", ""); await session.GetRingDevices(); }