예제 #1
0
        public void Arrange()
        {
            _configuration = new EmployerAccountsConfiguration
            {
                SupportConsoleUsers = SupportConsoleUsers
            };
            _mockAuthenticationService           = new Mock <IAuthenticationService>();
            AuthorizationContextTestsFixture     = new AuthorizationContextTestsFixture();
            MockIAuthorisationResourceRepository = new Mock <IAuthorisationResourceRepository>();
            Options      = new List <string>();
            _userContext = new UserContext(_mockAuthenticationService.Object, _configuration);
            SutDefaultAuthorizationHandler = new DefaultAuthorizationHandler(MockIAuthorisationResourceRepository.Object, _userContext);
            _testAuthorizationResource     = new AuthorizationResource
            {
                Name  = "Test",
                Value = Guid.NewGuid().ToString()
            };
            ResourceList = new List <AuthorizationResource>
            {
                _testAuthorizationResource
            };

            MockIAuthorisationResourceRepository.Setup(x => x.Get(It.IsAny <ClaimsIdentity>())).Returns(ResourceList);
            AuthorizationContext = new AuthorizationContext();
        }
예제 #2
0
        public void GetAuthorizationResult_WhenTheUserIsConsoleUser_ThenAllowTheUserToViewTeamPage(string role)
        {
            //Arrange
            AuthorizationContextTestsFixture.SetData(_testAuthorizationResource.Value, role);

            //Act
            AuthorizationContextTestsFixture.AuthorizationContext.ToString();

            //Assert
            var authorizationResult = SutDefaultAuthorizationHandler.GetAuthorizationResult(Options, AuthorizationContextTestsFixture.AuthorizationContext);

            authorizationResult.Result.IsAuthorized.Should().Be(true);
        }
예제 #3
0
        public void GetAuthorizationResult_WhenTheUserInRoleINotSupportConsoleAndClaimsSet_ThenAuthorizedTheUser()
        {
            //Arrange
            AuthorizationContextTestsFixture.SetDataNotSupportConsoleUser();

            //Act
            AuthorizationContextTestsFixture.AuthorizationContext.ToString();

            //Assert
            var authorizationResult = SutDefaultAuthorizationHandler.GetAuthorizationResult(Options, AuthorizationContextTestsFixture.AuthorizationContext);

            authorizationResult.Result.IsAuthorized.Should().Be(true);
        }
예제 #4
0
        public void GetAuthorizationResult_WhenTheUserInRoleIsSupportConsoleAndResourceNotSet_ThenAuthorizedTheUser(string role)
        {
            //Arrange
            AuthorizationContextTestsFixture.SetDataSupportConsoleUserNoResource(role);

            _mockAuthenticationService.Setup(m => m.HasClaim(ClaimsIdentity.DefaultRoleClaimType, role)).Returns(true);

            //Act
            AuthorizationContextTestsFixture.AuthorizationContext.ToString();

            //Assert
            var authorizationResult = SutDefaultAuthorizationHandler.GetAuthorizationResult(Options, AuthorizationContextTestsFixture.AuthorizationContext);

            authorizationResult.Result.IsAuthorized.Should().Be(false);
        }