public void Setup()
        {
            _projRepo           = new ProjectRepositoryMock();
            _userRepo           = new UserRepositoryMock();
            _userEditRepo       = new UserEditRepositoryMock();
            _permissionService  = new PermissionServiceMock(_userRepo);
            _userEditService    = new UserEditService(_userEditRepo);
            _userEditController = new UserEditController(
                _userEditRepo, _userEditService, _projRepo, _permissionService, _userRepo)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };

            _jwtAuthenticatedUser = new User {
                Username = "******", Password = "******"
            };
            _userRepo.Create(_jwtAuthenticatedUser);
            _jwtAuthenticatedUser = _permissionService.Authenticate(
                _jwtAuthenticatedUser.Username, _jwtAuthenticatedUser.Password).Result ?? throw new Exception();
            _userEditController.ControllerContext.HttpContext.Request.Headers["UserId"] = _jwtAuthenticatedUser.Id;
            _projId = _projRepo.Create(new Project {
                Name = "UserEditControllerTests"
            }).Result !.Id;
        }
Beispiel #2
0
        public void Setup()
        {
            _projRepo          = new ProjectRepositoryMock();
            _userRepo          = new UserRepositoryMock();
            _userRoleRepo      = new UserRoleRepositoryMock();
            _permissionService = new PermissionServiceMock(_userRepo);
            _semDomService     = new SemanticDomainService();
            _projController    = new ProjectController(_projRepo, _semDomService, _userRoleRepo,
                                                       _userRepo, _permissionService)
            {
                // Mock the Http Context because this isn't an actual call avatar controller
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };

            _jwtAuthenticatedUser = new User {
                Username = "******", Password = "******"
            };
            _userRepo.Create(_jwtAuthenticatedUser);
            _jwtAuthenticatedUser = _permissionService.Authenticate(
                _jwtAuthenticatedUser.Username, _jwtAuthenticatedUser.Password).Result ?? throw new Exception();

            _projController.ControllerContext.HttpContext.Request.Headers["UserId"] = _jwtAuthenticatedUser.Id;
        }
Beispiel #3
0
        public async Task <IActionResult> Authenticate([FromBody, BindRequired] Credentials cred)
        {
            try
            {
                var user = await _permissionService.Authenticate(cred.Username, cred.Password);

                if (user is null)
                {
                    return(Unauthorized(cred.Username));
                }
                return(Ok(user));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound(cred.Username));
            }
        }