Example #1
0
        public void RequiresAnyClaims_AuthorizedUserWithAllClaims_ReturnsAuthorized()
        {
            var attr        = new RequiresAnyClaimAttribute("b", "c", "a");
            var user        = UserSetup.GetUserWithClaims("a:0", "b:1", "c:2");
            var httpContext = new Fakes.FakeHttpContext();

            httpContext.User = user;
            var shouldContinue = attr.ShouldContinue(httpContext);

            Assert.True(shouldContinue.ShouldContinue);
        }
Example #2
0
        public void RequiresAnyClaims_UnauthenticatedUser_ReturnsUnauthenticated()
        {
            var attr        = new RequiresAnyClaimAttribute("a");
            var user        = new ClaimsPrincipal();
            var httpContext = new Fakes.FakeHttpContext();

            httpContext.User = user;
            var shouldContinue = attr.ShouldContinue(httpContext);

            Assert.False(shouldContinue.ShouldContinue);
            Assert.Equal(ApiFilterRunResult.Unauthenticated.SetResponseCode, shouldContinue.SetResponseCode);
        }
Example #3
0
        public void RequiresAnyClaim_ClaimsContainingWhiteSpaceClaim_ThrowsException()
        {
            bool error = false;

            try
            {
                var a = new RequiresAnyClaimAttribute("a", "   ");
            }
            catch (ArgumentException ex)
            {
                error = ex.Message.Contains("Claims cannot be null or empty or white space");
            }
            Assert.True(error);
        }
Example #4
0
        public void RequiresAnyClaim_EmptyClaimsArray_ThrowsException()
        {
            bool error = false;

            try
            {
                var a = new RequiresAnyClaimAttribute();
            }
            catch (ArgumentException ex)
            {
                error = ex.Message.Contains("Claims array is empty");
            }
            Assert.True(error);
        }
Example #5
0
        public void RequiresAnyClaim_NullClaims_ThrowsException()
        {
            bool error = false;

            try
            {
                var a = new RequiresAnyClaimAttribute(null);
            }
            catch (ArgumentNullException)
            {
                error = true;
            }
            Assert.True(error);
        }