public void MemeberShipService_AuthenticateUser()
        {
            _userRepository.Setup(e => e.FindUser(It.Is<string>(p => p == "test"))).Returns(
                new User
                    {
                        Name = "test",
                        Password = "******",
                        DeviceRegistrations = new Collection<Device>
                            {
                                new Device
                                    {
                                        KeyHandle = _deviceRegistration.KeyHandle,
                                        PublicKey = _deviceRegistration.PublicKey,
                                        AttestationCert = _deviceRegistration.AttestationCert,
                                        Counter = _deviceRegistration.Counter
                                    }
                            },
                        AuthenticationRequest = new AuthenticationRequest
                            {
                                AppId = _startedAuthentication.AppId,
                                KeyHandle = _startedAuthentication.KeyHandle,
                                Challenge = _startedAuthentication.Challenge
                            }
                    });
            _userRepository.Setup(e => e.RemoveUsersAuthenticationRequest(It.Is<string>(p => p == "test")));
            _userRepository.Setup(e => e.UpdateDeviceCounter(It.Is<string>(p => p == "test"), It.IsAny<byte[]>(), It.IsAny<uint>()));
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.AuthenticateUser("test", _authenticateResponse.ToJson());

            Assert.IsTrue(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
            _userRepository.Verify(e => e.RemoveUsersAuthenticationRequest(It.Is<string>(p => p == "test")), Times.Once);
        }
Ejemplo n.º 2
0
        public void MemeberShipService_GenerateServerRegistrationForUser()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.GenerateServerChallenge("test");

            Assert.IsNotNull(result);
        }
Ejemplo n.º 3
0
        public void MemeberShipService_GenerateServerRegistration()
        {
            _userRepository.Setup(e => e.SaveUserAuthenticationRequest(It.Is<string>(p => p == "test"), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()));
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.GenerateServerChallenge("test");

            Assert.IsNotNull(result);
            _userRepository.Verify(e => e.SaveUserAuthenticationRequest(It.Is<string>(p => p == "test"), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
        }
Ejemplo n.º 4
0
        public void MemeberShipService_GenerateServerChallengeNoUsername()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.GenerateServerChallenges("");

            Assert.IsNull(result);
        }
Ejemplo n.º 5
0
        public void MemeberShipService_SaveUserName()
        {
            _userRepository.Setup(s => s.FindUser(It.Is<string>(p => p == "someone"))).Returns((User) null).Verifiable();
            _userRepository.Setup(s => s.AddUser(It.Is<string>(p => p == "someone"), It.IsAny<string>())).Verifiable();
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var results = memeberShipService.SaveNewUser("someone", "password1");

            Assert.IsTrue(results);
            _userRepository.VerifyAll();
        }
Ejemplo n.º 6
0
        public void MemeberShipService_IsValidUserNameAndPassword()
        {
            _userRepository.Setup(e => e.FindUser(It.Is<string>(p => p == "test"))).Returns(new User { Password = "******" });
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.IsValidUserNameAndPassword("test", "hashedPassword");

            Assert.IsTrue(result);
            _userRepository.Verify(e => e.FindUser(It.Is<string>(p => p == "test")), Times.Once);
        }
Ejemplo n.º 7
0
        public void MemeberShipService_IsValidUserNameAndPasswordNullPassword()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.IsValidUserNameAndPassword("test", null);

            Assert.IsFalse(result);
        }
Ejemplo n.º 8
0
        public void MemeberShipService_CompleteRegistrationNoUserName()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.CompleteRegistration("", "nothing");

            Assert.IsFalse(result);
        }
Ejemplo n.º 9
0
        public void MemeberShipService_CompleteRegistrationSucess()
        {
            Device device = _user.DeviceRegistrations.First();
            _user.AuthenticationRequest.First().Challenge = _startedRegistration.Challenge;
            _user.AuthenticationRequest.First().AppId = _startedRegistration.AppId;

            _userRepository.Setup(e => e.FindUser("test")).Returns(_user);
            _userRepository.Setup(e => e.RemoveUsersAuthenticationRequests("test"));
            _userRepository.Setup(e => e.AddDeviceRegistration("Test", device.AttestationCert, Convert.ToUInt32(device.Counter), device.KeyHandle, device.PublicKey));
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.CompleteRegistration("test", _registerResponse.ToJson());

            Assert.IsTrue(result);
            _userRepository.Verify(e => e.RemoveUsersAuthenticationRequests("test"), Times.Once);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
Ejemplo n.º 10
0
        public void MemeberShipService_CannotSaveDuplicateUserName()
        {
            _userRepository.Setup(s => s.FindUser(It.Is<string>(p => p == "someone"))).Returns(new User()).Verifiable();
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var results = memeberShipService.SaveNewUser("someone", "password1");

            Assert.IsFalse(results);
            _userRepository.VerifyAll();
        }
Ejemplo n.º 11
0
        public void MemeberShipService_CompleteRegistrationNoDeviceResponse()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.CompleteRegistration("test", "");

            Assert.IsFalse(result);
        }
Ejemplo n.º 12
0
        public void MemeberShipService_AuthenticateUserNoUserName()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.AuthenticateUser("", _authenticateResponse.ToJson());

            Assert.IsFalse(result);
        }
Ejemplo n.º 13
0
        public void MemeberShipService_AuthenticateUserNoUserFound()
        {
            _userRepository.Setup(s => s.FindUser(It.Is<string>(p => p == "test")));

            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.AuthenticateUser("test", _authenticateResponse.ToJson());

            Assert.IsFalse(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
Ejemplo n.º 14
0
        public void MemeberShipService_AuthenticateUserNoDeviceResponse()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.AuthenticateUser("test", null);

            Assert.IsFalse(result);
        }
Ejemplo n.º 15
0
        public void MemeberShipService_IsUserRegisteredNoUserFound()
        {
            _userRepository.Setup(e => e.FindUser(It.Is<string>(p => p == "test")));
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.IsUserRegistered("test");

            Assert.IsFalse(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
Ejemplo n.º 16
0
        public void MemeberShipService_CompleteRegistrationUserFoundWithNoAuthenticationRequest()
        {
            _userRepository.Setup(e => e.FindUser("test")).Returns(new User());
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.CompleteRegistration("test", _authenticateResponse.ToJson());

            Assert.IsFalse(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
Ejemplo n.º 17
0
        public void MemeberShipService_IsUserRegisteredNoUserName()
        {
            _userRepository.Setup(e => e.FindUser(It.Is<string>(p => p == "test"))).Returns(new User
            {
                DeviceRegistrations = new Collection<Device>
                        {
                            new Device()
                        }
            });
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.IsUserRegistered("");

            Assert.IsFalse(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Never);
        }
Ejemplo n.º 18
0
        public void MemeberShipService_ConstructsProperly()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            Assert.IsNotNull(memeberShipService);
        }
Ejemplo n.º 19
0
        public void MemeberShipService_IsValidUserNameAndPasswordNoUser()
        {
            _userRepository.Setup(e => e.FindUser(It.Is<string>(p => p == "test")));
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.IsValidUserNameAndPassword("test", "hashedPassword");

            Assert.IsFalse(result);
            _userRepository.Verify(e => e.FindUser(It.Is<string>(p => p == "test")), Times.Once);
        }
Ejemplo n.º 20
0
        public void MemeberShipService_GenerateServerChallengeNoDeviceFound()
        {
            _userRepository.Setup(e => e.FindUser("test")).Returns(new User { DeviceRegistrations = new Collection<Device>() });
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.GenerateServerChallenges("test");

            Assert.IsNull(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
Ejemplo n.º 21
0
        public void MemeberShipService_SaveBlankUserName()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var results = memeberShipService.SaveNewUser("", "");

            Assert.IsFalse(results);
        }
Ejemplo n.º 22
0
        public void MemeberShipService_GenerateServerChallengeNoUserFound()
        {
            _userRepository.Setup(e => e.FindUser("test"));
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.GenerateServerChallenges("test");

            Assert.IsNull(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
Ejemplo n.º 23
0
        public void MemeberShipService_AuthenticateUserNoAuthenticationRequestFound()
        {
            _userRepository.Setup(s => s.FindUser(It.Is<string>(p => p == "test"))).Returns(new User
            {
                DeviceRegistrations = new Collection<Device>
                            {
                                new Device
                                    {
                                        KeyHandle = _deviceRegistration.KeyHandle,
                                        PublicKey = _deviceRegistration.PublicKey,
                                        AttestationCert = _deviceRegistration.AttestationCert,
                                        Counter = (int) _deviceRegistration.Counter
                                    }
                            }
            });

            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.AuthenticateUser("test", _authenticateResponse.ToJson());

            Assert.IsFalse(result);
            _userRepository.Verify(e => e.FindUser("test"), Times.Once);
        }
        public void MemeberShipService_GenerateServerRegistrationNoUserName()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

            var result = memeberShipService.GenerateServerRegistration("", "password");

            Assert.IsNull(result);
        }