private static void PopulateDestinationFromMailMessage(UniversalRequestObject uro, System.Net.Mail.MailMessage mailMessage) { uro.Destination.PolicyType = uro.PolicyType; uro.Destination.Properties = new Dictionary<string, string>(); uro.Destination.Items = new Collection<IRoutingItem>(); foreach (MailAddress mailAddress in mailMessage.To) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(routingItem); } foreach (MailAddress mailAddress in mailMessage.CC) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(routingItem); } foreach (MailAddress mailAddress in mailMessage.Bcc) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.BCC); uro.Destination.Items.Add(routingItem); } }
/// <summary> /// Converts a SafeMailItem to a System.Net.Mail.Message /// </summary> /// <param name="mail"></param> /// <returns></returns> /// <exception cref="ArgumentException">Passing in anything other than a reference to SafeMailItemClass throws an ArgumentException.</exception> public IUniversalRequestObject Convert(object mail) { using (new WsActivationContext()) { UniversalRequestObject retVal = new UniversalRequestObject(); SafeMailItemClass mailItem = mail as SafeMailItemClass; if (null == mailItem) { Logging.Trace.WriteLine(Properties.Resources.MAIL_NULL, "RedemptionMailConverter.Convert"); throw new ArgumentException(Properties.Resources.MAIL_NULL); } else { HandleSubjectAndBody(mailItem, retVal); HandleOriginator(mailItem, retVal); HandleRecipients(mailItem, retVal); HandleAttachments(mailItem, retVal); HandleUroProperties(mailItem, retVal); return retVal; } } }
public static UniversalRequestObject GetUroFromMailMessage(System.Net.Mail.MailMessage message) { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, message.Headers.ToString()); uro.Properties.Add(MailMessagePropertyKeys.Body, message.Body); uro.Properties.Add(MailMessagePropertyKeys.Subject, message.Subject); string sFilenames = ""; foreach (System.Net.Mail.Attachment attachment in message.Attachments) { sFilenames += attachment.Name + ' '; RequestAttachment ra = new RequestAttachment(); ra.Name = attachment.Name; ra.ContentType = attachment.ContentType.ToString(); ra.File = new Workshare.Policy.Engine.File(attachment.ContentStream, ra.Name); uro.Attachments.Add(ra); } uro.Properties.Add(MailMessagePropertyKeys.Attachments, sFilenames); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; if (message.From.Address.Length > 0) { PopulateSourceFromMailMessage(uro, message); } PopulateDestinationFromMailMessage(uro, message); return uro; }
RequestAttachment GetRequestAttachment(UniversalRequestObject uro, string stype, string filename, string displayname) { RequestAttachment ra = new RequestAttachment(); ra.Name = displayname; ra.ContentType = stype; ra.Data = new BinaryData(filename); return ra; }
public IUniversalRequestObject Convert(RequestChannel requestChannel) { UniversalRequestObject uro = new UniversalRequestObject(); uro.OriginalContentBytes = GetMime(); Convert(requestChannel, uro); return uro; }
public static void GenerateUROAttachmentData(UniversalRequestObject uro, string[] attachmentFiles) { if (null == attachmentFiles) return; foreach (string file in attachmentFiles) { RequestAttachment attachment = TestingUtils.TestHelpers.AddAttachment(uro, "doc", file, System.IO.Path.GetFileName(file)); } }
private static void PopulateSourceFromMailMessage(UniversalRequestObject uro, System.Net.Mail.MailMessage mailMessage) { uro.Source.PolicyType = uro.PolicyType; uro.Source.Properties = new Dictionary<string, string>(); uro.Source.Items = new Collection<IRoutingItem>(); RoutingItem routingItem = new RoutingItem(mailMessage.From.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailMessage.From.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(routingItem); }
UniversalRequestObject GetFileUro(string file, string displayname) { UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = PolicyType.ActiveContent; uro.DataTimeStamp = System.DateTime.Now; uro.Properties.Add(ActiveContentPropertyKeys.UserName, System.Environment.UserName); uro.Properties.Add(ActiveContentPropertyKeys.Application, "Professional.Policy.Inspector"); uro.Properties.Add(ActiveContentPropertyKeys.MachineName, System.Environment.MachineName); RequestAttachment ra = GetRequestAttachment(uro, "", file, displayname); uro.Attachments.Add(ra); return uro; }
private static void HandleOrigContentBytes(string mimeString, UniversalRequestObject uro) { RequestAttachment ra = new RequestAttachment(); ra.Name = "MIME"; ra.ContentType = "MIME"; using (MemoryStream mimeStream = new MemoryStream(Encoding.Unicode.GetBytes(mimeString))) { ra.Data = new OptimizedBinaryData(mimeStream); } uro.OriginalContentBytes = ra; }
/// <summary> /// This method will create a Universal Request Object /// </summary> private void CreateUro(FileInfo file) { m_uro = new UniversalRequestObject(); RequestAttachment ra = CreateAttachment(file); ra.FileName = file.FullName; ra.Name = Path.GetFileName(file.Name); ra.File = new Workshare.FCS.Lite.Interface.File(file.FullName, Path.GetFileNameWithoutExtension(file.FullName)); m_uro.Attachments.Add(ra); m_uro.PolicyType = PolicyType.ActiveContent; m_uro.DataTimeStamp = DateTime.Now; m_uro.DataTimeStamp = file.CreationTime; m_uro.Properties.Add("UserName", Environment.UserName); m_uro.Properties.Add("MachineName", Environment.MachineName); m_uro.Properties.Add("Application", Properties.Resources.APPNAME); }
public static IUniversalRequestObject GetURO(Request request) { if (null == request) throw new ArgumentNullException("request"); UniversalRequestObject uro = new UniversalRequestObject(); uro.DataTimeStamp = request.DateTime; uro.PolicyType = (PolicyType)Enum.Parse(typeof(PolicyType), request.PolicyType); uro.Source = RoutingEntityAdaptor.GetUniversalRoutingEntity(request.Source); uro.Destination = RoutingEntityAdaptor.GetUniversalRoutingEntity(request.Destination); uro.Attachments = new RequestAttachmentCollection(); if (request.Attachments != null) { foreach (Attachment attachment in request.Attachments) { if (!attachment.IgnoreForWorkshareActions) //yyz THIS MEANS .MP4 MISSED BY SENDLINK { uro.Attachments.Add(AttachmentAdaptor.GetRequestAttachment(attachment)); } } } uro.Properties = new Dictionary<string, string>(); if (request.Properties != null) { foreach (CustomProperty property in request.Properties) { //Original MIME content should be sent in via a named CustomProperty. if (0 == string.Compare(SMTPPropertyTags.OriginalMimeContent, property.Name, StringComparison.InvariantCulture)) { HandleOrigContentBytes(property.Value, uro); continue; } uro.Properties[property.Name] = property.Value; } } if (PolicyType.ClientEmail.ToString() == request.PolicyType) { uro.Properties["_ROOTCONTENTID"] = Guid.NewGuid().ToString(); } return uro; }
public static UniversalRequestObject GetUroFromMailMessage(System.Net.Mail.MailMessage message, string sPath) { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, message.Headers.ToString()); uro.Properties.Add(MailMessagePropertyKeys.Body, message.Body); uro.Properties.Add(MailMessagePropertyKeys.Subject, message.Subject); string sFilenames = ""; string name; System.Net.Mime.ContentType contentType; foreach (System.Net.Mail.Attachment attachment in message.Attachments) { using (attachment) { name = attachment.Name; contentType = attachment.ContentType; } sFilenames += name + ' '; RequestAttachment ra = new RequestAttachment(); ra.ContentType = contentType.ToString(); //ra.Data = new OptimizedBinaryData(attachment.ContentStream); ra.FileName = System.IO.Path.Combine(sPath, name); ra.Name = System.IO.Path.GetFileName(name); ra.File = new Workshare.FCS.Lite.Interface.File(ra.FileName, System.IO.Path.GetFileNameWithoutExtension(ra.FileName)); ra.ContentId = Guid.NewGuid().ToString(); uro.Attachments.Add(ra); } uro.Properties.Add(MailMessagePropertyKeys.Attachments, sFilenames); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; if (message.From.Address.Length > 0) { PopulateSourceFromMailMessage(uro, message); } PopulateDestinationFromMailMessage(uro, message); return uro; }
// Bool return also simplifies the edit changes to make the recordings in the test files public bool RecordDocument(string sType, string sFullFilePath) { try { string sExpectationFileFullPath = sFullFilePath.Substring(0, sFullFilePath.Length - 4); sExpectationFileFullPath += sType; sExpectationFileFullPath += @"_generated.xml"; m_uroIn = CreateSMTPUro(sType, sFullFilePath); EnforcePolicy(); bool bZip = sFullFilePath.EndsWith(".zip", true, System.Globalization.CultureInfo.InvariantCulture); return RecordPolicyReturned(sExpectationFileFullPath, bZip); } catch { return false; // throwing more agressively with the runtime policy? } }
public static PolicyResponseObject GeneratePRO(string[] files, PolicyType policyType, out IContainer container) { PolicyResponseObject pro = new PolicyResponseObject(); pro.RunAt = RunAt.Client; UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = policyType; uro.DataTimeStamp = DateTime.Now; GenerateURORoutingDetails(uro, policyType); GenerateUROProperties(uro, policyType); GenerateUROAttachmentData(uro, files); pro.UniversalRequestObject = uro; ContainerBuilder containerBuilder = new ContainerBuilder(pro); container = containerBuilder.CreateContainerFromUro(); return pro; }
public bool ProcessDocument(string sType, string sFullFilePath) { try { string sValidationFileFullPath = sFullFilePath.Substring(0, sFullFilePath.Length - 4); sValidationFileFullPath += sType; sValidationFileFullPath += @"_result.xml"; SetValidationRules(sValidationFileFullPath); m_uroIn = CreateSMTPUro(sType, sFullFilePath); EnforcePolicy(); bool bZip = sFullFilePath.EndsWith(".zip", true, System.Globalization.CultureInfo.InvariantCulture); if (ValidatePolicyWasApplied(bZip)) return true; return false; } catch { return false; // throwing more agressively with the runtime policy? } }
private UniversalRequestObject GetUro2() { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "4408 0412 3456 7890"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "subject line"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.RoutingType = RoutingTypes.Source; uro.Source.PolicyType = uro.PolicyType; IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(sourceRoutingItem); uro.Destination.RoutingType = RoutingTypes.Destination; uro.Destination.PolicyType = uro.PolicyType; IRoutingItem toRoutingItem1 = new RoutingItem("*****@*****.**"); toRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem1); IRoutingItem toRoutingItem2 = new RoutingItem("*****@*****.**"); toRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem2); IRoutingItem toRoutingItem3 = new RoutingItem("*****@*****.**"); toRoutingItem3.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem3); 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"); return uro; }
private UniversalRequestObject GetUro3(bool bAddAttachments) { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "4408 0412 3456 7890 piss"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Random Subject line"); if (bAddAttachments) uro.Properties.Add(MailMessagePropertyKeys.Attachments, "attachment1.txt; f**k.txt; c**t.txt"); else uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.RoutingType = RoutingTypes.Source; uro.Source.PolicyType = uro.PolicyType; IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(sourceRoutingItem); uro.Destination.RoutingType = RoutingTypes.Destination; uro.Destination.PolicyType = uro.PolicyType; IRoutingItem toRoutingItem1 = new RoutingItem("*****@*****.**"); toRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem1); IRoutingItem toRoutingItem2 = new RoutingItem("*****@*****.**"); toRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem2); IRoutingItem ccRoutingItem1 = new RoutingItem("*****@*****.**"); ccRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem1); IRoutingItem ccRoutingItem2 = new RoutingItem("*****@*****.**"); ccRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem2); IRoutingItem bccRoutingItem1 = new RoutingItem("*****@*****.**"); bccRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(bccRoutingItem1); if (bAddAttachments) { RequestAttachment ra = new RequestAttachment((new ASCIIEncoding()).GetBytes("tuff")); ra.Name = "attachment1.txt"; ra.ContentType = "text"; uro.Attachments.Add(ra); RequestAttachment ra2 = new RequestAttachment((new ASCIIEncoding()).GetBytes("is a big fishy, yes?")); ra2.Name = "f**k.txt"; ra2.ContentType = "fish"; uro.Attachments.Add(ra2); RequestAttachment ra3 = new RequestAttachment((new ASCIIEncoding()).GetBytes("tuff")); ra3.Name = "c**t.txt"; ra3.ContentType = "TEXT"; uro.Attachments.Add(ra3); } return uro; }
public void TestBlankUroDoesntCrashSmtp_OnlyWithSubject() { string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Default_policy_rules_sept_2006.xml")); string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Default_policy_objects_sept_2006.xml")); UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "subject line"); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; 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; IPolicyResponseObject pro = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions); //Assert.IsTrue(pro.ChannelType == ChannelType.SMTP); Assert.IsTrue(pro.ContentCollection.Count == 1); Assert.IsTrue(pro.ContentCollection[0].Encrypted == false); Assert.IsTrue(pro.ContentCollection[0].Name == "message subject/body"); Assert.IsTrue(pro.ContentCollection[0].Type == "Email"); Assert.IsTrue(pro.ContentCollection[0].Properties[MailMessagePropertyKeys.Subject] == "subject line"); }
public void TestDoubleProfantyPolicyShouldFire_BUGFix() { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Header"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "confidential f**k shit"); uro.Properties.Add(MailMessagePropertyKeys.Body, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\"><META content=\"MSHTML 6.00.5450.4\" name=GENERATOR><STYLE></STYLE></HEAD><FONT face=Arial><FONT size=2><BODY><DIV> </DIV></BODY></HTML></FONT></FONT>"); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; Workshare.Policy.Engine.UroPolicyEngine engine = CreatePolicyEngineWithRealPolicy(new string[] { Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\src\PolicyEngine.Tests\TestFiles\TestDoubleProfantyPolicyShouldFire_BUGFix\p5default.policy") }); IPolicyResponseObject pro = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Expressions); Assert.IsTrue(pro.ContentCollection.Count == 1); Assert.IsTrue(pro.ContentCollection[0].PolicySetCollection.Count == 1); //find the profane policy and check that its triggered IPolicyResponse profane_policy = null; foreach (IPolicyResponse policy in pro.ContentCollection[0].PolicySetCollection[0].PolicyReportCollection) { if (policy.Name == "Profane Language Policy") { profane_policy = policy; break; } } Assert.IsNotNull(profane_policy); Assert.IsTrue(profane_policy.Triggered); }
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); }
private UniversalRequestObject GetSmtpUroWithOnlyMailMessageHeader() { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; return uro; }
public void Test_07_CreateContainerFromNetMonChannelAsHTTPType() { string[] attachments = new string[] { Path.Combine(TEST_FOLDER, "TestProfanity.doc"), Path.Combine(TEST_FOLDER, "small.xls"), Path.Combine(TEST_FOLDER, "TestDoc.ppt") }; PolicyResponseObject pro = new PolicyResponseObject(); pro.RunAt = RunAt.Client; UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = PolicyType.NetMon; uro.DataTimeStamp = DateTime.Now; uro.Properties[HttpRequestPropertyKeys.Description] = "stuff"; uro.Properties["tag1"] = "This is a test"; uro.Properties["tag2"] = "This is a test"; ProHelper.GenerateUROAttachmentData(uro, attachments); pro.UniversalRequestObject = uro; ContainerBuilder containerBuilder = new ContainerBuilder(pro); IContainer container = containerBuilder.CreateContainerFromUro(); Assert.IsTrue(container.DisplayName == "HTTP Content"); }
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 Test_06_CreateContainerFromNetMonChannelAsEmailType() { string[] attachments = new string[] { Path.Combine(TEST_FOLDER, "TestProfanity.doc"), Path.Combine(TEST_FOLDER, "small.xls"), Path.Combine(TEST_FOLDER, "TestDoc.ppt") }; PolicyResponseObject pro = new PolicyResponseObject(); pro.RunAt = RunAt.Client; UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = PolicyType.NetMon; uro.DataTimeStamp = DateTime.Now; ProHelper.GenerateUROProperties(uro, PolicyType.NetMon); ProHelper.GenerateUROAttachmentData(uro, attachments); pro.UniversalRequestObject = uro; ContainerBuilder containerBuilder = new ContainerBuilder(pro); IContainer container = containerBuilder.CreateContainerFromUro(); Assert.IsTrue(container.DisplayName == "message subject/body"); }
public static void GenerateUROProperties(UniversalRequestObject uro, PolicyType policyType) { uro.Properties[MailMessagePropertyKeys.FileHeader] = String.Empty; uro.Properties[MailMessagePropertyKeys.Body] = "This is a test"; uro.Properties[MailMessagePropertyKeys.FormattedBody] = "This is a test"; uro.Properties[MailMessagePropertyKeys.Subject] = "This is a test"; uro.Properties[SMTPPropertyKeys.RequestChannel] = policyType.ToString(); }
public static UniversalRequestObject GetUro(bool bAddAttachments) { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "4408 0412 3456 7890"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Subject line"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.RoutingType = RoutingTypes.Source; uro.Source.PolicyType = uro.PolicyType; IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(sourceRoutingItem); uro.Destination.RoutingType = RoutingTypes.Destination; uro.Destination.PolicyType = uro.PolicyType; IRoutingItem toRoutingItem = new RoutingItem("sam test"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem); IRoutingItem ccRoutingItem1 = new RoutingItem("*****@*****.**"); ccRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem1); IRoutingItem ccRoutingItem2 = new RoutingItem("*****@*****.**"); ccRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem2); IRoutingItem bccRoutingItem = new RoutingItem("*****@*****.**"); bccRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.BCC); uro.Destination.Items.Add(bccRoutingItem); if (bAddAttachments) { string attachment1 = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestURO_Attachments\attachment1.txt"); string attachment2 = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestURO_Attachments\attachment2.txt"); string attachment3 = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestURO_Attachments\attachment3.txt"); RequestAttachment ra = new RequestAttachment(); ra.FileName = attachment1; ra.Name = Path.GetFileName(attachment1); ra.File = new Workshare.FCS.Lite.Interface.File(attachment1, Path.GetFileNameWithoutExtension(attachment1)); ra.ContentType = "text"; uro.Attachments.Add(ra); RequestAttachment ra2 = new RequestAttachment(); ra2.FileName = attachment2; ra2.Name = Path.GetFileName(attachment2); ra2.File = new Workshare.FCS.Lite.Interface.File(attachment2, Path.GetFileNameWithoutExtension(attachment2)); ra2.ContentType = "fish"; uro.Attachments.Add(ra2); RequestAttachment ra3 = new RequestAttachment(); ra3.FileName = attachment3; ra3.Name = Path.GetFileName(attachment3); ra3.File = new Workshare.FCS.Lite.Interface.File(attachment3, Path.GetFileNameWithoutExtension(attachment3)); ra3.ContentType = "TEXT"; uro.Attachments.Add(ra3); } return uro; }
public EasyMailUro(PolicyType policyType) { m_uro = new UniversalRequestObject(); InitializeUroForPolicyType(policyType); }
private UniversalRequestObject GetHttpUro(bool bWithFiles) { UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = PolicyType.NetMon; // uro.Properties.Add(HttpRequestPropertyKeys.Description, "Stuff"); uro.Properties.Add(HttpRequestPropertyKeys.RequestMethod, "POST"); uro.Properties.Add(HttpRequestPropertyKeys.RequestProtocol, "HTTP/1.1"); uro.Properties.Add(HttpRequestPropertyKeys.RequestURL, "scoats.com"); uro.Properties.Add(HttpRequestPropertyKeys.ReferrerURL, "wallaby.com"); uro.Properties.Add(IPPropertyKeys.OriginIP, "steve.com"); uro.Properties.Add(IPPropertyKeys.OriginPort, "12345"); uro.Properties.Add(IPPropertyKeys.DestinationIP, "mrandmrscoates.com"); uro.Properties.Add(IPPropertyKeys.DestinationPort, "54321"); uro.Properties.Add("EmailSubject", "profanity f**k violation"); uro.Properties.Add("Email Body", "profanity shit violation"); uro.Properties.Add("Some Other Form Field Property", "privacy 1234-1111-1111-1112 violation"); uro.Properties.Add("Yet another Form Field Property", " Confidential Private Classified! Do Not Distribute: For Internal Use Only "); uro.Properties.Add("And", " Social Security Number Bank Details "); uro.Properties.Add("And Finally", " much too old wet back spic f*g "); uro.DataTimeStamp = DateTime.Now; if (bWithFiles) { 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\F*****g Everything.doc"), "F*****g Everything.doc"); } return uro; }
private UniversalRequestObject GetFileUro(int iAttach) { UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = PolicyType.ActiveContent; uro.Properties.Add(Workshare.Policy.Interfaces.ActiveContentPropertyKeys.UserName, "Me"); uro.Properties.Add(Workshare.Policy.Interfaces.ActiveContentPropertyKeys.Application, "Hygiene"); uro.Properties.Add(Workshare.Policy.Interfaces.ActiveContentPropertyKeys.MachineName, "Dev001"); uro.DataTimeStamp = System.DateTime.Now; if (iAttach == 1) TestHelpers.AddAttachment(uro, RequestObjectContentType.DOC, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\F*****g Everything.doc"), "F*****g Everything.doc"); else if (iAttach == 2) TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestZipMore.zip"), "TestZipMore.zip"); return uro; }
public static void GenerateURORoutingDetails(UniversalRequestObject uro, PolicyType policyType) { UniversalRoutingEntity source = new UniversalRoutingEntity(); source.PolicyType = policyType; source.RoutingType = RoutingTypes.Destination; source.Items.Add(new RoutingItem("*****@*****.**")); UniversalRoutingEntity destination = new UniversalRoutingEntity(); destination.PolicyType = policyType; destination.RoutingType = RoutingTypes.Destination; destination.Items.Add(new RoutingItem("*****@*****.**")); destination.Properties[SMTPPropertyKeys.RequestChannel] = policyType.ToString() ; source.Properties[SMTPPropertyKeys.RequestChannel] = policyType.ToString(); uro.Source = source; uro.Destination = destination; }