public List<PolicyResponse> Scan(string file) { UroPolicyEngine engine = new UroPolicyEngine(); UniversalRequestObject uro = GetFileUro(file, "DisplayName"); engine.PolicyCache = PolicyProxy.CreateLocalRuntimeCache(); engine.Enforce(RunAt.Client, uro); PolicyResponseObject pro = engine.Upi; return GetViolatedPolicies(pro); }
public void TestEnforce_NestedZips() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\EnforceRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\EnforceObjectsU.xml")); Workshare.Policy.Engine.UroPolicyEngine engine = new Workshare.Policy.Engine.UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(1); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; engine.PolicyCache = cache; UniversalRequestObject uro = TestHelpers.GetUro(false); TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Nest01.zip"), "Nest01.zip"); TestHelpers.AddAttachment(uro, RequestObjectContentType.DOC, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestDoc.doc"), "TestDoc.doc"); TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Nest02.zip"), "Nest02.zip"); TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Nest03.zip"), "Nest03.zip"); TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Nest04.zip"), "Nest04.zip"); IUniversalRequestObject uroOut = engine.Enforce(RunAt.Client, uro); Assert.AreEqual(0, uroOut.Attachments.Count, "output should be empty"); #region review the authors intent //Assert.AreEqual(5, uroOut.Attachments.Count); //Assert.AreEqual(RequestObjectContentType.ZIP, uroOut.Attachments[0].ContentType); //Assert.AreEqual("Nest01.zip", Path.GetFileName(uroOut.Attachments[0].Name)); //Assert.AreEqual(RequestObjectContentType.DOC, uroOut.Attachments[1].ContentType); //Assert.AreEqual("TestDoc.doc", Path.GetFileName(uroOut.Attachments[1].Name)); //Assert.AreEqual(RequestObjectContentType.ZIP, uroOut.Attachments[2].ContentType); //Assert.AreEqual("Nest02.zip", Path.GetFileName(uroOut.Attachments[2].Name)); //Assert.AreEqual(RequestObjectContentType.ZIP, uroOut.Attachments[3].ContentType); //Assert.AreEqual("Nest03.zip", Path.GetFileName(uroOut.Attachments[3].Name)); //Assert.AreEqual(RequestObjectContentType.ZIP, uroOut.Attachments[4].ContentType); //Assert.AreEqual("Nest04.zip", Path.GetFileName(uroOut.Attachments[4].Name)); //// Nest01.zip //File fi = new File(uroOut.Attachments[0].Data.AsStream(), "zippy.zip"); //List<string> names = new List<string>(); //names.Add("TestGood.doc"); //names.Add("TestGood.zip"); //names.Add("TestProfanity.doc"); //names.Add("TestMixed.zip"); //CheckZipContents(fi, 4, names); //Assert.IsTrue(fi.Files[0].DisplayName.Contains("TestGood.doc")); //// disassemble those also to show 1 file in mixed, no zip of bad, and two in good //names.Clear(); //names.Add("TestGood.doc"); //names.Add("TestGood2.doc"); //CheckZipContents(fi.Files[1], 2, names); //Assert.IsTrue(fi.Files[2].DisplayName.Contains("TestProfanity.doc")); //names.Clear(); //names.Add("TestGood.doc"); //CheckZipContents(fi.Files[3], 1, names); //// Nest02.zip //fi = new File(uroOut.Attachments[2].Data.AsStream(), "zippy.zip"); //names.Clear(); //names.Add("TestGood.doc"); //names.Add("TestBad.zip"); //names.Add("TestMixed.zip"); //CheckZipContents(fi, 3, names); //names.Clear(); //names.Add("TestGood.doc"); //CheckZipContents(fi.Files[2], 1, names); //// Nest03.zip //fi = new File(uroOut.Attachments[3].Data.AsStream(), "zippy.zip"); //names.Clear(); //names.Add("TestBad.zip"); //names.Add("TestMixed.zip"); //names.Add("TestGood.zip"); //CheckZipContents(fi, 3, names); //names.Clear(); //names.Add("TestGood.doc"); //CheckZipContents(fi.Files[1], 1, names); //names.Add("TestGood2.doc"); //CheckZipContents(fi.Files[2], 2, names); // 01 Nest01.zip // 02 TestGood.doc // 03 TestGood.zip // 04 TestGood.doc // 05 TestGood2.doc // 06 TestMixed.zip // 07 F*E.doc // 08 TestGood.doc // 09 TestProfanity.doc // 00 TestDoc.doc // 11 Nest02.zip // 12 F*E.Doc // 13 TestBad.zip // 14 F*E.Doc // 15 F*E.Doc // 16 TestGood.Doc // 17 TestMixed.zip // 18 F*E.Doc // 19 TestGood.Doc // 20 TestPrivacy.doc // 21 Nest03.zip // 22 TestBad.zip // 23 F*E.Doc // 24 F*E.Doc // 25 TestGood.zip // 26 TestGood.doc // 27 TestGood2.doc // 28 TestMixed.zip // 29 F*E.Doc // 30 TestGood.Doc // 31 Nest04.zip // 32 F*E.Doc // 33 TestBad.zip // 34 F*E.Doc // 35 F*E.Doc #endregion }
public void TestEnforce_MultipleZips() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\EnforceRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\EnforceObjectsU.xml")); UroPolicyEngine engine = new UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(1); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; engine.PolicyCache = cache; UniversalRequestObject uro = TestHelpers.GetUro(false); TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestZip.zip"), "TestZip.zip"); TestHelpers.AddAttachment(uro, RequestObjectContentType.DOC, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"), "TestPrivacy.doc"); TestHelpers.AddAttachment(uro, RequestObjectContentType.DOC, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestDoc.doc"), "TestDoc.doc"); TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestZipMore.zip"), "TestZipMore.zip"); Assert.AreEqual(4, uro.Attachments.Count); IUniversalRequestObject uroOut = engine.Enforce(RunAt.Client, uro); Assert.AreEqual(0, uroOut.Attachments.Count, "Block action included so no processing should occur"); }
public void TestEnforce_Construct_SystemNetMailMessage_DirtyBody() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\SystemNetMailMessageRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\SystemNetMailMessageObjectsU.xml")); UniversalRequestObject uro = GetUro2(); UroPolicyEngine engineU = new UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\TestDocuments\SystemNetMailMessageLanguageU.xml")); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").NewLanguage("en", xmldoc.FirstChild.OuterXml, true); engineU.PolicyCache = cache; uro.Properties[MailMessagePropertyKeys.Body] = "F*****g dirty f****r f**k"; IUniversalRequestObject uroOut = engineU.Enforce(RunAt.Client, uro); Assert.IsTrue(uroOut.Attachments.Count == 0); }
public void TestMailMessage_AttachmentRemoved_ProfanityViolation() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\rsa_server_rulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\rsa_server_objectsU.xml")); Workshare.Policy.Engine.UroPolicyEngine engine = new Workshare.Policy.Engine.UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; engine.PolicyCache = cache; UniversalRequestObject uro = TestHelpers.GetUro(false); uro.Properties.Clear(); uro.Properties.Add(MailMessagePropertyKeys.Body, "random text"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "more random text"); TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"), "TestProfanity.doc"); IUniversalRequestObject uroOut = engine.Enforce(RunAt.Client, uro); Assert.IsTrue(uroOut.Attachments.Count == 0); // blocked! }
private void ExecutePolicyEngine(object x) { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\default_policy_rules.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\default_policy_objects.xml")); Workshare.Policy.Engine.UroPolicyEngine engineU = new Workshare.Policy.Engine.UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; engineU.PolicyCache = cache; string filePath = (string)x; UniversalRequestObject uro = TestHelpers.GetUro(false); TestHelpers.AddAttachment(uro, "Doc", filePath, Path.GetFileName(filePath)); IUniversalRequestObject uro2 = engineU.Enforce(RunAt.Client, uro); lock (m_uro_list) { m_uro_list.Add(uro2); } }
private List<_Document> scan(string file) { UroPolicyEngine engine = new UroPolicyEngine(); UniversalRequestObject uro = getFileUro(file); var defaultPath = OptionApi.GetString("ContentRiskDefaultPolicyPath"); engine.PolicyCache = string.IsNullOrEmpty(defaultPath) ? new LocalPolicyCache(true) : new LocalPolicyCache(defaultPath, true); engine.Enforce(Workshare.Policy.RunAt.Client, uro); PolicyResponseObject pro = engine.Upi; List<_Document> documentList = null; if(pro != null) { documentList = getDocumentPolicies(pro); } return documentList; }
public void TestPolicyProgressEvents() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\rsa_server_rulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\rsa_server_objectsU.xml")); Workshare.Policy.Engine.UroPolicyEngine engine = new Workshare.Policy.Engine.UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; engine.PolicyCache = cache; MockProgressCallback policyEvents = new MockProgressCallback(); engine.ProgressCallback = policyEvents; string bodyText = "4408 0412 3456 7890"; System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "subject line", bodyText); message.Attachments.Add(new System.Net.Mail.Attachment(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"))); UniversalRequestObject uro = TestHelpers.GetUroFromMailMessage(message); IUniversalRequestObject uroOut = engine.Enforce(RunAt.Client, uro); PolicyProgressEventArgs args = policyEvents.PolicyProgressEventArgs[0] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Policies"); Assert.IsTrue(args.Type == EventType.process); args = policyEvents.PolicyProgressEventArgs[1] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "The Seven Dirty Words! and some..."); Assert.IsTrue(args.Type == EventType.condition); args = policyEvents.PolicyProgressEventArgs[2] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Profanity"); Assert.IsTrue(args.Type == EventType.rule); args = policyEvents.PolicyProgressEventArgs[3] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Policies"); Assert.IsTrue(args.Type == EventType.process); args = policyEvents.PolicyProgressEventArgs[4] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Use of profanity"); Assert.IsTrue(args.Type == EventType.condition); args = policyEvents.PolicyProgressEventArgs[5] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Profane Language"); Assert.IsTrue(args.Type == EventType.rule); args = policyEvents.PolicyProgressEventArgs[6] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Policies"); Assert.IsTrue(args.Type == EventType.process); args = policyEvents.PolicyProgressEventArgs[7] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Policies"); Assert.IsTrue(args.Type == EventType.process); args = policyEvents.PolicyProgressEventArgs[8] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Possible credit card number in email or attachment"); Assert.IsTrue(args.Type == EventType.condition); args = policyEvents.PolicyProgressEventArgs[9] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Private Information Disclosure"); Assert.IsTrue(args.Type == EventType.rule); args = policyEvents.PolicyProgressEventArgs[10] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Privileged Sender to Trusted Recipient"); Assert.IsTrue(args.Type == EventType.routing); args = policyEvents.PolicyProgressEventArgs[11] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Internal Destinations"); Assert.IsTrue(args.Type == EventType.routing); args = policyEvents.PolicyProgressEventArgs[12] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Internal Destinations"); Assert.IsTrue(args.Type == EventType.routing); args = policyEvents.PolicyProgressEventArgs[13] as PolicyProgressEventArgs; Assert.IsTrue(args.Name == "Server_Block"); Assert.IsTrue(args.Type == EventType.action); ExecuteEventArgs executeArgs = policyEvents.AfterExecuteEventArgs[0] as ExecuteEventArgs; Assert.IsTrue(executeArgs.ActionName == "Server_Block"); Assert.IsTrue(executeArgs.Status == status.Completed); executeArgs = policyEvents.BeforeExecuteEventArgs[0] as ExecuteEventArgs; Assert.IsTrue(executeArgs.ActionName == "Server_Block"); Assert.IsTrue(executeArgs.Status == status.Started); }