Exemplo n.º 1
0
        public void ShouldPassEvaluateRuleIfCopyOutputValueFromInputIssuer()
        {
            var store = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@"content\integrationTest2.xml"));

            PolicyScope scope  = store.RetrieveScope(new Uri("http://localhost/1"));
            var         issuer = scope.Issuers.ElementAt(0);
            IList <InputPolicyClaim> inputClaims = new List <InputPolicyClaim>();
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");

            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "*"));
            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(claimType, string.Empty, CopyFromConstants.InputIssuer));

            store.AddPolicyRule(new Uri("http://localhost/1"), newRule);
            string claimValue = "myInputClaimValue33";

            ClaimsPolicyEvaluator evaluator = new ClaimsPolicyEvaluator(store);
            Claim inputClaim = new Claim("http://myClaimType", claimValue, string.Empty, "http://myIssuer1");
            IEnumerable <Claim> evaluatedOutputClaims = evaluator.Evaluate(new Uri("http://localhost/1"), new[] { inputClaim });

            Assert.IsNotNull(evaluatedOutputClaims);
            Assert.AreEqual("http://myClaimType", evaluatedOutputClaims.ElementAt(0).ClaimType);
        }
        public void AddPolicyRuleShouldAddNewOutputClaimTypeIfDoesNotExists()
        {
            XmlPolicyStore store    = new XmlPolicyStore("My Xml Store Path", new MockXmlRepository(@"..\..\content\claimMappings-PassingTest3.xml"));
            var            scopeUri = new Uri("http://localhost/1");

            IList <InputPolicyClaim> inputClaims = new List <InputPolicyClaim>();
            Issuer    issuer    = new Issuer("http://myIssuer1", "6f7051ece706096ac5a05ecb1860e2151c11b491", "myIssuer1");
            ClaimType claimType = new ClaimType("http://myClaimType", "myClaimType");

            inputClaims.Add(new InputPolicyClaim(issuer, claimType, "nicolas"));

            ClaimType newClaimType = new ClaimType("http://newClaimType", "myNewClaimType");

            PolicyRule newRule = new PolicyRule(AssertionsMatch.Any, inputClaims, new OutputPolicyClaim(newClaimType, string.Empty, CopyFromConstants.InputValue));

            store.AddPolicyRule(scopeUri, newRule);
            var scope = store.RetrieveScope(scopeUri);

            Assert.AreEqual(2, scope.ClaimTypes.Count);
            Assert.AreEqual(newClaimType.FullName, scope.ClaimTypes.ElementAt(1).FullName);
            Assert.AreEqual(newClaimType.DisplayName, scope.ClaimTypes.ElementAt(1).DisplayName);
        }