コード例 #1
0
        public void TestIgnoreRestrictionsOnInternalEmailOn()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(ignoreInternalDocumentRestrictionsOptions);

            SortedList<int, IAction> internalActions = template[TemplatePolicy.DocumentRestrictions, ChannelType.SMTP, Routing.Internal];
            SortedList<int, IAction> externalActions = template[TemplatePolicy.DocumentRestrictions, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, internalActions.Count, "Expected 1 internal action");
            Assert.AreEqual(1, externalActions.Count, "Expected 1 external action");

            DocumentRestrictionsPolicy drp = new DocumentRestrictionsPolicy(template, options);
            drp.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);

            PolicyTemplate modifedTemplate = new PolicyTemplate();
            modifedTemplate.Load(myPolicy);

            internalActions = modifedTemplate[TemplatePolicy.DocumentRestrictions, ChannelType.SMTP, Routing.Internal];
            externalActions = modifedTemplate[TemplatePolicy.DocumentRestrictions, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(0, internalActions.Count, "Expected 0 internal actions");
            Assert.AreEqual(1, externalActions.Count, "Expected 1 external actions");

            template.Close();
            modifedTemplate.Close();
            
            System.IO.File.Delete(runtimePolicy);
            System.IO.File.Delete(myPolicy);
        }
コード例 #2
0
ファイル: TestAlertPolicy.cs プロジェクト: killbug2004/WSProf
        public void TestApplyConditions()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(optionsxml);

            ContentPolicyReader cpr = new ContentPolicyReader();
            List<ContentRule> contentRules = cpr.Read(contentPolicy);

            AlertPolicy alertPolicy = new AlertPolicy(template, options, contentRules);
            alertPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);
            template.Close();
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
        }
コード例 #3
0
ファイル: TestPdfPolicy.cs プロジェクト: killbug2004/WSProf
        public void TestNoInternalExternal()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(noPdf);

            SortedList<int, IAction> internalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal];
            SortedList<int, IAction> externalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, internalActions.Count);
            Assert.AreEqual(1, externalActions.Count);

            PdfPolicy pdfPolicy = new PdfPolicy(template, options);
            pdfPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);

            PolicyTemplate modifedTemplate = new PolicyTemplate();
            modifedTemplate.Load(myPolicy);

            try
            {
                IPolicy policy = modifedTemplate[TemplatePolicy.PdfPolicy];
                Assert.IsTrue(false, "The policy should have been removed");
            }
            catch (System.IndexOutOfRangeException)
            {
            }


            modifedTemplate.Close();

            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
        }
コード例 #4
0
        public void TestLoadExportedContentPolicyPolicy()
        {
            OptionsExporter exporter = new OptionsExporter();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();


            exporter.Export(optionsxml, contentPolicy, myPolicy, runtimePolicy, riskRatingsPath);
            System.IO.FileInfo fi1 = new System.IO.FileInfo(runtimePolicy);
            System.IO.FileInfo fi2 = new System.IO.FileInfo(myPolicy);


            Assert.IsTrue(fi1.Length > 0);
            Assert.IsTrue(fi2.Length > 0);


            PolicyTemplate template = new PolicyTemplate();
            template.Load(myPolicy);

            template.Close();
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
        }
コード例 #5
0
ファイル: TestPdfPolicy.cs プロジェクト: killbug2004/WSProf
        public void TestNoExternal()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(pdfInternal);

            SortedList<int, IAction> internalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal];
            SortedList<int, IAction> externalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, internalActions.Count);
            Assert.AreEqual(1, externalActions.Count);

            PdfPolicy pdfPolicy = new PdfPolicy(template, options);
            pdfPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);


            PolicyTemplate modifedTemplate = new PolicyTemplate();
            modifedTemplate.Load(myPolicy);

            internalActions = modifedTemplate[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal];
            externalActions = modifedTemplate[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, internalActions.Count);
            Assert.AreEqual(0, externalActions.Count);


            modifedTemplate.Close();

            System.IO.File.Delete(runtimePolicy);
            System.IO.File.Delete(myPolicy);
        }
コード例 #6
0
ファイル: TestPdfPolicy.cs プロジェクト: killbug2004/WSProf
        public void TestAllowOverride()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(pdfInternalExternal);

            IAction internalAction = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal].Values[0];
            IAction externalAction = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External].Values[0];

            IPolicyObjectCollection<IDataElement> dataElements = internalAction.DataElements;
            int allowOverride = 0;
            int total = dataElements.Count;
            foreach (IDataElement dataElement in dataElements)
            {
                if (string.Compare(dataElement["allowoverride"].Value, "true", true) == 0)
                {
                    allowOverride++;
                }
            }

            Option allowPdfOverride = options.Find(Sections.GeneralPolicy, "{b22927e1-afce-4081-8ebf-3187ee1bfc15}");
            allowPdfOverride.Value = "0";

            PdfPolicy pdfPolicy = new PdfPolicy(template, options);
            pdfPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);
            
            PolicyTemplate modifedTemplate = new PolicyTemplate();
            modifedTemplate.Load(myPolicy);

            internalAction = modifedTemplate[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal].Values[0];
            dataElements = internalAction.DataElements;
            int modifedAllowOverride = 0;
            int modifiedTotal = dataElements.Count;
            foreach (IDataElement dataElement in dataElements)
            {
                if (string.Compare(dataElement["allowoverride"].Value, "true", false) == 0)
                {
                    modifedAllowOverride++;
                }
            }

            modifedTemplate.Close();
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);

            Assert.AreEqual(total, modifiedTotal, "The number of DataElements are not the same");
            Assert.AreEqual(0, modifedAllowOverride, "All the DataElement's allowoverride attributes should have been set to false");
        }
コード例 #7
0
ファイル: TestClean.cs プロジェクト: killbug2004/WSProf
        public void TestApply()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);
			Options options = new Options(optionsxml);

            SortedList<int, IAction> internalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.Internal];
            SortedList<int, IAction> externalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(2, internalActions.Count, "Unexpected number of actions");
            Assert.AreEqual(2, externalActions.Count, "Unexpected number of actions");

            IAction externalCleanAction = externalActions.Values[1];

			IDataElement deTrackChanges = externalCleanAction.DataElements[17];
			IDataElement deComments = externalCleanAction.DataElements[18];

            IDataItem diTrackChanges = deTrackChanges.Data as IDataItem;
            IDataItem diComments = deComments.Data as IDataItem;

            bool originalTrackChangesValue = (bool)diTrackChanges.Value;
            bool originalCommentsValue = (bool)diComments.Value;

            MetadataSecurityRatings msr = new MetadataSecurityRatings();
            
            CleanPolicy cleanPolicy = new CleanPolicy(template, options, msr.Read(riskRatingsPath));
            cleanPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);

            PolicyTemplate modifiedTemplate = new PolicyTemplate();
            modifiedTemplate.Load(myPolicy);

			internalActions = modifiedTemplate[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.Internal];
			externalActions = modifiedTemplate[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, externalActions.Count, "Unexpected number of actions");

			externalCleanAction = externalActions.Values[0];

			deTrackChanges = externalCleanAction.DataElements[17];
			deComments = externalCleanAction.DataElements[18];

			diTrackChanges = deTrackChanges.Data as IDataItem;
			diComments = deComments.Data as IDataItem;

			bool modifiedTrackChangesValue = (bool)diTrackChanges.Value;
			bool modifiedCommentsValue = (bool)diComments.Value;

			Assert.AreNotEqual(modifiedCommentsValue, originalCommentsValue);
			Assert.AreNotEqual(modifiedTrackChangesValue, originalTrackChangesValue);

			cleanPolicy = null;
			template.Close();
            modifiedTemplate.Close();
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
        }
コード例 #8
0
ファイル: TestClean.cs プロジェクト: killbug2004/WSProf
		public void TestApplyAllowOptionOverride_False()
		{
			PolicyTemplate template = new PolicyTemplate();
			template.Load(policyFile);
			Options options = new Options(noOverrideAllowed);

			MetadataSecurityRatings msr = new MetadataSecurityRatings();

			CleanPolicy cleanPolicy = new CleanPolicy(template, options, msr.Read(riskRatingsPath));
			cleanPolicy.Apply();

			string runtimePolicy = System.IO.Path.GetTempFileName();
			string myPolicy = System.IO.Path.GetTempFileName();
			template.Save(myPolicy, runtimePolicy);

			PolicyTemplate modifiedTemplate = new PolicyTemplate();
			modifiedTemplate.Load(myPolicy);

			SortedList<int, IAction> internalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.Internal];
			SortedList<int, IAction> externalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];

			Assert.AreEqual(1, internalActions.Count, "Unexpected number of actions");
			Assert.AreEqual(1, externalActions.Count, "Unexpected number of actions");

			IAction internalCleanAction = internalActions.Values[0];
			IAction externalCleanAction = externalActions.Values[0];

			for (int i = 0; i < internalCleanAction.DataElements.Count; i++)
			{ 
				IDataElement de = internalCleanAction.DataElements[i];
				if (string.Compare(de.DisplayName.Value, "Apply to All", true) == 0 ||
					string.Compare(de.DisplayName.Value, "Allow Override", true) == 0)
				{
					Assert.IsTrue(de["allowoverride"].Value == "True");	
				}
				else
					Assert.IsTrue(de["allowoverride"].Value == "False");
			}

			for (int i = 0; i < externalCleanAction.DataElements.Count; i++)
			{
				IDataElement de = externalCleanAction.DataElements[i];
				if (string.Compare(de.DisplayName.Value, "Apply to All", true) == 0 ||
					string.Compare(de.DisplayName.Value, "Allow Override", true) == 0)
				{
					Assert.IsTrue(de["allowoverride"].Value == "True");
				}
				else
					Assert.IsTrue(de["allowoverride"].Value == "False");
			}

			modifiedTemplate.Close();
			System.IO.File.Delete(myPolicy);
			System.IO.File.Delete(runtimePolicy);
		}
コード例 #9
0
ファイル: TestClean.cs プロジェクト: killbug2004/WSProf
		public void TestApply_InkAnnotations()
		{
			PolicyTemplate template = new PolicyTemplate();
			template.Load(policyFile);
			Options options = new Options(options3xml);

			SortedList<int, IAction> internalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.Internal];
			SortedList<int, IAction> externalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];

			Assert.AreEqual(2, internalActions.Count, "Unexpected number of actions");
			Assert.AreEqual(2, externalActions.Count, "Unexpected number of actions");

			IAction internalCleanAction = internalActions.Values[0];
			IAction externalCleanAction = externalActions.Values[0];

			IDataElement deIntInkAnnotations = internalCleanAction.DataElements[22];
			IDataElement deExtInkAnnotations = externalCleanAction.DataElements[22];

			IDataItem intInkAnnotations = deIntInkAnnotations.Data as IDataItem;
			IDataItem extInkAnnotations = deExtInkAnnotations.Data as IDataItem;

			bool originalInternalValue = (bool)intInkAnnotations.Value;
			bool originalExternalValue = (bool)extInkAnnotations.Value;

			MetadataSecurityRatings msr = new MetadataSecurityRatings();

			CleanPolicyForTests cleanPolicy = new CleanPolicyForTests(template, options, msr.Read(riskRatingsPath), true);
			cleanPolicy.Apply();

			string runtimePolicy = System.IO.Path.GetTempFileName();
			string myPolicy = System.IO.Path.GetTempFileName();
			template.Save(myPolicy, runtimePolicy);

			PolicyTemplate modifiedTemplate = new PolicyTemplate();
			modifiedTemplate.Load(myPolicy);

			internalActions = modifiedTemplate[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.Internal];
			externalActions = modifiedTemplate[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];

			Assert.AreEqual(1, internalActions.Count, "Unexpected number of actions");
			Assert.AreEqual(1, externalActions.Count, "Unexpected number of actions");

			internalCleanAction = internalActions.Values[0];
			externalCleanAction = externalActions.Values[0];

			deIntInkAnnotations = internalCleanAction.DataElements[22];
			deExtInkAnnotations = externalCleanAction.DataElements[22];

			intInkAnnotations = deIntInkAnnotations.Data as IDataItem;
			extInkAnnotations = deExtInkAnnotations.Data as IDataItem;

			bool modifiedInternalValue = (bool)intInkAnnotations.Value;
			bool modifiedExternalValue = (bool)extInkAnnotations.Value;

			Assert.AreEqual(originalInternalValue, modifiedInternalValue, "The value should be the same");
			Assert.AreNotEqual(originalExternalValue, modifiedExternalValue, "The value should not be the same");

			template.Close();
			modifiedTemplate.Close();
			System.IO.File.Delete(myPolicy);
			System.IO.File.Delete(runtimePolicy);
		}