Exemplo n.º 1
0
        public async Task NotSucceedWhenPermissionsRefused()
        {
            var requiredPermissions             = new[] { "customPermission" };
            var mockRequiredPermissionsResolver = CreateMockRequiredPermissionsResolver(requiredPermissions);
            var handler = new CustomBasedAuthorizationHandler(mockRequiredPermissionsResolver);

            var permissionClaims = new List <Claim>(new Claim[]
            {
                new Claim(Claims.PermissionsType, "otherresource")
            });

            var context = CreateAuthorizationHandlerContext(new List <Claim>());

            await handler.HandleAsync(context);

            Assert.False(context.HasSucceeded);
        }
Exemplo n.º 2
0
        public async Task SucceedWhenPermissionsGranted()
        {
            var requiredPermissions             = new[] { "customPermission" };
            var mockRequiredPermissionsResolver = CreateMockRequiredPermissionsResolver(requiredPermissions);
            var handler = new CustomBasedAuthorizationHandler(mockRequiredPermissionsResolver);

            var permissionClaims = new List <Claim>(new Claim[]
            {
                new Claim(Claims.PermissionsType, requiredPermissions[0])
            });

            var context = CreateAuthorizationHandlerContext(permissionClaims);

            await handler.HandleAsync(context);

            Assert.True(context.HasSucceeded);
        }