Пример #1
0
        public void Should_Authenticate_Test_Admin_Identity()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(_testAdminIdentity);
            var userAccess = serviceProvider.Authenticate();

            Assert.IsNotNull(userAccess);
        }
        public void Should_Not_Hit_Cache_When_Authenticating_The_First_Time()
        {
            var cacheMock = new Mock<ICache<UserAccess>>();
            var restServiceMock = new Mock<IRestService>();

            restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<string>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
            restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<Uri>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));

            var identityProvider = new IdentityProvider(restServiceMock.Object, cacheMock.Object);

            identityProvider.Authenticate(new RackspaceCloudIdentity());

            cacheMock.Verify(m => m.Get(It.IsAny<string>(), It.IsAny<Func<UserAccess>>(), It.IsAny<bool>()), Times.Never());
        }
        public void Should_Always_Request_Fresh_Data_From_Cache_When_Authenticating()
        {
            var cacheMock = new Mock<ICache<UserAccess>>();
            var restServiceMock = new Mock<IRestService>();

            restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<string>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
            restServiceMock.Setup(m => m.Execute<AuthenticationResponse>(It.IsAny<Uri>(), It.IsAny<HttpMethod>(), It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<RequestSettings>())).Returns(new Response<AuthenticationResponse>(200, "OK", new AuthenticationResponse(), new List<HttpHeader>(), null));
            
            var identityProvider = new IdentityProvider(restServiceMock.Object, cacheMock.Object);

            for (int i = 0; i < 100; i++)
            {
                identityProvider.Authenticate(new RackspaceCloudIdentity());
            }

            cacheMock.Verify(m => m.Get(It.IsAny<string>(), It.IsAny<Func<UserAccess>>(), true), Times.Exactly(100));
        }
Пример #4
0
        public void Should_Throw_Error_When_Authenticating_With_Invalid_Password()
        {
            var identity = new RackspaceCloudIdentity()
                               {
                                   Username = _testIdentity.Username,
                                   Password = "******"
                               };
            IIdentityProvider serviceProvider = new IdentityProvider(identity);

            try
            {
                var userAccess = serviceProvider.Authenticate();

                throw new Exception("This code path is invalid, exception was expected.");
            }
            catch (net.openstack.Core.Exceptions.Response.ResponseException)
            {
                Assert.IsTrue(true);
            }
        }
Пример #5
0
        public void Should_Return_List_Of_Users_Credentials_When_Requesting_As_Non_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            var creds = provider.ListUserCredentials(_userDetails.Id);

            Assert.IsNotNull(creds);
            Assert.IsTrue(creds.Any());

            foreach (var cred in creds)
            {
                Assert.IsFalse(string.IsNullOrWhiteSpace(cred.Name));
                Assert.IsFalse(string.IsNullOrWhiteSpace(cred.APIKey));
                Assert.IsFalse(string.IsNullOrWhiteSpace(cred.Username));
            }
        }
Пример #6
0
        public void Should_Return_User_API_Credential_When_Requesting_As_Non_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            var cred = provider.GetUserCredential(_userDetails.Id, "RAX-KSKEY:apiKeyCredentials");

            Assert.IsNotNull(cred);
            Assert.AreEqual("RAX-KSKEY:apiKeyCredentials", cred.Name);
            Assert.IsFalse(string.IsNullOrWhiteSpace(cred.APIKey));
            Assert.IsFalse(string.IsNullOrWhiteSpace(cred.Username));
        }
Пример #7
0
        public void Should_List_Only_Self_When_Retrieving_List_Of_Users_With_Non_Admin_Account()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(new RackspaceCloudIdentity { Username = _testUser.Username, Password = _newTestUserPassword });

            var users = serviceProvider.ListUsers();

            Assert.IsTrue(users.Count() == 1);
            Assert.AreEqual(_testUser.Username, users[0].Username);
        }
Пример #8
0
        public void Should_Return_The_Users_Tenant_When_Requesting_As_Non_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            var tenants = provider.ListTenants();

            Assert.IsTrue(tenants.Any());

            if(!string.IsNullOrWhiteSpace(_testIdentity.TenantId))
            {
                Assert.IsTrue(tenants.Any(t => t.Id == _testIdentity.TenantId));
            }
        }
Пример #9
0
        public void Should_Get_NewUser_When_Requesting_As_Self()
        {
            IIdentityProvider provider = new IdentityProvider(new RackspaceCloudIdentity { Username = _testUser.Username, Password = _newTestUserPassword });

            var user = provider.GetUser(_testUser.Id);

            Assert.IsNotNull(user);
        }
Пример #10
0
        public void Should_Update_NewUser_Username_And_Email_When_Requesting_As_Self()
        {
            IIdentityProvider provider = new IdentityProvider(new RackspaceCloudIdentity { Username = _testUser.Username, Password = _newTestUserPassword });

            var user = new User
            {
                Id = _testUser.Id,
                Username = "******",
                Email = "*****@*****.**",
                Enabled = true,
            };
            var updatedUser = provider.UpdateUser(user);

            Assert.IsNotNull(updatedUser);
            Assert.AreEqual("openstacknettestuser42", updatedUser.Username);
            Assert.AreEqual("*****@*****.**", updatedUser.Email);
            Assert.AreEqual(true, updatedUser.Enabled);
        }
Пример #11
0
        public void Should_Update_NewUser_Username_And_Email_When_Requesting_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider();

            var user = new User
                           {
                               Id = _newTestUser1.Id,
                               Username = "******",
                               Email = "*****@*****.**",
                               Enabled = true
                           };
            var updatedUser = provider.UpdateUser(_testIdentity, user);

            Assert.IsNotNull(updatedUser);
            Assert.AreEqual("openstacknettestuser12", updatedUser.Username);
            Assert.AreEqual("*****@*****.**", updatedUser.Email);
            Assert.AreEqual(true, updatedUser.Enabled);
            Assert.IsTrue(string.IsNullOrWhiteSpace(updatedUser.DefaultRegion));
        }
Пример #12
0
        public void Should_List_Details_Of_Other_User_When_Retrieving_User_By_Id_With_Admin_Account()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(_testAdminIdentity);

            var details = serviceProvider.GetUser(_userDetails.Id);

            Assert.IsNotNull(details);
            Assert.AreEqual(_testIdentity.Username, details.Username);
        }
Пример #13
0
        public void Should_Throw_Exception_When_Requesting_The_NewUser_After_It_Has_Been_Deleted_When_Requesting_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            try
            {
                provider.GetUser(_testUser.Id);

                throw new Exception("This code path is invalid, exception was expected.");
            }
            catch(Exception ex)
            {
                Assert.IsTrue(true);
            }
        }
Пример #14
0
        public void Should_List_Multiple_Users_When_Retrieving_List_Of_Users_With_Admin_Account()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(_testAdminIdentity);

            var users = serviceProvider.ListUsers();

            Assert.IsTrue(users.Any());
        }
Пример #15
0
        public void Should_Delete_NewUser_When_Requesting_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            var response = provider.DeleteUser(_testUser.Id);

            Assert.IsTrue(response);
        }
Пример #16
0
        public void Should_Authenticate_NewUser()
        {
            Assert.IsNotNull(_testUser);

            IIdentityProvider provider = new IdentityProvider();

            var userAccess =
                provider.Authenticate(new RackspaceCloudIdentity
                                          {Username = _testUser.Username, Password = _newTestUserPassword});

            Assert.IsNotNull(userAccess);
        }
Пример #17
0
        public void Should_Throw_Exception_When_Trying_To_Get_Details_Of_A_Different_User_When_Retrieving_User_By_Id_With_Non_Admin_Account()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(_testIdentity);

            try
            {
                var details = serviceProvider.GetUser(_adminUserDetails.Id);

                throw new Exception("This code path is invalid, exception was expected.");
            }
            catch (net.openstack.Core.Exceptions.Response.ResponseException)
            {
                Assert.IsTrue(true);
            }
        }
Пример #18
0
        public void Should_List_Only_User_In_Account_When_Retrieving_List_Of_Users_With_User_Admin_Account()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(_testIdentity);

            var users = serviceProvider.ListUsers();

            Assert.IsTrue(users.Any());
            Assert.AreEqual(_testIdentity.Username, users[0].Username);
        }
Пример #19
0
        public void Should_Update_NewUser_Username_And_Email_And_Default_Region_When_Requesting_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            var user = new User
            {
                Id = _testUser.Id,
                Username = "******",
                Email = "*****@*****.**",
                Enabled = true,
                DefaultRegion = "DFW"
            };
            var updatedUser = provider.UpdateUser(user);

            Assert.IsNotNull(updatedUser);
            Assert.AreEqual("openstacknettestuser32", updatedUser.Username);
            Assert.AreEqual("*****@*****.**", updatedUser.Email);
            Assert.AreEqual(true, updatedUser.Enabled);
            Assert.AreEqual("DFW", updatedUser.DefaultRegion);
        }
Пример #20
0
        public void Should_Add_New_User_2_With_Specifying_A_Password_But_Not_Default_Region_To_Account_When_Requesting_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testIdentity);

            var newUser = provider.AddUser(new NewUser { Username = "******", Email = "*****@*****.**", Enabled = true, Password = NewUserPassword });
            _newTestUserPassword = newUser.Password;

            Assert.IsNotNull(newUser);
            Assert.AreEqual("openstacknettestuser2", newUser.Username);
            Assert.AreEqual("*****@*****.**", newUser.Email);
            Assert.AreEqual(true, newUser.Enabled);
            Assert.AreEqual(NewUserPassword, newUser.Password);
            Assert.IsFalse(string.IsNullOrWhiteSpace(newUser.Password));
        }
Пример #21
0
        public void Should_List_Details_Of_Self_When_Retrieving_User_By_Name_With_Admin_Account()
        {
            IIdentityProvider serviceProvider = new IdentityProvider(_testAdminIdentity);

            _adminUserDetails = serviceProvider.GetUserByName(_testAdminIdentity.Username);

            Assert.IsNotNull(_adminUserDetails);
            Assert.AreEqual(_testAdminIdentity.Username, _adminUserDetails.Username);
        }
Пример #22
0
        public void Should_Retrieve_New_User_2_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider(_testAdminIdentity);

            _testUser = provider.GetUserByName("openstacknettestuser2");

            Assert.IsNotNull(_testUser);
            Assert.AreEqual("openstacknettestuser2", _testUser.Username);
            Assert.AreEqual("*****@*****.**", _testUser.Email);
            Assert.AreEqual(true, _testUser.Enabled);
        }
Пример #23
0
        public void Should_Add_New_User_Without_Specifying_A_Password_Or_Default_Region_To_Account_When_Requesting_As_User_Admin()
        {
            IIdentityProvider provider = new IdentityProvider();

            _newTestUser1 = provider.AddUser(_testIdentity, new NewUser { Username = "******", Email = "*****@*****.**", Enabled = true });

            Assert.IsNotNull(_newTestUser1);
            Assert.AreEqual("openstacknettestuser1", _newTestUser1.Username);
            Assert.AreEqual("*****@*****.**", _newTestUser1.Email);
            Assert.AreEqual(true, _newTestUser1.Enabled);
            Assert.IsFalse(string.IsNullOrWhiteSpace(_newTestUser1.Password));
        }