Ejemplo n.º 1
0
        public void BlockActionSingularity()
        {
            #region setup
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] {
                                                Path.Combine(m_testPath, "SamePolicyName\\New Policy Set.policy"),
                                                Path.Combine(m_testPath, "SamePolicyName\\New Policy Set2.policy") });
            
            List<string> attachments = new List<string>();
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Dirty.doc"));
            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments,"*****@*****.**", "*****@*****.**");

            UroPolicyEngine eng = new UroPolicyEngine();
            eng.PolicyCache = policyCache;
            #endregion

            // The line below calls into ActionProcessor.ProcessActions which itself calls PopulateResolvedActionCollection
            // trust me :).
            // This should be refactored to be more specific duh.
            PolicyResponseObject pro = eng.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions) as PolicyResponseObject;

            //all PolicyResponseObject actions should be superseded by the block action if it isnt an exception handling action
            Assert.Greater(pro.ResolvedActionCollection.Count, 0, "At least one action needed");
            List<IPolicyResponseAction> policyResponseActionCollection = ProInquisitor.GetPolicyResponseActions(pro);
            int count = 0;
            foreach (PolicyResponseAction pra in policyResponseActionCollection)
            {
                //if (!pra.Action.Blocking)
                //{
                //    count++;
                //    Assert.IsNotNull(pra.SupersededByAction, "All actions must be superceded by the blocking action");
                //}
            }
            Assert.Greater(count, 0, "no non blocking actions found, possibly wrong test setup ?");
        }
Ejemplo n.º 2
0
        public void NoSupercedingWhenOnlyBlockIsException()
        {
            #region setup
            IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { Path.Combine(m_testPath, "TestActionProcessor - Zip Policy Set.policy") });
            List<string> attachments = new List<string>();
            attachments.Add(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\Dirty.doc"));
            IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments, "*****@*****.**", "*****@*****.**");

            UroPolicyEngine eng = new UroPolicyEngine();
            eng.PolicyCache = policyCache;
            #endregion

            PolicyResponseObject pro = eng.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions) as PolicyResponseObject;
            //No superseding should take place as the BlockAction is only the exceptionhandler in this case
            Assert.Greater(pro.ResolvedActionCollection.Count, 0, "At least one action needed");

            foreach (PolicyResponseAction pra in ProInquisitor.GetPolicyResponseActions(pro))
            {
                Assert.IsNull(pra.SupersededByAction, "No superseding expected");
            }
        }
Ejemplo 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");
		}
Ejemplo n.º 4
0
		ReturnData SetupMockActionTest(List<string> attachments)
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] {
				Path.Combine(POLICY_FOLDER, "Mock User Action Policy.policy") });

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

			IUniversalRequestObject uro = TestHelpers.CreateRemovableDeviceUro(attachments, TEST_FOLDER);

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

			return new ReturnData(pro, uro, container);
		}