Exemple #1
0
        public void OldActionInterfaceImplementation()
        {
            #region setup
            string rulesXML = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction\rules.xml"));
            string objectsXML = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction\objects.xml"));

            //substitute class in existing policy files with ours.
            //this is not really kosher for purists, but no usable object model neccessitates this
            objectsXML =
                objectsXML.Replace("assembly=\"Typical3rdPartyAction.dll\" class=\"Typical3rdPartyAction.ThirdPartyAction\"",
                        "assembly=\"MockUserAction.dll\" class=\"MockUserAction.MockUserActionOld\"");
            GeneralPolicyProcessor gpp = new GeneralPolicyProcessor();
            //start following parameters have no bearing on this test case but need to be filled in for the gpp to run
            gpp.FileType = "*.email";
            gpp.CurrentUser = "******";
            gpp.CurrentRunAtMode = RunAt.Client;
            gpp.RecipientList = new string[] { "*****@*****.**" };
            //end irrelevant parameters
            gpp.Initialise(RunAt.Client, rulesXML, objectsXML);
            #endregion

            string assemblyName, className;
            CachedAction action = gpp.LoadActionObject("f2c04c19-54fb-48f6-af3d-82c9404deaf2",
                "3rd Party", out assemblyName, out className);

            Assert.IsNotNull(action, "No {0} action found", "3rd Party");
            Assert.IsTrue(action.Action.SupportedFileCollection.Supports(".*"), "Action should support all files");
            Assert.IsTrue((bool) action.Properties["TestBoolProp"].Value, "Incorrect value for TestBoolProp");
            Assert.AreEqual("Hello world", action.Properties["TestStringProp"].Value.ToString(), "Incorrect value for TestStringProp");

            ActionData testData = new ActionData();
			testData.FileName = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\TestfileActionLoad.txt");
			testData.Properties.Add("DisplayName", Path.GetFileName(testData.FileName));	
            ActionPropertySet propertySet = new ActionPropertySet();

            StreamReader sr = new StreamReader(action.Action.Execute(testData, propertySet));
            string result = sr.ReadToEnd().TrimEnd('\r', '\n');
            Assert.AreEqual("Just what do you think you're doing, Dave?", result, "Incorrect HAL message");

        }
Exemple #2
0
        /// <summary>
        /// Tests loading of a workshare signed action with no unmanaged dependencies.
        /// This test relies on an example action precompiled and committed to source control as
        /// test data : this AbortOnExecute action can be found in the PESAction solution. 
        /// </summary>
       // [Test]
        public void LoadSignedActionFromLocation()
        {
            ActionDetails ad = new ActionDetails("Abort",
                 Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction"),
                "Workshare.Policy.Actions.AbortOnExecuteAction.dll",
                "Workshare\\ProtectEnterprise\\Actions",
                "Workshare.Policy.Actions.AbortOnExecuteAction",
                "f2099407-96c1-4e5d-8b6a-ed5163b41fd4");

            System.IO.File.Move(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ad.AssemblyName),
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ad.AssemblyName + ".tmp"));
            try
            {
                #region setup
                RegistryTree rt = new RegistryTree(ad.HKLMRegLocation, ad.AssemblyName, ad.Path);
                //now comes the ugly bit of the setup
                //rules and object file below retrieved from a policy created with PolicyDesigner and copy/pasted from the
                //policy explorer
                string rulesXML = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction\rules.xml"));
                string objectsXML = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction\objects.xml"));
                GeneralPolicyProcessor gpp = new GeneralPolicyProcessor();
                //start following parameters have no bearing on this test case but need to be filled in for the gpp to run
                gpp.FileType = "*.email";
                gpp.CurrentUser = "******";
                gpp.CurrentRunAtMode = RunAt.Client;
                gpp.RecipientList = new string[] { "*****@*****.**" };
                //end irrelevant parameters
                gpp.Initialise(RunAt.Client, rulesXML, objectsXML);

            #endregion

                string assemblyName, className;

                //execute
                //parameters must match what is setup in the object and rules file
                CachedAction action = gpp.LoadActionObject(ad.ObjectRef, ad.Name, out assemblyName, out className);

                //verify

                Assert.IsNotNull(action, "No {0} action found", ad.Name);
                VerifyObjectLocation(action.Action, ad);
            }
            finally
            {
                System.IO.File.Move(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ad.AssemblyName + ".tmp"),
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ad.AssemblyName));
            }
        }
Exemple #3
0
        /// <summary>
        /// Tests loading of a 3rd party unsigned action with a dependency on an unmanaged dll. 
        /// Verifies that all the action ifaces are loaded from the correct location and that the unmanaged dll
        /// is loaded from the correct location.
        /// </summary>
       // [Test]
        public void LoadUnsignedActionFromLocation()
        {
			if (Marshal.SizeOf(typeof(IntPtr)) == 8)
				throw new IgnoreException("can't run this test easily on 64 bit without recompiling the action and adding its references and a whole bunch of related stuff");

            #region setup
            ActionDetails ad = new ActionDetails("3rd Party",
                Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\UnsignedAction"),
                "Typical3rdPartyAction.dll",
                "Workshare\\ProtectEnterprise\\Actions",
                "Typical3rdPartyAction",
                "f2c04c19-54fb-48f6-af3d-82c9404deaf2");

            string managedDll = "unmanageddll.dll";
            string managedDllLocation = Path.Combine(Path.GetDirectoryName(ad.Path), managedDll);
            string targetDllLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, managedDll);

            //attempt to copy the managed dll to the basedirectory of current appdomain so its in 2 locations
            System.IO.File.Copy(managedDllLocation,targetDllLocation, true);
            //add temp file to the deletion list
            m_TempFiles.Add(targetDllLocation);

            RegistryTree rt = new RegistryTree(ad.HKLMRegLocation, ad.AssemblyName, ad.Path);
            string rulesXML = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction\rules.xml"));
            string objectsXML = System.IO.File.ReadAllText(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\SignedPartyAction\objects.xml"));
            GeneralPolicyProcessor gpp = new GeneralPolicyProcessor();
            //start following parameters have no bearing on this test case but need to be filled in for the gpp to run
            gpp.FileType = "*.email";
            gpp.CurrentUser = "******";
            gpp.CurrentRunAtMode = RunAt.Client;
            gpp.RecipientList = new string[] { "*****@*****.**" };
            //end irrelevant parameters
            gpp.Initialise(RunAt.Client, rulesXML, objectsXML);
            Chilkat.Cert cert = new Chilkat.Cert();
            #endregion

            string assemblyName, className;
            CachedAction action = gpp.LoadActionObject(ad.ObjectRef, ad.Name, out assemblyName, out className);

            Assert.IsNotNull(action, "No {0} action found", ad.Name);
            VerifyObjectLocation(action.Action, ad);
            //verify location of unmanaged dll - cause unmanaged dll is latebound we need to invoke to make sure it gets loaded first
            ActionPropertySet adata = action.Action.PropertySet;
            ActionData testData = new ActionData();
   			testData.FileName = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\PolicyEngine.Tests\TestFiles\TestfileActionLoad.txt");
			testData.Properties.Add("DisplayName", Path.GetFileName(testData.FileName));	
            action.Action.Execute(testData, adata);
            // testdll.dll should be loaded now
            bool found = false;
            foreach (ProcessModule pm in Process.GetCurrentProcess().Modules)
            {
                if (pm.ModuleName.Equals(managedDll, StringComparison.InvariantCultureIgnoreCase))
                {
                    found = true;
                    Assert.IsTrue(string.Equals(managedDllLocation, pm.FileName, StringComparison.InvariantCultureIgnoreCase),
                        "{0} loaded from incorrect location, expected {1}, actual {2}", managedDll, managedDllLocation, pm.FileName);
                }
            }
            Assert.IsTrue(found, "unmanaged dll {0} not found in current process' modules", managedDll);
        }