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