Esempio n. 1
0
        public void When_Same_ResourceKey_Different_Type_Then_Cache_Does_Not_Affect()
        {
            // Arrange
            var demandedClaim1 = new Claim(
                "http://www.example.com/Claim/Permissions/Read",
                "http://www.example.com/Claim/Resource/4",
                "Type1");

            var demandedClaim2 = new Claim(
                "http://www.example.com/Claim/Permissions/Read",
                "http://www.example.com/Claim/Resource/4",
                "Type2");

            var claimChecker = new ClaimInspector(Enumerable.Empty <IResourceKeyExpander>(), new InMemoryCache(), new NullLogger <ClaimInspector>());

            // Push through once to add to cache
            claimChecker.IsDemandedClaimFulfilled(
                new[] { demandedClaim1 }.ToClaimsHolder(),
                demandedClaim1,
                ClaimExpansionState.RequiresExpansion);

            // Act

            var differentTypeIsValid = claimChecker.IsDemandedClaimFulfilled(
                new[] { demandedClaim1 }.ToClaimsHolder(),
                demandedClaim2,
                ClaimExpansionState.RequiresExpansion);

            // Assert
            differentTypeIsValid.Should().BeFalse();
        }
        public void When_Invoked_Then_Does_Not_Throw_SecurityException()
        {
            // Arrange
            var userClaim = new Claim(
                ClaimTypes.Permission,
                "Account/6",
                "Read");

            var demandedClaim = new Claim(
                ClaimTypes.Permission,
                "Task/4",
                "Read");

            var resourceKeyExpander = new Mock <IResourceKeyExpander>();

            resourceKeyExpander.Setup(e => e.Expand("Task/4")).Returns("Account/6/Project/9/Task/4");

            var claimChecker = new ClaimInspector(new[] { resourceKeyExpander.Object }, Cache.NoCache, new NullLogger <ClaimInspector>());

            // Act
            claimChecker.IsDemandedClaimFulfilled(
                new[] { userClaim }.ToClaimsHolder(),
                demandedClaim,
                ClaimExpansionState.RequiresExpansion);

            // Assert
            Assert.Pass("No exception should be thrown when demanding required claims.");
        }