Esempio n. 1
0
        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);
        }
Esempio n. 2
0
	    private void ExportDefaultPolicy()
	    {
	        string tempPolicyfile = GetPolicyTemplateFromResources();

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

	        MetadataSecurityRatings msr = new MetadataSecurityRatings();
	        Dictionary<RiskRating, List<string>> riskRatings = msr.Read(MetadataSecurityRatingsFile);
	        Dictionary<RiskRating, List<string>> PDFriskRatings = msr.Read(PDFMetadataSecurityRatingsFile);

	        if (!HandleFootnotesAsHiddenData())
	        {
	            riskRatings = RemoveFootnoteItemFromLowRiskRatingCollection(riskRatings);
	        }

	        List<IPolicyAction> policyActions = new List<IPolicyAction>();
	        policyActions.Add(new PdfPolicy(template));
	        policyActions.Add(new CleanPolicy(template, riskRatings));
	        policyActions.Add(new PDFCleanPolicy(template, PDFriskRatings));
	        policyActions.Add(new ZipPolicy(template));
	        //policyActions.Add(new DocumentRestrictionsPolicy(template));
	        policyActions.Add(new DetectWorkshareStyles(template));

	        if (ReportOnContentPolicyViolations())
	        {
	            ContentPolicyReader cpr = new ContentPolicyReader();
	            List<ContentRule> contentRules = cpr.Read(ContentPolicyFile);
	            policyActions.Add(new AlertPolicy(template, contentRules));
	        }
	        else
	        {
	            template.RemovePolicy(TemplatePolicy.AlertPolicy);
	        }

	        bool hideOptionsDlgForInternal = HideEmailOptionsDlg(true /*internal routing*/);
	        bool hideOptionsDlgForExternal = HideEmailOptionsDlg(false /*external routing*/);

	        foreach (IPolicyAction policyAction in policyActions)
	        {
	            if (hideOptionsDlgForInternal)
	            {
	                MakeAllActionsTransparent(policyAction.InternalActions, true);
	            }

	            if (hideOptionsDlgForExternal)
	            {
	                MakeAllActionsTransparent(policyAction.ExternalActions, false);
	            }

	            policyAction.Apply();
	        }

	        template.Save(PolicyFile, RuntimePolicyFile);
	    }
Esempio n. 3
0
        public void TestCleanConditions()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);
            Options options = new Options(optionsxml);

            MetadataSecurityRatings msr = new MetadataSecurityRatings();

            Dictionary<RiskRating, List<string>> riskRatings = msr.Read(riskRatingsPath);
            List<IPolicyAction> policyActions = new List<IPolicyAction>();
            policyActions.Add(new CleanPolicy(template, options, riskRatings));

            foreach (IPolicyAction policyAction in policyActions)
            {
                policyAction.Apply();
            }

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

            IPolicy cleanPolicy = pt[TemplatePolicy.CleaningPolicy];
            List<IPolicyObject> conditionGroups =  pt.GetConditions(cleanPolicy);

            IConditionGroup conditionGroup = conditionGroups[0] as IConditionGroup;
            foreach (ICondition condition in conditionGroup.Conditions)
            {
                string name = condition.Name.Value;

                IDataSource ds = condition.DataLeft.Data as IDataSource;
                IDataMethod dm = ds.Method;
                IPolicyObjectCollection<IParameter> parameters = dm.Parameters;

                if (parameters.Count != 4)
                    throw new System.IndexOutOfRangeException("Unexpected number of parameters for condition");

                PolicyObjectCollection<IDataItem> items = parameters[3].Value.Data as PolicyObjectCollection<IDataItem>;

                foreach (IDataItem di in items)
                {
                    string diItem = di.Value as string;
                    if (string.Compare(diItem, "Footnote", false) == 0)
                    {
                        System.IO.File.Delete(myPolicy);
                        System.IO.File.Delete(runtimePolicy);
                        return;
                    }
                }
            }
            
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
            Assert.Fail("Should have found Footnote in the condition parameter list");

        }
Esempio n. 4
0
		public void TestApplyHiddenDataExclusions()
		{
			List<string> exclusions = new List<string>();
			exclusions.Add("ExcludeCustomProperties");
			exclusions.Add("ExcludeFieldCodesAuthorInformation");
			exclusions.Add("ExcludeFieldCodesDocumentInformation");
			exclusions.Add("ExcludeFieldCodesFormFields");
			exclusions.Add("ExcludeFieldCodesIncludeFields");
			exclusions.Add("ExcludeFieldCodesIndexTables");
			exclusions.Add("ExcludeFieldCodesNumbering");
			exclusions.Add("ExcludeFieldCodesHyperlinks");
			exclusions.Add("ExcludeFieldCodesLinks");
			exclusions.Add("ExcludeFieldCodesReferences");
			exclusions.Add("ExcludeFieldCodesEquationsFormulas");
			exclusions.Add("ExcludeFieldCodesDocumentAutomation");
			exclusions.Add("ExcludeDocumentVariables");
			exclusions.Add("ExcludeFieldCodes");
			exclusions.Add("DeleteFieldCodes");
            
			PolicyTemplate template = new PolicyTemplate();
			template.Load(policyFile);
			Options options = new Options(noFieldExclusions);

			SortedList<int, IAction> externalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];
			IAction externalClean = externalActions.Values[0];
			IDataItem diExecute = externalClean.DataElements[1].Data as IDataItem;
			bool originalExecute = (bool)diExecute.Value;

			Assert.IsTrue(originalExecute);

			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);

			externalActions = modifiedTemplate[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];
			IAction externalAction = externalActions.Values[0];
			bool exclusionsFound = false;
			bool foundFieldCodesIndexAndTables = false;
			for(int i = 0; i < externalAction.DataElements.Count; i++)
			{
				IDataItem di = externalAction.DataElements[i].Data as IDataItem;
				string name = di.Name.Value;
				if (string.IsNullOrEmpty(name))
					continue;

				foreach(string s in exclusions)
				{
					if (string.Compare(s, name, true) == 0)
					{
						exclusionsFound = true;
						string value = di.Value.ToString();
						if (string.Compare(name, "ExcludeFieldCodesIndexTables", true) == 0)
						{
							foundFieldCodesIndexAndTables = true;
							Assert.IsTrue(string.Compare(value, "true", true) == 0, name + " - Metadata exclusions should be set true");
							break;
						}
						else if ((string.Compare(name, "ExcludeCustomProperties", true) == 0))
                        {
                            Assert.IsTrue(string.Compare(value, "Custom One", true) == 0, name + " - Metadata exclusions should be set to empty string");
                        }
                        else if ((string.Compare(name, "ExcludeDocumentVariables", true) == 0) ||
                            (string.Compare(name, "ExcludeFieldCodes", true) == 0) ||
                            (string.Compare(name, "DeleteFieldCodes", true) == 0))
                        {
                            Assert.IsTrue(value.Length == 0, name + " - Metadata exclusions should be set to empty string");
                        }
                        else
						{
							Assert.IsTrue(string.Compare(value, "false", true) == 0, name + " - Metadata exclusions should NOT be set to true");
							break;
						}
					}
				}
			}
			Assert.IsTrue(exclusionsFound, "We didn't find any exclusions on the action - that is wrong");
			Assert.IsTrue(foundFieldCodesIndexAndTables, "We didn't find ExcludeFieldCodesIndexTables on the action - that is wrong");
			System.IO.File.Delete(runtimePolicy);
			System.IO.File.Delete(myPolicy);
		}
Esempio n. 5
0
		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);
		}
Esempio n. 6
0
        public void TestApplySkipCleaningExternal()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);
            Options options = new Options(skipAllCleaningxml);

            SortedList<int, IAction> externalActions = template[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];
            IAction externalClean = externalActions.Values[0];
            IDataItem diExecute = externalClean.DataElements[1].Data as IDataItem;
            bool originalExecute = (bool)diExecute.Value;

            Assert.IsTrue(originalExecute);

            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);

            externalActions = modifiedTemplate[TemplatePolicy.CleaningPolicy, ChannelType.SMTP, Routing.External];
            IAction externalAction = externalActions.Values[0];
            IDataItem diModifiedExecute = externalAction.DataElements[1].Data as IDataItem;
            Assert.IsTrue((System.Convert.ToString(diExecute.Value) == "True"));
            Assert.IsTrue((System.Convert.ToString(diModifiedExecute.Value) == "True")); // True by default.

            System.IO.File.Delete(runtimePolicy);
            System.IO.File.Delete(myPolicy);
        }
Esempio n. 7
0
		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);
		}