コード例 #1
0
        public void CannotVerifyWithIncorrectKey()
        {
            var user = new User()
            {
                Id = 1,
            };
            var token = new Token()
            {
                CreatedAt = new DateTime(2001, 1, 1),
                TokenGuid = Guid.NewGuid(),
                UserId    = user.Id
            };
            var patrols = new List <CurrentUserPatrolDto>();

            patrols.Add(new CurrentUserPatrolDto()
            {
                Id               = 1,
                Name             = "Test Patrol",
                EnableScheduling = true,
                Role             = Role.Administrator
            });

            var jwt = _authenticationService.CreateSignedJwtToken(token, user, patrols);

            var incorrectAuthenticationService = new AuthenticationService(_loggerMock.Object, _userRepositoryMock.Object, _passwordServiceMock.Object, _tokenRepositoryMock.Object, _systemClockMock.Object, _patrolRepository.Object, new Configuration.AppConfiguration()
            {
                JwtKey = "incorrectJwtKeyincorrectJwtKeyincorrectJwtKey", RootUrl = "jwtIssuer"
            });

            Assert.Throws <SecurityTokenInvalidSignatureException>(() =>
            {
                var validatedJwt = incorrectAuthenticationService.ValidateSignedJwtToken(jwt);
            });
        }
コード例 #2
0
 public void Setup()
 {
     _userRepositoryMock    = new Mock <IUserRepository>();
     _tokenRepositoryMock   = new Mock <ITokenRepository>();
     _passwordServiceMock   = new Mock <IPasswordService>();
     _loggerMock            = new Mock <ILogger <AuthenticationService> >();
     _systemClockMock       = new Mock <ISystemClock>();
     _patrolRepository      = new Mock <IPatrolRepository>();
     _authenticationService = new AuthenticationService(_loggerMock.Object, _userRepositoryMock.Object, _passwordServiceMock.Object, _tokenRepositoryMock.Object, _systemClockMock.Object, _patrolRepository.Object, new Configuration.AppConfiguration()
     {
         JwtKey = "jwtKeyjwtKeyjwtKeyjwtKeyjwtKey", RootUrl = "jwtIssuer"
     });
 }