public void TestNoInternal() { PolicyTemplate template = new PolicyTemplate(); template.Load(policyFile); Options options = new Options(pdfExternal); 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(0, internalActions.Count); Assert.AreEqual(1, externalActions.Count); modifedTemplate.Close(); System.IO.File.Delete(runtimePolicy); System.IO.File.Delete(myPolicy); }
public void TestIgnoreRestrictionsOnInternalEmailOff() { PolicyTemplate template = new PolicyTemplate(); template.Load(policyFile); Options options = new Options(applyInternalDocumentRestrictionsOptions); 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(1, internalActions.Count, "Expected 1 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); }
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 ZipPolicy(PolicyTemplate template) : base (template) { m_internalZipPolicy = Template[TemplatePolicy.InternalZipPolicy]; m_externalZipPolicy = Template[TemplatePolicy.ExternalZipPolicy]; m_internalZipAction = Template[TemplatePolicy.InternalZipPolicy, ChannelType.SMTP, Routing.Internal].Values[0]; m_externalZipAction = Template[TemplatePolicy.ExternalZipPolicy, ChannelType.SMTP, Routing.External].Values[0]; }
public CleanPolicy(PolicyTemplate template, Dictionary<RiskRating, List<string>> riskRatings) : base(template) { m_internalBinaryClean = GetCleanAction(true, false); m_externalBinaryClean = GetCleanAction(true, true); m_internalClean = GetCleanAction(false, false); m_externalClean = GetCleanAction(false, true); m_RiskRatings = riskRatings; }
public void TestInternalIsRemoved() { OptionsExporter exporter = new OptionsExporter(); string runtimePolicy = System.IO.Path.GetTempFileName(); string myPolicy = System.IO.Path.GetTempFileName(); exporter.Export(internalExternalZipDisabled, contentPolicy, myPolicy, runtimePolicy, riskRatingsPath); PolicyTemplate modifedTemplate = new PolicyTemplate(); modifedTemplate.Load(myPolicy); IPolicy policy = modifedTemplate[TemplatePolicy.InternalZipPolicy]; }
public void TestGetChannelActions() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); PolicySetItem psi = template.PolicySet; IPolicySet policyset = psi.Data; IPolicy internalZipPolicy = policyset.Policies[1]; IPolicyChannel internalSmtpChannel = template.GetChannels(internalZipPolicy)[0]; SortedList<int, IAction> internalActions = template.GetChannelActions(internalSmtpChannel, Routing.Internal); SortedList<int, IAction> externalActions = template.GetChannelActions(internalSmtpChannel, Routing.External); Assert.AreEqual(0, externalActions.Count); Assert.AreEqual(1, internalActions.Count); }
public void TestGetChannels() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); PolicySetItem psi = template.PolicySet; IPolicySet policyset = psi.Data; IPolicyObjectCollection<IPolicy> policies = policyset.Policies; IPolicy internalZipPolicy = policies[1]; List<IPolicyChannel> channels = template.GetChannels(internalZipPolicy); Assert.AreEqual(4, channels.Count); Assert.AreEqual("SMTP Channel", channels[0].Name.Value); Assert.AreEqual("HTTP Channel", channels[1].Name.Value); Assert.AreEqual("Active Content Channel", channels[2].Name.Value); Assert.AreEqual("Removeable Device Channel", channels[3].Name.Value); }
public void TestGetAction() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); PolicySetItem psi = template.PolicySet; IPolicySet policyset = psi.Data; IPolicy internalZipPolicy = policyset.Policies[1]; IPolicyChannel internalSmtpChannel = template.GetChannels(internalZipPolicy)[0]; SortedList<int, IAction> internalActions = template.GetChannelActions(internalSmtpChannel, Routing.Internal); Assert.AreEqual(1, internalActions.Count); IAction internalZipAction = internalActions.Values[0]; Assert.AreEqual(14002, internalZipAction.Precedence); Assert.AreEqual("ZIP - Microsoft Office Documents", internalZipAction.Name.Value); Assert.AreEqual("Workshare.Policy.Actions.ZipUserAction", internalZipAction.Class); }
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); }
public void TestLoadTemplate() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); PolicySetItem psi = template.PolicySet; IPolicySet policyset = psi.Data; IPolicyObjectCollection<IPolicy> policies = policyset.Policies; Assert.AreEqual(10, policies.Count); Assert.AreEqual(TemplatePolicy.PdfPolicy, policies[0].Name.Value); Assert.AreEqual(TemplatePolicy.InternalZipPolicy, policies[1].Name.Value); Assert.AreEqual(TemplatePolicy.AlertPolicy, policies[2].Name.Value); Assert.AreEqual(TemplatePolicy.ExternalZipPolicy, policies[3].Name.Value); IPolicy internalZipPolicy = policies[1]; List<IPolicyObject> conditions = template.GetConditions(internalZipPolicy); Assert.IsTrue(conditions.Count == 1); Assert.IsTrue(conditions[0] is IConditionGroup); }
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); }
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); }
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"); }
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); }
public PDFCleanPolicy(PolicyTemplate template, Dictionary<RiskRating, List<string>> riskRatings) : base(template, riskRatings) { m_internalClean = GetCleanAction(false); m_externalClean = GetCleanAction(true); }
public PolicyAction(PolicyTemplate template) { m_template = template; }
public void TestModifyActionProperties() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); IAction zipAction = template[TemplatePolicy.InternalZipPolicy, ChannelType.SMTP, Routing.Internal].Values[0]; IDataItem value1 = zipAction.DataElements[new Guid("{252635eb-d7ff-44be-bc43-eb35356cebb1}")].Data as IDataItem; value1.Value = true; bool orginal = (bool)(value1.Value); Options options = new Options(optionsxml); ZipPolicy zipPolicy = new ZipPolicy(template, options); zipPolicy.Apply(); IDataItem value2 = zipAction.DataElements[new Guid("{252635eb-d7ff-44be-bc43-eb35356cebb1}")].Data as IDataItem; bool modifed = (bool)(value2.Value); Assert.AreNotEqual(modifed, orginal, "The data element's value should have been modified"); }
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"); }
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 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 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); }
public void TestSave() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); Options options = new Options(optionsxml); ZipPolicy zipPolicy = new ZipPolicy(template, options); zipPolicy.Apply(); string runtimePolicy = System.IO.Path.GetTempFileName(); string myPolicy = System.IO.Path.GetTempFileName(); template.Save(myPolicy, runtimePolicy); Assert.IsTrue(System.IO.File.Exists(runtimePolicy)); System.IO.FileInfo fi = new System.IO.FileInfo(runtimePolicy); Assert.IsTrue(fi.Length > 0); System.IO.File.Delete(runtimePolicy); System.IO.File.Delete(myPolicy); }
public void TestOnlyExternalIsRemoved() { string runtimePolicy = System.IO.Path.GetTempFileName(); string myPolicy = System.IO.Path.GetTempFileName(); try { OptionsExporter exporter = new OptionsExporter(); exporter.Export(externalZipDisabled, contentPolicy, myPolicy, runtimePolicy, riskRatingsPath); PolicyTemplate modifedTemplate = new PolicyTemplate(); modifedTemplate.Load(myPolicy); try { IPolicy policy = modifedTemplate[TemplatePolicy.InternalZipPolicy]; } catch { Assert.IsTrue(false, "There should have been an internal zip policy"); } IPolicy policy2 = modifedTemplate[TemplatePolicy.ExternalZipPolicy]; } finally { System.IO.File.Delete(runtimePolicy); System.IO.File.Delete(myPolicy); } }
public void TestRemoveAction() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); 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); IPolicyChannel pdfSmtpChannel = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP]; template.RemoveAction(pdfSmtpChannel, Routing.Internal, internalActions.Values[0]); internalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal]; externalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External]; Assert.AreEqual(0, internalActions.Count); Assert.AreEqual(1, externalActions.Count); template.RemoveAction(pdfSmtpChannel, Routing.External, externalActions.Values[0]); internalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal]; externalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External]; Assert.AreEqual(0, internalActions.Count); Assert.AreEqual(0, externalActions.Count); }
public void TestSaveRemoveActionPersistsToTemplate() { PolicyTemplate template = new PolicyTemplate(); template.Load(policy_file); 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); IPolicyChannel pdfSmtpChannel = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP]; template.RemoveAction(pdfSmtpChannel, Routing.Internal, internalActions.Values[0]); string runtimePolicy = System.IO.Path.GetTempFileName(); string myPolicy = System.IO.Path.GetTempFileName(); template.Save(myPolicy, runtimePolicy); PolicyTemplate updatedPolicy = new PolicyTemplate(); updatedPolicy.Load(myPolicy); internalActions = updatedPolicy[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal]; externalActions = updatedPolicy[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External]; Assert.AreEqual(0, internalActions.Count); Assert.AreEqual(1, externalActions.Count); }
public AlertPolicy(PolicyTemplate template, List<ContentRule> rules) : base(template) { m_rules = rules; }
public PdfPolicy(PolicyTemplate template) : base(template) { m_externalPdfAction = GetPDFAction(Routing.External); m_internalPdfAction = GetPDFAction(Routing.Internal); }
public DetectWorkshareStyles(PolicyTemplate template) : base(template) { m_internalAlert = GetAlertAction(false); m_externalAlert = GetAlertAction(true); }
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); }