Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        public AuthorizationContextTestsFixture SetDataNotSupportConsoleUser()
        {
            var claimsIdentity = new ClaimsIdentity();
            var principal      = new ClaimsPrincipal(claimsIdentity);

            MockContextBase.Setup(c => c.User).Returns(principal);
            AuthorizationContext.Set("ClaimsIdentity", claimsIdentity);
            return(this);
        }
Ejemplo n.º 3
0
 public AuthorizationContextTestsFixture()
 {
     AuthorizationContext = new AuthorizationContext();
     MockContextBase      = new Mock <HttpContextBase>();
     MockRequestBase      = new Mock <HttpRequestBase>();
     MockResponseBase     = new Mock <HttpResponseBase>();
     MockRouteHandler     = new Mock <IRouteHandler>();
     MockContextBase.Setup(x => x.Request).Returns(MockRequestBase.Object);
     MockContextBase.Setup(x => x.Response).Returns(MockResponseBase.Object);
 }
Ejemplo n.º 4
0
        public IAuthorizationContext GetAuthorizationContext()
        {
            var authorizationContext = new AuthorizationContext();
            var accountValues        = GetAccountValues();
            var userValues           = GetUserValues();

            if (accountValues.Id.HasValue)
            {
                authorizationContext.AddEmployerUserRoleValues(accountValues.Id.Value, userValues.Ref.Value);
            }

            authorizationContext.AddEmployerFeatureValues(accountValues.Id, userValues.Email);

            return(authorizationContext);
        }
Ejemplo n.º 5
0
        public AuthorizationContextTestsFixture SetDataSupportConsoleUserNoResource(string role)
        {
            var claimsIdentity = new ClaimsIdentity(new[]
            {
                new Claim(DasClaimTypes.Id, "UserRef"),
                new Claim(DasClaimTypes.Email, "Email"),
                new Claim("sub", "UserRef"),
            });

            claimsIdentity.AddClaim(new Claim(claimsIdentity.RoleClaimType, role));
            var principal = new ClaimsPrincipal(claimsIdentity);

            MockContextBase.Setup(c => c.User).Returns(principal);
            AuthorizationContext.Set("ClaimsIdentity", claimsIdentity);

            return(this);
        }
Ejemplo n.º 6
0
        public AuthorizationContextTestsFixture SetData(string url, string role)
        {
            var resource = new Resource {
                Value = url
            };

            AuthorizationContext.Set("Resource", resource);

            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(claimsIdentity.RoleClaimType, role));
            var principal = new ClaimsPrincipal(claimsIdentity);

            MockContextBase.Setup(c => c.User).Returns(principal);
            AuthorizationContext.Set("ClaimsIdentity", claimsIdentity);

            return(this);
        }