Ejemplo n.º 1
0
        public void TestIsAuthorized_NoMatch()
        {
            // arrange
            var claims = new List <Claim> {
                new Claim("DisplayName", "DisplayName"),
                new Claim("UserName", "UserName"),
                new Claim("Email", "Email"),
                new Claim("UserId", "UserId"),
                new Claim("Claims", "b|http://b|role1;role2"),
            };
            var             identity  = new ClaimsIdentity(claims);
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);
            var             claim     = new api.Claim {
                Name  = "a",
                Url   = "http://a",
                Roles = new string[] { "role1" },
            };

            // act
            var authPrinicpal = Authorization.IsAuthorized(principal, claim, "issuer");

            // assert
            authPrinicpal
            .Should()
            .BeNull();
        }
Ejemplo n.º 2
0
        public void TestIsAuthorized_PathAndTrailingSlash()
        {
            // arrange
            var claims = new List <Claim> {
                new Claim("DisplayName", "DisplayName"),
                new Claim("UserName", "UserName"),
                new Claim("Email", "Email"),
                new Claim("UserId", "UserId"),
                new Claim("Claims", "a|http://a/path/|role1;role2"),
            };
            var             identity  = new ClaimsIdentity(claims);
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);
            var             claim     = new api.Claim {
                Name  = "a",
                Url   = "http://a/path",
                Roles = new string[] { "role1" },
            };

            // act
            var authPrinicpal = Authorization.IsAuthorized(principal, claim, "issuer");

            // assert
            authPrinicpal
            .Should()
            .NotBeNull();
            authPrinicpal.Identity.AuthenticationType
            .Should()
            .Be("JWT");
            authPrinicpal.Claims
            .Should()
            .HaveCount(7);
            authPrinicpal.Claims
            .Should()
            .Contain(x => x.Type == "DisplayName" && x.Value == "DisplayName");
            authPrinicpal.Claims
            .Should()
            .Contain(x => x.Type == "UserName" && x.Value == "UserName");
        }