示例#1
0
        public static IPolicyCache CreatePolicyCache(string[] filenames)
        {
            Workshare.Policy.ClientCache.LocalPolicyCache lc = new Workshare.Policy.ClientCache.LocalPolicyCache(null, false);

            MockPolicyCache mockPolicyCache = new MockPolicyCache(0);

            foreach (string filename in filenames)
            {
                mockPolicyCache.PolicySets.Add(lc.GetPolicySet(filename));
            }

            return mockPolicyCache;
        }
        public void TestProcessNoPolicyCache()
        {
            IPolicyCache policyCache = new MockPolicyCache(0);
            PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
            ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

            List<string> attachments = new List<string>();
            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

            IContainer container;
            PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
            Assert.IsNotNull(pro);

            RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
            Assert.IsNull(routingProcessor.Process(pro));
        }
示例#3
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!
		}
示例#4
0
		public void TestProcessMessageContent_Monitor()
		{
			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);

			UniversalRequestObject uro = TestHelpers.GetUro(true);
			engine.Monitor(RunAt.Client, uro, true);
			PolicyResponseObject pui = engine.Upi;
			ContentItem content = pui.ContentCollection[3] as ContentItem;
			PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse;
			IPolicyResponse pi = policySet.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;
			policySet = content.PolicySetCollection[0] as PolicySetResponse;
			IPolicyResponse pi3 = policySet.PolicyReportCollection[1];

			Assert.IsTrue(pi3.Name == "Profanity");
			Assert.IsTrue(pi3.Triggered == false);
			content = pui.ContentCollection[1] as ContentItem;
			policySet = content.PolicySetCollection[0] as PolicySetResponse;
			IPolicyResponse pi1 = policySet.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;

			RoutingResponse routingResponse = pi1.Routing as RoutingResponse;
			Assert.IsTrue(routingResponse.ActionSetId == "Profanity_bad");
			//Assert.IsTrue(expression.ActionSetId == "Profanity_bad");
			content = pui.ContentCollection[3] as ContentItem;
			policySet = content.PolicySetCollection[0] as PolicySetResponse;
			pi3 = policySet.PolicyReportCollection[0];

			//expression = pi3.ExpressionCollection[2] as ExpressionResponse;
			routingResponse = pi3.Routing as RoutingResponse;
			Assert.IsTrue(routingResponse.ActionSetId == "Privacy_Privileged_NonTrusted_Actions");
		   // Assert.IsTrue(expression.Type == "ROUTING");
		}
示例#5
0
		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!
		}
示例#6
0
        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);
        }
示例#7
0
		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");
		}
示例#8
0
		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);
		}
示例#9
0
		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);
		}
示例#10
0
		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);
			}
		}
示例#11
0
		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);
		}
示例#12
0
		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);
		}
示例#13
0
		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);
		}
示例#14
0
		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);
		}
示例#15
0
		public void TestPolicyResponseObject_ResolvedActionList_TwoActionsWithDuplicateFileNamesDoesntGetConfused()
		{
			string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\ResolvedActionsRules01.xml"));
			string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\ResolvedActionsObjects01.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\TestProfanity.doc"), "TestProfanity.doc");
			TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"), "TestProfanity.doc");

			IPolicyResponseObject pro = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions);

			Assert.AreEqual(2, pro.ResolvedActionCollection.Count);

			IResolvedAction resolvedAction = pro.ResolvedActionCollection[0];
			Assert.AreEqual("Client_Block", resolvedAction.ResponseAction.Name);
			Assert.AreEqual(1, resolvedAction.ContentCollection.Count);
			Assert.AreEqual("message subject/body", resolvedAction.ContentCollection[0].Name);

			resolvedAction = pro.ResolvedActionCollection[1];
			Assert.AreEqual("HD_Remove", resolvedAction.ResponseAction.Name);
			Assert.AreEqual(2, resolvedAction.ContentCollection.Count);
			Assert.AreEqual("TestProfanity.doc", Path.GetFileName(resolvedAction.ContentCollection[0].Name));
			Assert.AreEqual("TestProfanity.doc", Path.GetFileName(resolvedAction.ContentCollection[1].Name));
		}
示例#16
0
		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);
			}
		}
示例#17
0
		public void TestPolicyResponseObject_ResolvedActionList_NoActions()
		{
			string rulesxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\ResolvedActionsRulesNoActions.xml"));
			string objectsxml = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\ResolvedActionsObjectsNoActions.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\TestProfanity.doc"), "TestProfanity.doc");
			TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"), "TestPrivacy.doc");

			IPolicyResponseObject pro = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions);

			// There are no actions.
			Assert.IsTrue(pro.ResolvedActionCollection.Count == 0);
		}
示例#18
0
		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);
		}
示例#19
0
		private Workshare.Policy.Engine.UroPolicyEngine CreatePolicyEngineWithRealPolicy(string[] filenames)
		{
			ClientCache.LocalPolicyCache lc = new Workshare.Policy.ClientCache.LocalPolicyCache(null, false);
			
			Workshare.Policy.Engine.UroPolicyEngine policyEngine = new Workshare.Policy.Engine.UroPolicyEngine();
			MockPolicyCache mockPolicyCache = new MockPolicyCache(0);
			foreach (string filename in filenames)
			{
				mockPolicyCache.PolicySets.Add(lc.GetPolicySet(filename));
			}
			policyEngine.PolicyCache = mockPolicyCache;
			return policyEngine;
		}
示例#20
0
		public void TestProcessFile_BigFile()
		{
			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\Big_Test.doc"), "AppSpec"));

			engineU.Monitor(RunAt.Client, uro, !true);
			PolicyResponseObject upi = engineU.Upi as PolicyResponseObject;
			ContentItem content = upi.ContentCollection[0] as ContentItem;
			PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse;

			Assert.IsTrue(policySet.PolicyReportCollection[0].Name == "Classified Information Disclosure");
			Assert.IsTrue(policySet.PolicyReportCollection[0].Triggered == false);

			Assert.IsTrue(policySet.PolicyReportCollection[1].Name == "Hidden Information Disclosure");
			Assert.IsTrue(policySet.PolicyReportCollection[1].Triggered == false);

			Assert.IsTrue(policySet.PolicyReportCollection[2].Name == "Private Information Disclosure");
			Assert.IsTrue(policySet.PolicyReportCollection[2].Triggered == false);

			Assert.IsTrue(policySet.PolicyReportCollection[3].Name == "Profane Language");
			Assert.IsTrue(policySet.PolicyReportCollection[3].Triggered == false);

			Assert.IsTrue(policySet.PolicyReportCollection[4].Name == "Discriminatory Language");
			Assert.IsTrue(policySet.PolicyReportCollection[4].Triggered == false);

			Assert.IsTrue(policySet.PolicyReportCollection[5].Name == "Metadata/Security Disclosure");
			Assert.IsTrue(policySet.PolicyReportCollection[5].Triggered == true);

		}
示例#21
0
		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");
		}
示例#22
0
		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
		}
示例#23
0
        static IXPathNavigable GenerateTypicalReport()
        {
            string rulesxml = System.IO.File.ReadAllText(_testFilePath + "ResolvedActionsRules01.xml");
            string objectsxml = System.IO.File.ReadAllText(_testFilePath + "ResolvedActionsObjects01.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(Attachments.NoAttachments);
            TestHelpers.AddAttachment(uro, "Doc", _testFilePath + "TestPrivacy.doc", "TestPrivacy.doc");
            TestHelpers.AddAttachment(uro, "Doc", _testFilePath + "TestProfanity.doc", "TestProfanity.doc");

            IPolicyResponseObject response = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions);
            return response.XMLReport;
        }