Пример #1
0
        public void TestEnforce_Construct_SystemNetMailMessage_CleanBody()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\SystemNetMailMessageRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\SystemNetMailMessageObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            string bodyText = "clean text";

            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(@"P:\projects\Hygiene\src\TestDocuments\TestClean.doc"));

            MailMessage mailMessage = engine.Enforce(RunAtMode.Client, message, null);
            Assert.IsTrue(mailMessage.BodyEncoding == System.Text.Encoding.ASCII);
            Assert.IsTrue(mailMessage.From.Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.To[0].Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.To[1].Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.To[2].Address == "*****@*****.**");
            Assert.IsTrue(mailMessage.Subject == "subject line"); 
            Assert.IsTrue(mailMessage.Body == "clean text");    
            Assert.IsTrue(mailMessage.Attachments.Count == 1);

            Assert.IsTrue(auditor.m_MailMessage.Attachments.Length == 2);
            Assert.IsTrue(auditor.m_MailMessage.Attachments[0].Name == "TestClean.doc");
            Assert.IsTrue(auditor.m_MailMessage.Attachments[1].Name == "subject line");
        }
Пример #2
0
        public void TestAuditMessageOnlyCalledOnce()
        {
            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore();

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "subject line", "body");
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"));
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));
            engine.Monitor(Workshare.Policy.Interfaces.RunAtMode.Both, message, null);
            Assert.AreEqual(1, auditor.m_AuditCalledCount);
            Assert.IsTrue(auditor.m_AuditMessageCalled);
            Assert.IsTrue(auditor.m_MailMessage.Attachments.Length == 3);
        }
Пример #3
0
        public void TestProcessActions_MetaDataViolation()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessActionsRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessActionsObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

           // string bodyText = "This is a safe email";

            List<IFile> files = new List<IFile>();
            files.Add(new Workshare.Policy.Engine.File(@"P:\projects\Hygiene\src\TestDocuments\Dirty.doc", "Dirty"));
            
            List<FileRouting> fileRoutings = engine.ProcessFiles(RunAtMode.Client, files);

            string from = @"*****@*****.**";
            List<string> to = new List<string>();
            to.Add(@"*****@*****.**");
            to.Add(@"*****@*****.**");

            List<string> cc = new List<string>();
            List<string> bcc = new List<string>();

            List<FileActions> fileActions = engine.ProcessRoutings(RunAtMode.Client, fileRoutings, from, to.ToArray(), cc.ToArray(), bcc.ToArray());
            Assert.IsTrue(fileActions[0].ActionObjects[0].Name == "HD_Remove");
            List<IFile> processedFiles = engine.ProcessActions(RunAtMode.Client, fileActions);
            Assert.IsTrue(processedFiles.Count == 1);
        }
Пример #4
0
        public void TestProcessFiles_NoViolations()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessFilesRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessFilesObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            List<IFile> files = new List<IFile>();
            files.Add(new Workshare.Policy.Engine.File(@"P:\projects\Hygiene\src\TestDocuments\TestClean.doc", "TestCleanDocument"));

            List<FileRouting> fileRoutings = engine.ProcessFiles(RunAtMode.Client, files);
            Assert.IsTrue(fileRoutings.Count == 1);
            Assert.IsTrue(fileRoutings[0].RoutingIds.Count == 0);

            DocumentEntity firstDocument = fileRoutings[0].DocumentEntity;

            Assert.IsTrue(firstDocument.DocumentEvents[0].ConditionRules[0].ConditionRuleName == "Privacy");
            Assert.IsFalse(firstDocument.DocumentEvents[0].ConditionRules[0].Violated);
            Assert.IsTrue(firstDocument.DocumentEvents[0].ConditionRules[1].ConditionRuleName == "Profanity");
            Assert.IsFalse(firstDocument.DocumentEvents[0].ConditionRules[1].Violated);
        }
Пример #5
0
        public void TestProcessFiles_MultipleViolations()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessFilesRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessFilesObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            List<IFile> files = new List<IFile>();
            files.Add(new Workshare.Policy.Engine.File(@"P:\projects\Hygiene\src\TestDocuments\TestProfanity.doc", "Profanity doc"));
            files.Add(new Workshare.Policy.Engine.File(@"P:\projects\Hygiene\src\TestDocuments\TestPrivacy.doc", "Privacy doc"));

            List<FileRouting> fileRoutings = engine.ProcessFiles(RunAtMode.Client, files);
            Assert.IsTrue(fileRoutings.Count == 2);
            
            Assert.IsTrue(fileRoutings[0].RoutingIds[0].RoutingId == "Profanity_Routing");
            Assert.IsTrue(fileRoutings[1].RoutingIds[0].RoutingId == "Privacy_Routing");

            DocumentEntity firstDocument = fileRoutings[0].DocumentEntity;

            Assert.IsTrue(firstDocument.DocumentEvents[0].ConditionRules[0].ConditionRuleName == "Privacy");
            Assert.IsFalse(firstDocument.DocumentEvents[0].ConditionRules[0].Violated);
            Assert.IsTrue(firstDocument.DocumentEvents[0].ConditionRules[1].ConditionRuleName == "Profanity");
            Assert.IsTrue(firstDocument.DocumentEvents[0].ConditionRules[1].Violated);
            ConditionEntity[] profanityConditions = firstDocument.DocumentEvents[0].ConditionRules[1].Conditions;
            Assert.IsTrue(profanityConditions[0].ConditionData == "The Seven Dirty Words! and some...");
            Assert.IsTrue(profanityConditions[0].ConditionRating == "Low");
            Assert.IsTrue(profanityConditions[0].ConditionType == "CONDITION");
            Assert.IsTrue(profanityConditions[0].ConditionViolated == true);

            ConditionPropertyEntity[] condtionProperties = profanityConditions[0].ConditionProperties;
            Assert.IsTrue(condtionProperties.Length == 5);
            
            DocumentEntity secondDocument = fileRoutings[1].DocumentEntity;
            Assert.IsTrue(secondDocument.DocumentEvents[0].ConditionRules[0].ConditionRuleName == "Privacy");
            Assert.IsTrue(secondDocument.DocumentEvents[0].ConditionRules[0].Violated);
            Assert.IsTrue(secondDocument.DocumentEvents[0].ConditionRules[1].ConditionRuleName == "Profanity");
            Assert.IsFalse(secondDocument.DocumentEvents[0].ConditionRules[1].Violated);
        }
Пример #6
0
        public void TestProcessMessageContent_MultipleViolations()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessMessageContentRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessMessageContentObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            string bodyText = "4408 0412 3456 7890 piss";

            List<string> attachmentNames = new List<string>();
            attachmentNames.Add("attachment1");
            attachmentNames.Add("F**k");
            attachmentNames.Add("c**t");

            FileRouting fileRouting = engine.ProcessMessageContent(RunAtMode.Client, "Random subject", bodyText, attachmentNames);

            EventEntity documentEvent = fileRouting.DocumentEntity.DocumentEvents[0];
            ConditionRuleEntity privacyRule = documentEvent.ConditionRules[0];

            Assert.IsTrue(privacyRule.ConditionRuleName == "Privacy");
            Assert.IsTrue(privacyRule.Violated == true);
            Assert.IsTrue(privacyRule.Conditions[0].ConditionData == "Possible Social Security Number");
            Assert.IsTrue(privacyRule.Conditions[0].ConditionViolated == false);
            Assert.IsTrue(privacyRule.Conditions[1].ConditionData == "Possible Credit Card Number");
            Assert.IsTrue(privacyRule.Conditions[1].ConditionViolated == true);
            Assert.IsTrue(privacyRule.Conditions[1].ConditionProperties[0].Name == "Body");
            Assert.IsTrue(privacyRule.Conditions[1].ConditionProperties[0].PropertyValue == "4408 0412 3456 7890");

            ConditionRuleEntity profanityRule = documentEvent.ConditionRules[1];

            Assert.IsTrue(profanityRule.ConditionRuleName == "Profanity");
            Assert.IsTrue(profanityRule.Violated == true);
            Assert.IsTrue(profanityRule.Conditions[0].ConditionProperties[0].Name == "Body");
            Assert.IsTrue(profanityRule.Conditions[0].ConditionProperties[0].PropertyValue == "piss");
            Assert.IsTrue(profanityRule.Conditions[0].ConditionProperties[1].Name == "Attachments");
            Assert.IsTrue(profanityRule.Conditions[0].ConditionProperties[1].PropertyValue == "F**k");
            Assert.IsTrue(profanityRule.Conditions[0].ConditionProperties[2].Name == "Attachments");
            Assert.IsTrue(profanityRule.Conditions[0].ConditionProperties[2].PropertyValue == "c**t");

            Assert.IsTrue(profanityRule.Conditions[0].ConditionData == "The Seven Dirty Words! and some...");
        }
Пример #7
0
        public void TestProcessMessageContent_NoViolation()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessMessageContentRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\TestProcessMessageContentObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            string bodyText = "Body Text with no violation";

            List<string> attachmentNames = new List<string>();
            attachmentNames.Add("attachment1");
            attachmentNames.Add("attachment2");
            attachmentNames.Add("attachment3");

            FileRouting fileRouting = engine.ProcessMessageContent(RunAtMode.Client, "Random subject", bodyText, attachmentNames);

            EventEntity documentEvent = fileRouting.DocumentEntity.DocumentEvents[0];
            ConditionRuleEntity privacyRule = documentEvent.ConditionRules[0];
            ConditionRuleEntity profanityRule = documentEvent.ConditionRules[1];

            Assert.IsTrue(privacyRule.ConditionRuleName == "Privacy");
            Assert.IsFalse(privacyRule.Violated);
            Assert.IsTrue(profanityRule.ConditionRuleName == "Profanity");
            Assert.IsFalse(profanityRule.Violated);
        }
Пример #8
0
        public void TestMailMessage_AttachmentRemoved_ProfanityViolation()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\rsa_server_rules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\rsa_server_objects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            System.Net.Mail.MailMessage profanityMessage = new System.Net.Mail.MailMessage("*****@*****.**", "[email protected],[email protected],[email protected]", "random subject line", "random body text");
            profanityMessage.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));

            System.Net.Mail.MailMessage mailMessage = engine.Enforce(RunAtMode.Client, profanityMessage, null);
            Assert.IsTrue(mailMessage.Attachments.Count == 0);

            MailMessageEntity msgEntity = auditor.m_MailMessage;

            Assert.IsTrue(msgEntity.Attachments.Length == 2);
            ActionEntity actionEntity = msgEntity.Attachments[0].DocumentEvents[0].ConditionRules[0].EventActions[0];
            Assert.IsTrue(actionEntity.ActionData == "Server_Block");
        }
Пример #9
0
        //[Ignore("TODO: Fix this. Skipped by PW - test fails becaise ActionEntity action2 does not exist in ConditionRule")]
        public void TestEnforce_MailMessageEntity_ActionProperties()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            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(@"P:\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"));
            message.Attachments.Add(new System.Net.Mail.Attachment(@"P:\projects\Hygiene\src\TestDocuments\TestProfanity.doc"));

            engine.Enforce(RunAtMode.Client, message, null);
            MailMessageEntity mailMessage = auditor.m_MailMessage;

            ActionEntity action1 = mailMessage.Attachments[0].DocumentEvents[0].ConditionRules[0].EventActions[0];
            Assert.IsTrue(action1.ActionProcessed);
            Assert.IsTrue(action1.ActionProperties.Length == 3);
            Assert.IsTrue(action1.ActionProperties[0].Name == "Unblock");
            Assert.IsTrue(action1.ActionProperties[0].PropertyValue == "False");
            Assert.IsTrue(action1.ActionProperties[1].Name == "AllowOverride");
            Assert.IsTrue(action1.ActionProperties[1].PropertyValue == "True");
            Assert.IsTrue(action1.ActionProperties[2].Name == "FileSelected");
            Assert.IsTrue(action1.ActionProperties[2].PropertyValue == "False");

            ActionEntity action3 = mailMessage.Attachments[2].DocumentEvents[0].ConditionRules[0].EventActions[0];
            Assert.IsTrue(action3.ActionProcessed);
            Assert.IsTrue(action3.ActionProperties.Length == 3);
            Assert.IsTrue(action1.ActionProperties[0].Name == "Unblock");
            Assert.IsTrue(action1.ActionProperties[0].PropertyValue == "False");
            Assert.IsTrue(action1.ActionProperties[1].Name == "AllowOverride");
            Assert.IsTrue(action1.ActionProperties[1].PropertyValue == "True");
            Assert.IsTrue(action1.ActionProperties[2].Name == "FileSelected");
            Assert.IsTrue(action1.ActionProperties[2].PropertyValue == "False");
        }
Пример #10
0
        public void TestExecuteEvents_AreCalled()
        {
            string rulesxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceRules.xml");
            string objectsxml = System.IO.File.ReadAllText(@"P:\projects\Hygiene\src\TestDocuments\EnforceObjects.xml");

            Workshare.Policy.Engine.EmailPolicyEngine engine = new Workshare.Policy.Engine.EmailPolicyEngine();
            IRuleStore store = new MockRuleStore(rulesxml, objectsxml);

            MockEmailPolicyAuditor auditor = new MockEmailPolicyAuditor();

            engine.SetRuleStore(store);
            engine.SetPolicyAuditor(auditor);

            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(@"P:\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"));

            MockPolicyEvents policyEvents = new MockPolicyEvents();
            engine.SetPolicyEvents(policyEvents);

            Assert.IsTrue(policyEvents.AfterExecuteEventArgs.Count == 0);
            Assert.IsTrue(policyEvents.BeforeExecuteEventArgs.Count == 0);
            
            engine.Enforce(RunAtMode.Client, message, null);

            Assert.IsTrue(policyEvents.AfterExecuteEventArgs.Count == 2);
            Assert.IsTrue(policyEvents.BeforeExecuteEventArgs.Count == 2);
        }