public void ConformanceTestIIE_30(XmlDocument policy, XmlDocument request, XmlDocument response, XmlDocument aPolicy, XmlDocument aPolicySet) { var serialize = new Xacml30ProtocolSerializer(); XacmlContextRequest requestData; XacmlContextResponse responseData; XacmlPolicy aPolicyData; XacmlPolicySet aPolicySetData; using (XmlReader reader = XmlReader.Create(new StringReader(request.OuterXml))) { requestData = serialize.ReadContextRequest(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(response.OuterXml))) { responseData = serialize.ReadContextResponse(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(aPolicy.OuterXml))) { aPolicyData = serialize.ReadPolicy(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(aPolicySet.OuterXml))) { aPolicySetData = serialize.ReadPolicySet(reader); } var policyRepositoryMock = Substitute.For <IXacmlPolicyRepository>(); policyRepositoryMock.RequestPolicy(Arg.Is(aPolicyData.PolicyId)).Returns(aPolicyData); policyRepositoryMock.RequestPolicySet(Arg.Is(aPolicySetData.PolicySetId)).Returns(aPolicySetData); EvaluationEngine engine = EvaluationEngineFactory.Create(policy, policyRepositoryMock); XacmlContextResponse evaluatedResponse = engine.Evaluate(requestData, request); XacmlResponseAssert(responseData, evaluatedResponse); }
public void ConformanceTest_30(XmlDocument policy, XmlDocument request, XmlDocument response, Type expectedException) { var serialize = new Xacml30ProtocolSerializer(); XacmlContextRequest requestData; XacmlContextResponse responseData; Action action = () => { using (XmlReader reader = XmlReader.Create(new StringReader(request.OuterXml))) { requestData = serialize.ReadContextRequest(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(response.OuterXml))) { responseData = serialize.ReadContextResponse(reader); } EvaluationEngine engine = EvaluationEngineFactory.Create(policy, null); XacmlContextResponse evaluatedResponse = engine.Evaluate(requestData, request); XacmlResponseAssert(responseData, evaluatedResponse); }; if (expectedException != null) { Assert.That(() => action(), Throws.TypeOf(expectedException)); } else { action(); } }
public void IIE003_30() { XmlDocument policy = new XmlDocument(); XmlDocument request = new XmlDocument(); XmlDocument response = new XmlDocument(); XmlDocument policy1 = new XmlDocument(); XmlDocument policy2 = new XmlDocument(); policy.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IIE003Policy.xml")); request.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IIE003Request.xml")); response.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IIE003Response.xml")); policy1.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IIE003PolicyId1.xml")); policy2.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IIE003PolicyId2.xml")); var serialize = new Xacml30ProtocolSerializer(); XacmlContextRequest requestData; XacmlContextResponse responseData; XacmlPolicy policy1Data; XacmlPolicy policy2Data; using (XmlReader reader = XmlReader.Create(new StringReader(request.OuterXml))) { requestData = serialize.ReadContextRequest(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(response.OuterXml))) { responseData = serialize.ReadContextResponse(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(policy1.OuterXml))) { policy1Data = serialize.ReadPolicy(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(policy2.OuterXml))) { policy2Data = serialize.ReadPolicy(reader); } var policyRepositoryMock = Substitute.For <IXacmlPolicyRepository>(); policyRepositoryMock.RequestPolicy(Arg.Is(policy1Data.PolicyId)).Returns(policy1Data); policyRepositoryMock.RequestPolicy(Arg.Is(policy2Data.PolicyId)).Returns(policy2Data); policyRepositoryMock.RequestPolicySet(Arg.Any <Uri>()).Returns((XacmlPolicySet)null); EvaluationEngine engine = EvaluationEngineFactory.Create(policy, policyRepositoryMock); XacmlContextResponse evaluatedResponse = engine.Evaluate(requestData, request); XacmlResponseAssert(responseData, evaluatedResponse); }
public static EvaluationEngine Create(XmlReader reader, IXacmlPolicyRepository ch) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } EvaluationEngine engine; if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml10Constants.Namespaces.Policy)) { Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicy(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml10Constants.Namespaces.Policy)) { Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicySet(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml20Constants.Namespaces.Policy)) { Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicy(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml20Constants.Namespaces.Policy)) { Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicySet(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml30Constants.Namespaces.Policy)) { Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer(); engine = new EvaluationEngine30(serializer.ReadPolicy(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml30Constants.Namespaces.Policy)) { Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer(); engine = new EvaluationEngine30(serializer.ReadPolicySet(reader)); } else { throw new XmlException("Unknown XML"); } engine.ch = ch; return(engine); }
public void IID030_30() { XmlDocument request = new XmlDocument(); XmlDocument response = new XmlDocument(); XmlDocument policy1 = new XmlDocument(); XmlDocument policy2 = new XmlDocument(); request.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IID030Request.xml")); response.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IID030Response.xml")); policy1.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IID030Policy1.xml")); policy2.Load(Path.Combine(Xacml30TestsCases.TestCasePath, "IID030Policy2.xml")); var serialize = new Xacml30ProtocolSerializer(); XacmlContextRequest requestData; XacmlContextResponse responseData; XacmlPolicy policy1Data; XacmlPolicy policy2Data; using (XmlReader reader = XmlReader.Create(new StringReader(request.OuterXml))) { requestData = serialize.ReadContextRequest(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(response.OuterXml))) { responseData = serialize.ReadContextResponse(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(policy1.OuterXml))) { policy1Data = serialize.ReadPolicy(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(policy2.OuterXml))) { policy2Data = serialize.ReadPolicy(reader); } var policySet = new XacmlPolicySet(Xacml10Constants.PolicyCombiningAlgorithms.OnlyOneApplicable, new XacmlTarget()); // TODO: PolicyCombiningAlgorithms policySet.Policies.Add(policy1Data); policySet.Policies.Add(policy2Data); EvaluationEngine engine = new EvaluationEngine30(policySet); XacmlContextResponse evaluatedResponse = engine.Evaluate(requestData, request); XacmlResponseAssert(responseData, evaluatedResponse); }
public void RunOfficialTestsCheckResult_Geo(XmlDocument policy, XmlDocument request, XmlDocument response) { var serialize = new Xacml30ProtocolSerializer(); XacmlContextRequest requestData; XacmlContextResponse responseData; using (XmlReader reader = XmlReader.Create(new StringReader(request.OuterXml))) { requestData = serialize.ReadContextRequest(reader); } using (XmlReader reader = XmlReader.Create(new StringReader(response.OuterXml))) { responseData = serialize.ReadContextResponse(reader); } EvaluationEngine engine = EvaluationEngineFactory.Create(policy, null); XacmlContextResponse evaluatedResponse = engine.Evaluate(requestData, request); Assert.AreEqual(responseData.Results.First().Decision, evaluatedResponse.Results.First().Decision, evaluatedResponse.Results.First().Status.StatusMessage); Assert.True(evaluatedResponse.Results.First().Obligations.Count == responseData.Results.First().Obligations.Count); }
public static EvaluationEngine Create(XmlReader reader, IXacmlPolicyRepository ch) { Contract.Requires<ArgumentNullException>(reader != null); EvaluationEngine engine; if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml10Constants.Namespaces.Policy)) { Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicy(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml10Constants.Namespaces.Policy)) { Xacml10ProtocolSerializer serializer = new Xacml10ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicySet(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml20Constants.Namespaces.Policy)) { Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicy(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml20Constants.Namespaces.Policy)) { Xacml20ProtocolSerializer serializer = new Xacml20ProtocolSerializer(); engine = new EvaluationEngine(serializer.ReadPolicySet(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.Policy, Xacml30Constants.Namespaces.Policy)) { Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer(); engine = new EvaluationEngine30(serializer.ReadPolicy(reader)); } else if (reader.IsStartElement(XacmlConstants.ElementNames.PolicySet, Xacml30Constants.Namespaces.Policy)) { Xacml30ProtocolSerializer serializer = new Xacml30ProtocolSerializer(); engine = new EvaluationEngine30(serializer.ReadPolicySet(reader)); } else { throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new XmlException("Unknown XML")); } engine.ch = ch; return engine; }