コード例 #1
0
        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     = "test",
                    KeyHandle = _authenticateResponse.KeyHandle,
                    Challenge = _authenticateResponse.GetClientData().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);
        }
コード例 #2
0
        public void MemeberShipService_AuthenticateUserNoDeviceResponse()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

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

            Assert.IsFalse(result);
        }
コード例 #3
0
        public void MemeberShipService_AuthenticateUserNoUserName()
        {
            MemeberShipService memeberShipService = new MemeberShipService(_userRepository.Object);

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

            Assert.IsFalse(result);
        }
コード例 #4
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);
        }
コード例 #5
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         = _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);
        }