Exemplo n.º 1
0
		public void Test_04_ExecuteAction_ProcessContainer()
		{
			ActionExecuter executer = new ActionExecuter(null);
			string[] attachments = new string[] { System.IO.Path.Combine(TEST_FOLDER, "TestClean.doc"), System.IO.Path.Combine(TEST_FOLDER, "TestDoc.doc") };

			IContainer container;
			PolicyResponseObject pro = ProHelper.GeneratePRO(attachments, PolicyType.ClientRemovableMedia, out container);

			Assert.AreEqual(3, pro.ContentCollection.Count); // The folder container, TestClean.doc, TestDoc.doc

			MockExecutableContainerAction containerAction = new MockExecutableContainerAction();
			ProHelper.AddActionToContentCollection(pro, containerAction, false, true);

			List<string> results = new List<string>();
			HasContainerBeenModified(container, results);
			Assert.AreEqual(0, results.Count);

			IUniversalRequestObject uro = executer.ExecuteActions(pro, ref container);

			HasContainerBeenModified(container, results);
			Assert.AreEqual(2, results.Count);

			Assert.AreEqual(2, uro.Attachments.Count);

			Assert.AreEqual(3, pro.ContentCollection.Count);
		}
Exemplo n.º 2
0
		public void RequestTextStreamCalled()
		{
			#region setup
			string readContent = null;
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				Console.WriteLine("readable about to be called from action");
				StreamReader sr = new StreamReader(input.ReadableContent);
				readContent = sr.ReadLine();
				sr.Dispose();
				return input.FileName;
			}
			);


			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			ActionExecuter executer = new ActionExecuter(null);
			executer.GetReadableContent = new ReadableContentRequest(delegate(File source)
			{

				StreamWriter sw = new StreamWriter(new MemoryStream());
				sw.WriteLine("Hello world");
				sw.Flush();
				sw.BaseStream.Position = 0;
				Console.WriteLine("readable set to Hello world");

				return sw.BaseStream;

			});
			#endregion

			// execute
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			// verify
			Assert.AreEqual("Hello world", readContent, "Incorrect readable string provided");
		}
Exemplo n.º 3
0
		public void MimeActionExecutes()
		{
			int count = 0;
			bool isEmail = false;
			IActionProperty currentUser = null;
			#region setup

			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = delegate(IActionData3 input, ActionPropertySet set)
											{
												count++;
												return input.FileName;
											};

			configuration.ExecuteMimeMethod = delegate(IActionData3 input, ActionPropertySet props)
												{
													count++;
													if (props.SystemProperties.ContainsKey("FileType") &&
														props.SystemProperties["FileType"].Value.ToString() == ".email")
														isEmail = true;
													props.SystemProperties.TryGetValue("CurrentUser", out currentUser);
													return input.Content;
												};



			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".email;.ppt", "");
			configuration.Capabilities = new ActionCapabilities(false, true);

			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] {
				Path.Combine(POLICY_FOLDER, "New Policy Set.policy") });

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt"));

			IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments, "*****@*****.**", "*****@*****.**");

			UroPolicyEngine engine = new UroPolicyEngine();
			engine.PolicyCache = policyCache;
			PolicyResponseObject pro = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions) as PolicyResponseObject;
			IContainer container = engine.Container;
			#endregion

			//execute
			ActionExecuter executer = new ActionExecuter(null);
			executer.ExecuteActions(pro, ref container);

			Assert.AreEqual(1, count, "Mime action should be triggered 1x");
			Assert.IsTrue(isEmail, "The FileType property in the system properties wasnt passed to the mime action correctly");
			Assert.AreEqual(pro.UniversalRequestObject.Source.Items[0].Content, currentUser.Value, "CurrentUser not propagated to action");
		}
Exemplo n.º 4
0
		public void DocumentInsideZipContainerFileAction()
		{
			int count = 0;
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				count++;
				return input.FileName;
			}
			);
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*");
			configuration.Capabilities = new ActionCapabilities(false, false);

			List<string> attachments = new List<string>();
			TestHelpers.GetFilesInFolder(Path.Combine(TEST_FOLDER, "ActionExecuter\\TestZipIgnore"), attachments);

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			Assert.AreEqual(7, retValue.Uro.Attachments.Count); // just verifying no one is messing with test data
			Assert.AreEqual(12, retValue.Pro.ContentCollection.Count);
			#endregion


			//execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			Assert.AreEqual(8, count, "Expected  8 action executions");
			Assert.AreEqual(7, outputUro.Attachments.Count, "Incorrect attachment count");
		}
Exemplo n.º 5
0
		public void FolderActionExecutedOnce()
		{
			int count = 0;
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				count++;
				return input.FileName;
			}
			);
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*;.fld", "");
			configuration.Capabilities = new ActionCapabilities(true, false);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Test folder\\Sub Folder\\TestDoc.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			//execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			Assert.AreEqual(1, count, "Folder supported action should be called only once");
		}
Exemplo n.º 6
0
		public void OnlySupportedFileTypesFileAction()
		{
			int count = 0;
			string filename = null;
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				count++;
				filename = input.Properties["FileName"];
				return input.FileName;
			}
			);

			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".ppt", "");

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			//execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);


			Assert.AreEqual(1, count, "Action should have been triggered just once");
			Assert.AreEqual("TestDoc.ppt", Path.GetFileName(filename), "Action was given wrong file to process");


		}
Exemplo n.º 7
0
		public void EnsureContentItemDetailsArePropagatedOnActionException()
		{
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				throw new DataMisalignedException("A rather esoteric exception");
			}
			);
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", "");

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;

			Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback policyEvents =
				new Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback();

			ActionExecuter executer = new ActionExecuter(policyEvents);
			#endregion

			try
			{
				executer.ExecuteActions(retValue.Pro, ref container);
			}
			catch (System.Exception e)
			{
				Assert.IsInstanceOf(typeof(PolicyActionException), e);
				PolicyActionException paeThrown = e as PolicyActionException;

				Assert.IsTrue(paeThrown.Action.StartsWith("MockUser"), "Action name in exception incorrect {0}, expecting MockUser action", paeThrown.Action);
				Assert.AreEqual(Path.GetFileName(attachments[0]), paeThrown.ContentId, "Expected filename in exception details");

			}
		}
Exemplo n.º 8
0
		public void AllZipContainersFilteredOutIfActionDoesntSupportZip()
		{
			int count = 0;
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = delegate(IActionData3 input, ActionPropertySet set)
					{
						count++;
						return input.FileName;
					};
			configuration.MergePropertiesMethod = delegate(ActionPropertySet[] sets)
					{
						return sets[0];
					};
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", ".zip;.fld;.email");
			configuration.Capabilities = new ActionCapabilities(false, false);

			List<string> attachments = new List<string>();
			TestHelpers.GetFilesInFolder(Path.Combine(TEST_FOLDER, "ActionExecuter\\TestZipIgnore"), attachments);

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			Assert.AreEqual(7, retValue.Uro.Attachments.Count); // just verifying no one is messing with test data
			Assert.AreEqual(12, retValue.Pro.ContentCollection.Count);
			#endregion


			//execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			Assert.AreEqual(5, count, "Folder supported action should be called exactly 5 times");
		}
Exemplo n.º 9
0
		public void ExceptionInFileAction()
		{
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				throw new InvalidDataException("This is HAL 3000");
			}
			);
			configuration.MergePropertiesMethod = delegate(ActionPropertySet[] sets)
			{
				return sets[0];
			};

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			// execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);
		}
Exemplo n.º 10
0
		public void ChangeContentsFileAction()
		{
			string outputString = TESTDOC_RTF_CONTENT;
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				input.Properties["FileName"] = Path.ChangeExtension(input.Properties["FileName"], ".txtx");
				return input.FileName;
			}
			);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.rtf"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			// execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			// verify
			Assert.AreEqual(1, outputUro.Attachments.Count, "Output doesnt contain any attachments");
			Assert.IsTrue(outputUro.Attachments[0].Properties["FileName"].EndsWith(".txtx"), "Filename not changed");
			string contents = System.IO.File.ReadAllText(outputUro.Attachments[0].FileName);
			Assert.AreEqual(outputString, contents, "Incorrect contents set");

		}
Exemplo n.º 11
0
		public void RemoveFileNameFileAction()
		{
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				return null;
			}
			);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			// execute
			ActionExecuter executer = new ActionExecuter(null);
			Assert.Throws<PolicyActionException>
				(delegate
			{
				executer.ExecuteActions(retValue.Pro, ref container);
			}
				);
		}
Exemplo n.º 12
0
		public void ChangeFileNameFileAction()
		{
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				input.Properties["FileName"] = Path.ChangeExtension(input.Properties["FileName"], ".foobar");
				return input.FileName;
			}
			);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			//execute
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			//verify
			Assert.AreEqual(2, retValue.Pro.ContentCollection.Count);
			Assert.AreEqual(FileType.WordDocument.ToString(), retValue.Pro.ContentCollection[1].Type);
			Assert.AreEqual(1, outputUro.Attachments.Count);
			Assert.IsTrue(outputUro.Attachments[0].Properties["FileName"].EndsWith(".foobar"), "Filename not changed by action");
		}
Exemplo n.º 13
0
		public void Test_10_ExecuteAction_SMTP_Default_Policy_And_ZIP_Policy()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { 
				Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\Policies\p5default.policy"),
				Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(2, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt"));

			IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

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

			// PROCESS ROUTING
			RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
			Assert.IsNotNull(routingProcessor.Process(pro));

			Assert.AreEqual(4, pro.ContentCollection.Count);
			Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
			Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
			Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
			Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
			Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));

			// PROCESS ACTIONS
			ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
			actionProcessor.ProcessActions(pro);
			ActionUtils.PopulateResolvedActionCollection(pro);

			// EXECUTE ACTIONS
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(pro, ref container);

			//Assert.AreEqual(4, pro.ContentCollection.Count);
			//Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			//Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			//Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
			//Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(2, outputUro.Attachments.Count);
			Assert.AreEqual("TestDoc.ppt", outputUro.Attachments[0].Name);
			Assert.AreEqual("attachments.zip", outputUro.Attachments[1].Name);

			File outputFile = new File(outputUro.Attachments[1].Data, outputUro.Attachments[0].Name);
			Assert.IsNotNull(outputFile);
			outputFile.ExpandContainer(outputFile.Password);
			Assert.AreEqual(2, outputFile.Files.Count);
			Assert.AreEqual("TestProfanity.doc", outputFile.Files[0].DisplayName);
			Assert.AreEqual("Dirty.doc", outputFile.Files[1].DisplayName);
		}
Exemplo n.º 14
0
		public void Test_06_ExecuteAction_SMTP_ZipPolicy_HasZip()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(
				new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(1, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "I am a dirty zip.zip"));

			IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

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

			// PROCESS ROUTING
			RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
			Assert.IsNotNull(routingProcessor.Process(pro));

			Assert.AreEqual(4, pro.ContentCollection.Count);
			Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			Assert.AreEqual(FileType.ZIP.ToString(), pro.ContentCollection[2].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(2, pro.UniversalRequestObject.Attachments.Count);
			Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
			Assert.AreEqual("I am a dirty zip.zip", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));

			// PROCESS ACTIONS
			ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
			actionProcessor.ProcessActions(pro);
			ActionUtils.PopulateResolvedActionCollection(pro);

			// EXECUTE ACTIONS
			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(pro, ref container);

			Assert.AreEqual(4, pro.ContentCollection.Count);
			Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
			Assert.AreEqual(FileType.ZIP.ToString(), pro.ContentCollection[2].Type);
			Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type);

			Assert.AreEqual(2, outputUro.Attachments.Count);
			Assert.AreEqual("TestProfanity.zip", outputUro.Attachments[0].Name);
			Assert.AreEqual("I am a dirty zip.zip", outputUro.Attachments[1].Name);
		}
Exemplo n.º 15
0
		public void RecursiveRequestStreamTransform()
		{
			StringBuilder sb = new StringBuilder();

			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*"); // support everything and folders except mime emails
			configuration.Capabilities = new ActionCapabilities(true, false);

			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(
				delegate(IActionData3 input, ActionPropertySet props)
				{
					foreach (IActionData3 nodes in input.Nested)
					{
						ReadAllContents(nodes, sb);
					}
					input.Nested.Clear();

					ActionData newOne = new ActionData();

					string tempFileName = System.IO.Path.GetTempFileName();
					System.IO.File.WriteAllText(tempFileName, sb.ToString());

					newOne.FileName = tempFileName;
					newOne.DisplayName = input.FileName;
					newOne.Underworld = new File(tempFileName, input.FileName);

					input.Nested.Add(newOne);

					return input.FileName;
				}
				);
			List<string> attachments = new List<string>();
			TestHelpers.GetFilesInFolder(Path.Combine(TEST_FOLDER, "ActionExecuter\\TestZipIgnore"), attachments);

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			ActionExecuter executer = new ActionExecuter(null);
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			foreach (RequestAttachment ra in outputUro.Attachments)
			{
				StreamReader reader = new StreamReader(ra.Data.AsStream());
				Console.WriteLine(reader.ReadToEnd());
				reader.BaseStream.Close();
			}
			Assert.AreEqual(1, outputUro.Attachments.Count, "Expecting one result");
		}
Exemplo n.º 16
0
		public void Test_05_ExecuteAction_SMTP_ZipPolicy()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(
				new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(1, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			using (LocalCopyOfFileManager lcfm = new LocalCopyOfFileManager())
			{
				string folderName = lcfm.ManagedFolder;

				string fileName = Path.Combine(folderName, "TestProfanity.doc");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestProfanity.doc"), fileName);
				attachments.Add(fileName);
				fileName = Path.Combine(folderName, "Dirty.doc");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "Dirty.doc"), fileName);
				attachments.Add(fileName);
				fileName = Path.Combine(folderName, "TestDoc.ppt");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestDoc.ppt"), fileName);
				attachments.Add(fileName);

				IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

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

				// PROCESS ROUTING
				RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
				Assert.IsNotNull(routingProcessor.Process(pro));

				Assert.AreEqual(4, pro.ContentCollection.Count);
				Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
				Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

				Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
				Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
				Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
				Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));

				// PROCESS ACTIONS
				ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
				actionProcessor.ProcessActions(pro);

				ActionUtils.PopulateResolvedActionCollection(pro);

				// EXECUTE ACTIONS
				ActionExecuter executer = new ActionExecuter(null);
				executer.ExecuteActions(pro, ref container);

				Assert.AreEqual(4, pro.ContentCollection.Count);
				Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
				Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

				Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
				Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
				Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
				Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));
			}
		}
Exemplo n.º 17
0
		public void AbortInFileAction()
		{
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				throw new AbortActionException("Aint going no where");
			}
			);

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;
			#endregion

			try
			{
				// execute
				ActionExecuter executer = new ActionExecuter(null);
				IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);
			}
			catch (PolicyActionException ex) // expecting this
			{
				Assert.AreEqual(ActionExceptionHandling.Abort, ex.ExceptionHandling, "Expecting engine to request an abort");
			}
		}
Exemplo n.º 18
0
		public void ExecuteEventsRaised()
		{
			int count = 0;
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				count++;
				return input.FileName;
			}
			);
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", "");

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc"));
			attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt"));
			attachments.Add(Path.Combine(TEST_FOLDER, "Test folder\\Sub Folder\\TestDoc.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;

			Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback policyEvents =
				new Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback();

			ActionExecuter executer = new ActionExecuter(policyEvents);

			#endregion

			//execute            
			IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container);

			Assert.AreEqual(outputUro.Attachments.Count, policyEvents.AfterExecuteEventArgs.Count, "{0} before execute events should have been fired", outputUro.Attachments.Count);
			Assert.AreEqual(outputUro.Attachments.Count, policyEvents.BeforeExecuteEventArgs.Count, "{0} before execute events should have been fired", outputUro.Attachments.Count);
			Assert.AreEqual(outputUro.Attachments.Count, count, "Expected {0} files to be processed", outputUro.Attachments.Count);
		}
Exemplo n.º 19
0
		public void ActionBlowsUpButAllowsUserPrompt()
		{
			#region setup
			MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance;
			configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set)
			{
				throw new DataMisalignedException("A rather esoteric exception");
			}
			);
			configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", "");

			List<string> attachments = new List<string>();
			attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc"));

			ReturnData retValue = SetupMockActionTest(attachments);
			IContainer container = retValue.Container;

			Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback policyEvents =
				new Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback();

			ActionExecuter executer = new ActionExecuter(policyEvents);



			// set(enforce) block on exception to false on all policies
			foreach (ContentItem ci in retValue.Pro.ContentCollection)
			{
				foreach (PolicySetResponse psr in ci.PolicySetCollection)
				{
					foreach (PolicyResponse p in psr.PolicyReportCollection)
					{
						if (p.Triggered)
						{
							p.BlockOnException = false;
						}
					}
				}
			}
			#endregion

			try
			{
				executer.ExecuteActions(retValue.Pro, ref container);
			}
			catch (System.Exception e)
			{
				Assert.IsInstanceOf(typeof(PolicyActionException), e);
				PolicyActionException paeThrown = e as PolicyActionException;

				Assert.IsTrue(paeThrown.Action.StartsWith("MockUser"), "Action name in exception incorrect {0}, expecting MockUser action", paeThrown.Action);
				Assert.AreEqual(ActionExceptionHandling.Prompt, paeThrown.ExceptionHandling, "This exception should result in a block");
			}
		}