예제 #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_Authenticate_NewUser()
        {
            Assert.IsNotNull(_testUser);

            IIdentityProvider provider = new IdentityProvider();

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

            Assert.IsNotNull(userAccess);
        }