Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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");
            }
        }
Exemplo n.º 9
0
 public async Task GetDevicesUnauthenticatedTest()
 {
     var session = new Api.Session(Username, Password);
     await session.GetRingDevices();
 }
Exemplo n.º 10
0
        public async Task AuthenticateFailTest()
        {
            var session = new Api.Session("*****@*****.**", "someinvalidpassword");

            await session.Authenticate();
        }
Exemplo n.º 11
0
 public async Task GetDevicesUnauthenticatedTest()
 {
     var session = new Api.Session("", "");
     await session.GetRingDevices();
 }