public void TestCreditCardNumberRegex() { ContentPolicyReader cpr = new ContentPolicyReader(); List<ContentRule> contentRules = cpr.Read(contentPolicy); Assert.AreEqual(4, contentRules.Count); ContentRule personalInformationRule = contentRules[0]; Assert.AreEqual(3, personalInformationRule.Conditions.Count); ContentCondition ccCondition = personalInformationRule.Conditions[0]; Assert.AreEqual(sReCCN, ccCondition.Regex); Regex reCCN = new Regex(sReCCN); // Ensure we correctly match valid credit card numbers foreach (string sValidCCN in CreditCardNumberTestData.Valid) { Assert.IsTrue(reCCN.IsMatch(sValidCCN), "Expected to match a valid credit card number"); } // Ensure we don't false positive on non-valid numbers foreach (string sNonValidCCN in CreditCardNumberTestData.NonValid) { Assert.IsFalse(reCCN.IsMatch(sNonValidCCN), "Expected NOT to match a non-valid credit card number"); } }
public void TestTabsAndNewLinesAreStrippedFromTheExplanation() { ContentPolicyReader cpr = new ContentPolicyReader(); List<ContentRule> contentRules = cpr.Read(contentPolicy); Assert.AreEqual(4, contentRules.Count); ContentRule personalInformationRule = contentRules[0]; Assert.AreEqual(3, personalInformationRule.Conditions.Count); ContentCondition ccCondition = personalInformationRule.Conditions[0]; Assert.IsTrue(ccCondition.Explanation.IndexOf('\n') == -1); Assert.IsTrue(ccCondition.Explanation.IndexOf('\t') == -1); }
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 TestReadContentPolicy() { ContentPolicyReader cpr = new ContentPolicyReader(); List<ContentRule> contentRules = cpr.Read(contentPolicy); Assert.AreEqual(4, contentRules.Count); ContentRule personalInformationRule = contentRules[0]; Assert.AreEqual(3, personalInformationRule.Conditions.Count); ContentCondition ccCondition = personalInformationRule.Conditions[0]; Assert.AreEqual("Possible Credit Card Number", ccCondition.Name); Assert.AreEqual(sReCCN, ccCondition.Regex); Assert.AreEqual(5, ccCondition.Contexts.Count); Assert.AreEqual("Paragraph", ccCondition.Contexts[0]); Assert.AreEqual("Footnote", ccCondition.Contexts[1]); Assert.AreEqual("Endnote", ccCondition.Contexts[2]); Assert.AreEqual("Header", ccCondition.Contexts[3]); Assert.AreEqual("Footer", ccCondition.Contexts[4]); Assert.IsTrue(ccCondition.Explanation.Contains("It is necessary to manage and secure identity information such as :")); }
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); }