public void TestProcessFile_TraceFiles() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\rules-en-GB.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\PolicyObjects.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; UniversalRequestObject uro = GetUro3(false); uro.Properties[MailMessagePropertyKeys.Body] = "This is a safe email"; TestHelpers.AddAttachment(uro, new Workshare.Policy.Engine.File(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\AppSpec.doc"), "AppSpec")); PolicyResponseObject upi = engineU.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; upi = engineU.ProcessRoutings(upi) as PolicyResponseObject; upi = engineU.ProcessActions(upi) as PolicyResponseObject; Assert.AreEqual(2, upi.ContentCollection.Count); ContentItem content = upi.ContentCollection[1] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse policyResponse = policySet.PolicyReportCollection[0]; Assert.AreEqual("Classified Information Disclosure", policyResponse.Name); Assert.IsFalse(policyResponse.Triggered); policyResponse = policySet.PolicyReportCollection[1]; Assert.AreEqual("Hidden Information Disclosure", policyResponse.Name); Assert.IsFalse(policyResponse.Triggered); policyResponse = policySet.PolicyReportCollection[2]; Assert.AreEqual("Private Information Disclosure", policyResponse.Name); Assert.IsFalse(policyResponse.Triggered); policyResponse = policySet.PolicyReportCollection[3]; Assert.AreEqual("Profane Language", policyResponse.Name); Assert.IsFalse(policyResponse.Triggered); policyResponse = policySet.PolicyReportCollection[4]; Assert.AreEqual("Discriminatory Language", policyResponse.Name); Assert.IsFalse(policyResponse.Triggered); policyResponse = policySet.PolicyReportCollection[5]; Assert.AreEqual("Metadata/Security Disclosure", policyResponse.Name); Assert.IsTrue(policyResponse.Triggered); IUniversalRequestObject uroOut = engineU.ExecuteActions(upi); Assert.AreEqual(1, uroOut.Attachments.Count); }
public void TestProcessMessageContent_SubjectViolation() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessMessageContentRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessMessageContentObjectsU.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; // MockUroPolicyAuditor auditor = new MockUroPolicyAuditor(); // engine.SetPolicyAuditor(auditor); PolicyResponseObject pui = engine.ProcessConditions(RunAt.Client, TestHelpers.GetUro(true)) as PolicyResponseObject; ContentItem content = pui.ContentCollection[0] as ContentItem; PolicySetResponse policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse pi = policySetInfo.PolicyReportCollection[0]; Assert.AreEqual("Privacy", pi.Name); Assert.IsTrue(pi.Triggered); Assert.AreEqual("Possible Social Security Number", pi.ExpressionCollection[0].Name); Assert.IsFalse(pi.ExpressionCollection[0].Triggered); Assert.AreEqual("Possible Credit Card Number", pi.ExpressionCollection[1].Name); Assert.IsTrue(pi.ExpressionCollection[1].Triggered); Assert.AreEqual("Body", pi.ExpressionCollection[1].ExpressionDetailCollection[0].Name); Assert.AreEqual("4408 0412 3456 7890", pi.ExpressionCollection[1].ExpressionDetailCollection[0].Value); IPolicyResponse pi1 = policySetInfo.PolicyReportCollection[1]; Assert.AreEqual("Profanity", pi1.Name); Assert.IsFalse(pi1.Triggered); IPolicyResponse pi3 = policySetInfo.PolicyReportCollection[1]; Assert.AreEqual("Profanity", pi1.Name); Assert.IsFalse(pi1.Triggered); }
public void TestProcessActions_MetaDataViolation() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessActionsRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessActionsObjects.xml")); Workshare.Policy.Engine.UroPolicyEngine engineU = 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; engineU.PolicyCache = cache; UniversalRequestObject uro = GetUro3(false); uro.Properties[MailMessagePropertyKeys.Body] = "This is a safe email"; string dirtyDoc = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute( @"\projects\Hygiene\src\TestDocuments\Dirty -MetaDataVoilation.doc"); string tempDirtyDoc = System.IO.Path.GetTempFileName(); if (System.IO.File.Exists(tempDirtyDoc)) { System.IO.File.Delete(tempDirtyDoc); } tempDirtyDoc = Path.ChangeExtension(tempDirtyDoc, ".doc"); System.IO.File.Copy(dirtyDoc, tempDirtyDoc); TestHelpers.AddAttachment(uro, new Workshare.Policy.Engine.File(tempDirtyDoc, "Dirty")); PolicyResponseObject upi = engineU.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; upi = engineU.ProcessRoutings(upi) as PolicyResponseObject; upi = engineU.ProcessActions(upi) as PolicyResponseObject; Assert.AreEqual(2, upi.ContentCollection.Count); ContentItem content = upi.ContentCollection[1] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual("Clean", policySet.PolicyReportCollection[3].ActionCollection[0].Type); IUniversalRequestObject uroOut = engineU.ExecuteActions(upi); Assert.AreEqual(1, uroOut.Attachments.Count); if (System.IO.File.Exists(tempDirtyDoc)) { System.IO.File.Delete(tempDirtyDoc); } }
public void TestProcessActions_LotsOfViolations() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessActionsRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessActionsObjects.xml")); Workshare.Policy.Engine.UroPolicyEngine engineU = 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; engineU.PolicyCache = cache; UniversalRequestObject uro = GetUro3(false); uro.Properties[MailMessagePropertyKeys.Body] = "This is a safe email"; TestHelpers.AddAttachment(uro, new File(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\F*****g Everything.doc"), "F*****g Everything")); PolicyResponseObject upi = engineU.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; upi = engineU.ProcessRoutings(upi) as PolicyResponseObject; upi = engineU.ProcessActions(upi) as PolicyResponseObject; Assert.AreEqual(2, upi.ContentCollection.Count); ContentItem content = upi.ContentCollection[1] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual("Clean", policySet.PolicyReportCollection[3].ActionCollection[0].Type); IUniversalRequestObject uroOut = engineU.ExecuteActions(upi); Assert.AreEqual(0, uroOut.Attachments.Count); }
public void TestEnforce_MailMessageEntity_ExecuteAction() { 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(); cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").Content = rulesxml; cache.PolicySets[0].LatestVersion.GetCompiledPolicySet("SMTP", "Client").ObjectReferences = objectsxml; engine.PolicyCache = cache; // MockUroPolicyAuditor auditor = new MockUroPolicyAuditor(); // engine.SetPolicyAuditor(auditor); UniversalRequestObject uro = TestHelpers.GetUro(false); TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"), "TestPrivacy.doc"); TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"), "TestProfanity.doc"); PolicyResponseObject pui = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; PolicyResponseObject pui1 = engine.ProcessRoutings(pui) as PolicyResponseObject; PolicyResponseObject pui2 = engine.ProcessActions(pui1) as PolicyResponseObject; ContentItem content = pui.ContentCollection[2] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse pi1 = policySet.PolicyReportCollection[2]; Assert.AreEqual("Profanity", pi1.Name); Assert.IsTrue(pi1.Triggered); IUniversalRequestObject uroOut = engine.ExecuteActions(pui2); Assert.AreEqual(0, uroOut.Attachments.Count, "Expecting an empty shell of a URO with no attachments"); // ????: once a block action is introduced, all bets are off :), specifically it means that // _nothing_ else will get executed. // //Assert.IsTrue(uroOut.Attachments.Count == 1); // the profanity got cleaned! //IPolicyResponseObject pui3 = engine.ProcessConditions(RunAt.Client, uroOut); //content = pui.ContentCollection[1] as ContentItem; //policySet = content.PolicySetCollection[0] as PolicySetResponse; //IPolicyResponse pi3 = policySet.PolicyReportCollection[2]; //Assert.AreEqual("Profanity", pi3.Name); //Assert.IsFalse(pi3.Triggered); // shows it got cleaned! }
public void TestProcessMessageContent_ActionProcessing() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessMessageContentRulesU.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProcessMessageContentObjectsU.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(true); PolicyResponseObject pui = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; ContentItem content = pui.ContentCollection[3] as ContentItem; PolicySetResponse policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse pi = policySetInfo.PolicyReportCollection[0]; Assert.IsTrue(pi.Name == "Privacy"); Assert.IsTrue(pi.Triggered == true); Assert.IsTrue(pi.ExpressionCollection[0].Name == "Possible Social Security Number"); Assert.IsTrue(pi.ExpressionCollection[0].Triggered == false); Assert.IsTrue(pi.ExpressionCollection[1].Name == "Possible Credit Card Number"); Assert.IsTrue(pi.ExpressionCollection[1].Triggered == true); Assert.IsTrue(pi.ExpressionCollection[1].ExpressionDetailCollection[0].Name == "Body"); Assert.IsTrue(pi.ExpressionCollection[1].ExpressionDetailCollection[0].Value == "4408 0412 3456 7890"); Assert.IsTrue(pi.Routing.Name == "Privacy"); RoutingResponse routing = pi.Routing as RoutingResponse; Assert.IsTrue(routing.RoutingId == "Privacy_Routing"); content = pui.ContentCollection[3] as ContentItem; policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse pi3 = policySetInfo.PolicyReportCollection[1]; Assert.IsTrue(pi3.Name == "Profanity"); Assert.IsTrue(pi3.Triggered == false); PolicyResponseObject pui2 = engine.ProcessRoutings(pui) as PolicyResponseObject; content = pui2.ContentCollection[1] as ContentItem; policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse pi1 = policySetInfo.PolicyReportCollection[1]; Assert.IsTrue(pi1.Routing.Name == "Profanity"); routing = pi1.Routing as RoutingResponse; Assert.IsTrue(routing.RoutingId == "Profanity_Routing"); //ExpressionResponse expression = pi1.ExpressionCollection[1] as ExpressionResponse; //Assert.IsTrue(expression.ActionSetId == "Profanity_bad"); RoutingResponse routingResponse = pi1.Routing as RoutingResponse; Assert.IsTrue(routingResponse.ActionSetId == "Profanity_bad"); content = pui.ContentCollection[3] as ContentItem; policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; pi3 = policySetInfo.PolicyReportCollection[0]; routingResponse = pi3.Routing as RoutingResponse; //expression = pi3.ExpressionCollection[2] as ExpressionResponse; //Assert.IsTrue(expression.ActionSetId == "Privacy_Privileged_NonTrusted_Actions"); //Assert.IsTrue(expression.Type == "ROUTING"); Assert.IsTrue(routingResponse.ActionSetId == "Privacy_Privileged_NonTrusted_Actions"); PolicyResponseObject pui3 = engine.ProcessActions(pui2) as PolicyResponseObject; content = pui3.ContentCollection[1] as ContentItem; policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; pi1 = policySetInfo.PolicyReportCollection[1]; //expression = pi1.ExpressionCollection[1] as ExpressionResponse; Assert.IsTrue(pi1.Routing.Name == "Profanity"); routing = pi1.Routing as RoutingResponse; Assert.IsTrue(routing.RoutingId == "Profanity_Routing"); routingResponse = pi1.Routing as RoutingResponse; Assert.IsTrue(routingResponse.ActionSetId == "Profanity_bad"); //Assert.IsTrue(expression.ActionSetId == "Profanity_bad"); Assert.IsTrue(pi1.ActionCollection[0].Name == "Find Profanity"); Assert.IsTrue(pi1.ActionCollection[0].Type == "Test_MetdataCleaner"); Assert.IsTrue(pi1.ActionCollection[1].Name == "Remove Profanity"); Assert.IsTrue(pi1.ActionCollection[1].Type == "Test_MetdataCleaner"); // stet. as stated in the dll content = pui3.ContentCollection[3] as ContentItem; policySetInfo = content.PolicySetCollection[0] as PolicySetResponse; pi3 = policySetInfo.PolicyReportCollection[0]; //expression = pi3.ExpressionCollection[2] as ExpressionResponse; routingResponse = pi3.Routing as RoutingResponse; //Assert.IsTrue(expression.ActionSetId == "Privacy_Privileged_NonTrusted_Actions"); Assert.IsTrue(routingResponse.ActionSetId == "Privacy_Privileged_NonTrusted_Actions"); Assert.IsTrue(pi3.ActionCollection[0].Name == "Find Social Security Number"); Assert.IsTrue(pi3.ActionCollection[0].Type == "Test_MetdataCleaner"); Assert.IsTrue(pi3.ActionCollection[1].Name == "Remove Social Security Number"); Assert.IsTrue(pi3.ActionCollection[1].Type == "Test_MetdataCleaner"); }
public void TestProcessZipPolicy() { string testPath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\"); UroPolicyEngine engine = new UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(-1); Assert.AreEqual(0, cache.PolicySets.Count, "Expected not policy sets to exist"); IPolicySetCache policySetCache = cache.NewPolicySet("Test"); Assert.AreEqual(1, cache.PolicySets.Count, "Expected one policy sets to exist"); policySetCache.LatestVersion.Content = System.IO.File.ReadAllText(testPath + "BlockZipFilesAndZipWordFilesPolicy.xml"); engine.PolicyCache = cache; UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "You breaka my policy, I breaka you're middle toe"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Zip my attachment if they are word doc and block zip attachments"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, "I am a dirty zip.zip; Dirty.doc"); // Add a zip attachment RequestAttachment zipAttachment = TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, testPath + "I am a dirty zip.zip", "I am a dirty zip.zip"); // Add a word doc RequestAttachment wordAttachment = TestHelpers.AddAttachment(uro, RequestObjectContentType.DOC, testPath + "Dirty.doc", "Dirty.doc"); uro.Source.PolicyType = uro.PolicyType; uro.Source.RoutingType = RoutingTypes.Source; IRoutingItem fromRoutingItem = new RoutingItem("*****@*****.**"); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "pair"); uro.Source.Items.Add(fromRoutingItem); uro.Destination.PolicyType = uro.PolicyType; uro.Destination.RoutingType = RoutingTypes.Destination; IRoutingItem toRoutingItem = new RoutingItem("sam test"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "sam test"); uro.Destination.Items.Add(toRoutingItem); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = DateTime.Now; PolicyResponseObject conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; PolicyResponseObject rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; PolicyResponseObject actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; Assert.AreEqual(4, actionPolicyInfo.ContentCollection.Count); ContentItem content = actionPolicyInfo.ContentCollection[1] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse zipPolicyInfo = policySet.PolicyReportCollection[1]; Assert.IsTrue(zipPolicyInfo.Triggered); content = actionPolicyInfo.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse wordPolicyInfo = policySet.PolicyReportCollection[0]; Assert.IsFalse(wordPolicyInfo.Triggered); // Remove the zip attachment. uro.Attachments.Remove(zipAttachment); conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; content = actionPolicyInfo.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; zipPolicyInfo = policySet.PolicyReportCollection[1]; Assert.IsFalse(zipPolicyInfo.Triggered); content = actionPolicyInfo.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; wordPolicyInfo = policySet.PolicyReportCollection[0]; Assert.IsTrue(wordPolicyInfo.Triggered); Assert.AreEqual(1, actionPolicyInfo.UniversalRequestObject.Attachments.Count); Assert.AreEqual(RequestObjectContentType.DOC, actionPolicyInfo.UniversalRequestObject.Attachments[0].ContentType); Assert.AreEqual("Dirty.doc", Path.GetFileName(actionPolicyInfo.UniversalRequestObject.Attachments[0].Name)); IUniversalRequestObject outputUro = engine.ExecuteActions(actionPolicyInfo); Assert.AreEqual(1, outputUro.Attachments.Count, "Expected a zip attachment to be created"); IRequestAttachment outputAttachment = outputUro.Attachments[0]; Assert.AreEqual("Dirty.zip", Path.GetFileName(outputUro.Attachments[0].Name), "Is LDAP configured correctly?"); CheckZipFile(outputUro.Attachments[0].Data.AsStream(), new string[] { "Dirty.doc" }, true, "", false); }
public void TestProcessPolicyWhenChangesMadeToPolicySetAfterPolicyEngineLoaded() { string testPath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\"); string rulesxml = System.IO.File.ReadAllText(testPath + "EnforceRulesU.xml"); string objectsxml = System.IO.File.ReadAllText(testPath + "EnforceObjectsU.xml"); Workshare.Policy.Engine.UroPolicyEngine engine = new Workshare.Policy.Engine.UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(-1); Assert.AreEqual(0, cache.PolicySets.Count, "Expected not policy sets to exist"); IPolicySetCache policySetCache = cache.NewPolicySet("Test"); Assert.AreEqual(1, cache.PolicySets.Count, "Expected one policy sets to exist"); policySetCache.LatestVersion.Content = System.IO.File.ReadAllText(testPath + "TestPolicyEngine.xml"); engine.PolicyCache = cache; UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "f**k"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Subject line"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.Source.PolicyType = uro.PolicyType; uro.Source.RoutingType = RoutingTypes.Source; IRoutingItem fromRoutingItem = new RoutingItem("*****@*****.**"); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(fromRoutingItem); uro.Destination.PolicyType = uro.PolicyType; uro.Destination.RoutingType = RoutingTypes.Destination; IRoutingItem toRoutingItem = new RoutingItem("sam test"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; PolicyResponseObject conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; PolicyResponseObject rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; PolicyResponseObject actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; ContentItem content = actionPolicyInfo.ContentCollection[0] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual(1, policySet.PolicyReportCollection[2].ExpressionCollection[0].ExpressionDetailCollection.Count); IPolicySetVersionCache latestVersion = cache.PolicySets[0].LatestVersion; cache.PolicySets[0].NewVersion(cache.PolicySets[0].LatestVersion.Content.Replace("(?i:f**k)", "(?i:jou ma se)")); conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; content = actionPolicyInfo.ContentCollection[0] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual(0, policySet.PolicyReportCollection[2].ExpressionCollection[0].ExpressionDetailCollection.Count); uro.Properties[MailMessagePropertyKeys.Body] = "jou ma se"; conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; content = actionPolicyInfo.ContentCollection[0] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual(1, policySet.PolicyReportCollection[2].ExpressionCollection[0].ExpressionDetailCollection.Count); }
public void TestMultiEnforce() { 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(); 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, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\F*****g Everything.doc"), "F*****g Everything.doc"); DateTime dtStart1 = DateTime.Now; PolicyResponseObject pui = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; DateTime dtEnd1 = DateTime.Now; TimeSpan ts1 = dtEnd1 - dtStart1; PolicyResponseObject pui1 = engine.ProcessRoutings(pui) as PolicyResponseObject; PolicyResponseObject pui2 = engine.ProcessActions(pui1) as PolicyResponseObject; ContentItem content = pui.ContentCollection[1] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse pi1 = policySet.PolicyReportCollection[3]; Assert.IsTrue(pi1.Name == "Metadata"); Assert.IsTrue(pi1.Triggered); // I don't really understand what this next line was testing. It was too vague to be // of any real use... //Assert.IsTrue(pi1.Actions[0].Properties.Count == 4); // ["TrackChanges"]) == false); IUniversalRequestObject uroOut = engine.ExecuteActions(pui2); Assert.IsTrue(uroOut.Attachments.Count == 0); // the profanity got cleaned! UniversalRequestObject uro2 = TestHelpers.GetUro(false); TestHelpers.AddAttachment(uro2, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"), "TestProfanity.doc"); DateTime dtStart2 = DateTime.Now; PolicyResponseObject pui3 = engine.ProcessConditions(RunAt.Client, uro2) as PolicyResponseObject; DateTime dtEnd2 = DateTime.Now; TimeSpan ts2 = dtEnd2 - dtStart2; engine.ProcessRoutings(pui3); engine.ProcessActions(pui3); // NOW! there were trackchanges in first doc and not in the second content = pui3.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.IsTrue(policySet.PolicyReportCollection[2].ActionCollection.Count > 0); // and again! this time with same file UniversalRequestObject uro3 = TestHelpers.GetUro(false); TestHelpers.AddAttachment(uro3, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"), "TestProfanity.doc"); DateTime dtStart3 = DateTime.Now; pui3 = engine.ProcessConditions(RunAt.Client, uro3) as PolicyResponseObject; DateTime dtEnd3 = DateTime.Now; TimeSpan ts3 = dtEnd3 - dtStart3; engine.ProcessRoutings(pui3); engine.ProcessActions(pui3); // NOW! there were trackchanges in first doc and not in the second content = pui3.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.IsTrue(policySet.PolicyReportCollection[2].ActionCollection.Count > 0); }