Beispiel #1
0
        public void IIIF003()
        {
            string[] files = new string[] { "2.IIIF003Policy.xml", "2.IIIF003Request.xml", "2.IIIF003Response.xml" };
            Assert.AreEqual(files.Length, 3); FileInfo policyFile = new FileInfo(Consts.Path + files[0]);
            FileInfo requestFile  = new FileInfo(Consts.Path + files[1]);
            FileInfo responseFile = new FileInfo(Consts.Path + files[2]);

            using (FileStream fs = new FileStream(policyFile.FullName, FileMode.Open, FileAccess.Read))
                using (FileStream fs1 = new FileStream(requestFile.FullName, FileMode.Open, FileAccess.Read))
                    using (FileStream fs2 = new FileStream(responseFile.FullName, FileMode.Open, FileAccess.Read))
                    {
                        // Load Policy
                        PolicyDocument policyDocument = (PolicyDocument)PolicyLoader.LoadPolicyDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadOnly);
                        // Load Request
                        ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);
                        // Load ResponseElement
                        ContextDocumentReadWrite responseDocument = ContextLoader.LoadContextDocument(fs2, XacmlVersion.Version20);
                        EvaluationEngine         engine           = new EvaluationEngine();

                        ResponseElement res = engine.Evaluate(policyDocument, (ContextDocument)requestDocument);
                        Assert.AreEqual(((ResultElement)res.Results[0]).Obligations.Count, ((ResultElement)responseDocument.Response.Results[0]).Obligations.Count);
                        Assert.AreEqual(responseDocument.Response.Results.Count, res.Results.Count);
                        Assert.IsTrue(((ResultElement)res.Results[0]).Decision.ToString() == ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), string.Format("Decission incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), ((ResultElement)res.Results[0]).Decision.ToString()));
                        Assert.IsTrue(((ResultElement)res.Results[0]).Status.StatusCode.Value == ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, String.Format("Status incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, ((ResultElement)res.Results[0]).Status.StatusCode.Value));
                    }
        }
Beispiel #2
0
        public void TestMessageQueue()
        {
            var queue = String.Format("FormatName:DIRECT=OS:{0}\\policy_ipm", GeneralUtility.MachineName);

            var loaderXml = XmlUtility.LoadFileText(@"C:\Documents and Settings\john.gwynn\My Documents\policyLoad.xml");

            Test.Assert.IsNotEmpty(loaderXml, "policy loader is empty!");

            var loader = new PolicyLoader(loaderXml);

            Test.Assert.IsNotEmpty(loader.Action, "Loader failed!");

            Console.WriteLine(String.Format("PolicyLoader.Action = {0}", loader.Action));
            Console.WriteLine(String.Format("PolicyLoader.ClientCode = {0}", loader.ClientCode));
            Console.WriteLine(String.Format("PolicyLoader.CreatTime = {0}", loader.CreatTime));
            Console.WriteLine(String.Format("PolicyLoader.FileName = {0}", loader.FileName));
            Console.WriteLine(String.Format("PolicyLoader.FileTranLogId = {0}", loader.FileTranLogId));
            Console.WriteLine(String.Format("PolicyLoader.Sequence = {0}", loader.Sequence));
            Console.WriteLine(String.Format("PolicyLoader.Status = {0}", loader.Status));
            Console.WriteLine("***Sending Message....");
            var message = loader.ToXml();

            Test.Assert.IsTrue(MessageQueue.SendMessage(queue, message, loader.Name), "send failed!");

            /*
             * Console.WriteLine("***Retrieving Message....");
             * string results = MessageQueue.GetNextMessage(queue);
             * Test.Assert.IsTrue(results.Length > 0, "Nothing was returned");
             * Test.Assert.IsTrue(message.Equals(results),"results don't compare...");
             * Console.WriteLine(results);
             */
        }
Beispiel #3
0
        /// <summary>
        /// NUNIT Tests the policy loader.
        /// </summary>
        [Test][Ignore] public void TestPolicyLoader()
        {
            var doc = new XmlDocument();

            doc.Load("C:\\Documents and Settings\\john.gwynn\\My Documents\\policyLoad.xml");

            string xml = doc.OuterXml;

            Assert.IsNotEmpty(xml, "xml is empty!");

            var loader = new PolicyLoader(xml);

            Assert.IsNotEmpty(loader.Action, "Loader failed!");

            Console.WriteLine(String.Format("PolicyLoader.Action = {0}", loader.Action));
            Console.WriteLine(String.Format("PolicyLoader.ClientCode = {0}", loader.ClientCode));
            Console.WriteLine(String.Format("PolicyLoader.CreatTime = {0}", loader.CreatTime));
            Console.WriteLine(String.Format("PolicyLoader.FileName = {0}", loader.FileName));
            Console.WriteLine(String.Format("PolicyLoader.FileTranLogId = {0}", loader.FileTranLogId));
            Console.WriteLine(String.Format("PolicyLoader.Sequence = {0}", loader.Sequence));
            Console.WriteLine(String.Format("PolicyLoader.Status = {0}", loader.Status));

            string results = loader.ToXml();

            Assert.IsNotEmpty(results, "toXml failed!");

            Console.WriteLine(results);
        }
Beispiel #4
0
		public void TestGetChannels()
		{
			PolicyLoader policyLoader = new PolicyLoader();
			policyLoader.LoadRuntimePolicy("Pro5.test");
			foreach (IPolicy policy in policyLoader.Policies)
			{
				List<IPolicyChannel> channels = policyLoader.GetChannels(policy);
				Assert.IsTrue(channels.Count == 2);
			}
		}
Beispiel #5
0
		public void TestIsLDAPRouting()
		{
			PolicyLoader policyLoader = new PolicyLoader();
			policyLoader.LoadRuntimePolicy("Pro5.test");

			foreach (IPolicy policy in policyLoader.Policies)
			{
				List<IPolicyChannel> channels = policyLoader.GetChannels(policy);
				foreach (IPolicyChannel policyChannel in channels)
				{
					Assert.IsFalse(policyLoader.IsLDAPRouting(policyChannel), "There should be no LDAP routing in Pro5.test policies");
				}
			}
		}
Beispiel #6
0
        public async Task TestLoadFromGit()
        {
            ObjectIndex index = new ObjectIndex();

            string[] urls = new string[]
            {
                "https://raw.githubusercontent.com/azure-ad-b2c/samples/master/policies/change-sign-in-name/policy/TrustFrameworkExtensions.xml",
                "https://raw.githubusercontent.com/azure-ad-b2c/samples/master/policies/change-sign-in-name/policy/TrustFrameworkBase.xml",
                "https://raw.githubusercontent.com/azure-ad-b2c/samples/master/policies/change-sign-in-name/policy/SignUpOrSignin.xml",
                "https://raw.githubusercontent.com/azure-ad-b2c/samples/master/policies/change-sign-in-name/policy/ChangeSignInName.xml"
            };
            var policies = await PolicyLoader.LoadFromUrls(index, urls);

            Assert.IsTrue(policies.Count > 0);
            Assert.IsNotNull(index.GetPolicyReference("B2C_1A_ChangeSignInName"));
            Assert.IsNotNull(index.GetPolicyReference("B2C_1A_ChangeSignInName").RelyingParty);
            Assert.IsNotNull(index.GetPolicyReference("B2C_1A_ChangeSignInName").RelyingParty.DefaultUserJourney);
        }
Beispiel #7
0
        public void IIA001()
        {
            string[]      files    = new string[] { "2.IIA001Policy.xml" };
            string        tempFile = Path.GetTempFileName();
            XmlTextWriter tw       = new XmlTextWriter(tempFile, System.Text.Encoding.ASCII);

            tw.Namespaces = true;
            tw.Formatting = Formatting.Indented;

            FileInfo policyFile = new FileInfo(Consts.Path + files[0]);

            using (FileStream fs = new FileStream(policyFile.FullName, FileMode.Open, FileAccess.Read))
            {
                // Load Policy
                PolicyDocumentReadWrite policyDocument = PolicyLoader.LoadPolicyDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadWrite);

                if (policyDocument.Policy == null)
                {
                    policyDocument.PolicySet.Description = "UnitTest!!";
                }
                else
                {
                    policyDocument.Policy.Description = "UnitTest!!";
                }
                policyDocument.WriteDocument(tw);
                tw.Close();

                using (FileStream fs1 = new FileStream(tempFile, FileMode.Open, FileAccess.Read))
                {
                    PolicyDocument newPd = (PolicyDocument)PolicyLoader.LoadPolicyDocument(fs1, XacmlVersion.Version20, DocumentAccess.ReadOnly);

                    if (newPd.Policy == null)
                    {
                        Assert.AreEqual(newPd.PolicySet.Description, policyDocument.PolicySet.Description);
                    }
                    else
                    {
                        Assert.AreEqual(newPd.Policy.Description, policyDocument.Policy.Description);
                    }
                }
            }
        }
Beispiel #8
0
		public void TestCountActions()
		{
			PolicyLoader policyLoader = new PolicyLoader();
			policyLoader.LoadRuntimePolicy("Pro5.test");

			int ex = 0;
			int In = 0;
			foreach (IPolicy policy in policyLoader.Policies)
			{
				List<IPolicyChannel> channels = policyLoader.GetChannels(policy);
				foreach (IPolicyChannel policyChannel in channels)
				{
					ex += policyLoader.GetCountExternalActions(policyChannel);
					In += policyLoader.GetCountInternalActions(policyChannel);
				}
			}

			Assert.AreEqual(20, ex);
			Assert.AreEqual(0, In);
		}