示例#1
0
文件: AuthTests.cs 项目: ajj7060/csla
        public void TestAuthCloneRules()
        {
            ApplicationContext.GlobalContext.Clear();

            Csla.ApplicationContext.User = GetPrincipal("Admin");

            Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin"));

            #region "Pre Cloning Tests"

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied 1");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied 2");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied 3");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied 4");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed 5");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed 6");

            #endregion

            #region "After Cloning Tests"

            //Do they work under cloning as well?
            DataPortal.DpRoot NewRoot = root.Clone();

            ApplicationContext.GlobalContext.Clear();

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", NewRoot.DenyReadOnProperty,
                            "Read should have been denied 7");

            //Is it denying write properly?
            NewRoot.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", NewRoot.Auth,
                            "Write should have been denied 8");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", NewRoot.DenyReadWriteOnProperty,
                            "Read should have been denied 9");

            NewRoot.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", NewRoot.Auth,
                            "Write should have been denied 10");

            //Is it allowing both read and write properly?
            Assert.AreEqual(NewRoot.AllowReadWriteOnProperty, NewRoot.Auth,
                            "Read should have been allowed 11");

            NewRoot.AllowReadWriteOnProperty = "AllowReadWriteOnProperty";
            Assert.AreEqual("AllowReadWriteOnProperty", NewRoot.Auth,
                            "Write should have been allowed 12");

            #endregion

            Csla.ApplicationContext.User = new ClaimsPrincipal();
        }
示例#2
0
        public void TestAuthCloneRules()
        {
            ApplicationContext.GlobalContext.Clear();

#pragma warning disable CS0436 // Type conflicts with imported type
            Security.TestPrincipal.SimulateLogin();
#pragma warning restore CS0436 // Type conflicts with imported type

            Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin"));

            #region "Pre Cloning Tests"

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied 1");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied 2");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied 3");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied 4");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed 5");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed 6");

            #endregion

            #region "After Cloning Tests"

            //Do they work under cloning as well?
            DataPortal.DpRoot NewRoot = root.Clone();

            ApplicationContext.GlobalContext.Clear();

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", NewRoot.DenyReadOnProperty,
                            "Read should have been denied 7");

            //Is it denying write properly?
            NewRoot.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", NewRoot.Auth,
                            "Write should have been denied 8");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", NewRoot.DenyReadWriteOnProperty,
                            "Read should have been denied 9");

            NewRoot.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", NewRoot.Auth,
                            "Write should have been denied 10");

            //Is it allowing both read and write properly?
            Assert.AreEqual(NewRoot.AllowReadWriteOnProperty, NewRoot.Auth,
                            "Read should have been allowed 11");

            NewRoot.AllowReadWriteOnProperty = "AllowReadWriteOnProperty";
            Assert.AreEqual("AllowReadWriteOnProperty", NewRoot.Auth,
                            "Write should have been allowed 12");

            #endregion

#pragma warning disable CS0436 // Type conflicts with imported type
            Security.TestPrincipal.SimulateLogout();
#pragma warning restore CS0436 // Type conflicts with imported type
        }
示例#3
0
        public void TestAuthBeginEditRules()
        {
            IDataPortal <DataPortal.DpRoot> dataPortal = _adminDIContext.CreateDataPortal <DataPortal.DpRoot>();

            TestResults.Reinitialise();

            DataPortal.DpRoot root = dataPortal.Create(new DataPortal.DpRoot.Criteria());

            Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin"));

            root.Data = "Something new";

            root.BeginEdit();

            #region "Pre-Testing"

            root.Data = "Something new 1";

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");

            #endregion

            #region "Cancel Edit"

            //Cancel the edit and see if the authorization rules still work
            root.CancelEdit();

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");

            #endregion

            #region "Apply Edit"

            //Apply this edit and see if the authorization rules still work
            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");


            #endregion
        }
示例#4
0
        public void TestAuthCloneRules()
        {
            IDataPortal <DataPortal.DpRoot> dataPortal = _adminDIContext.CreateDataPortal <DataPortal.DpRoot>();
            ApplicationContext applicationContext      = _adminDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            DataPortal.DpRoot root = dataPortal.Fetch(new DataPortal.DpRoot.Criteria());

            Assert.AreEqual(true, applicationContext.User.IsInRole("Admin"));

            #region "Pre Cloning Tests"

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied 1");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied 2");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied 3");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied 4");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed 5");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed 6");

            #endregion

            #region "After Cloning Tests"

            //Do they work under cloning as well?
            DataPortal.DpRoot newRoot = root.Clone();

            TestResults.Reinitialise();

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", newRoot.DenyReadOnProperty,
                            "Read should have been denied 7");

            //Is it denying write properly?
            newRoot.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", newRoot.Auth,
                            "Write should have been denied 8");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", newRoot.DenyReadWriteOnProperty,
                            "Read should have been denied 9");

            newRoot.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", newRoot.Auth,
                            "Write should have been denied 10");

            //Is it allowing both read and write properly?
            Assert.AreEqual(newRoot.AllowReadWriteOnProperty, newRoot.Auth,
                            "Read should have been allowed 11");

            newRoot.AllowReadWriteOnProperty = "AllowReadWriteOnProperty";
            Assert.AreEqual("AllowReadWriteOnProperty", newRoot.Auth,
                            "Write should have been allowed 12");

            #endregion
        }
示例#5
0
        public void TestAuthBeginEditRules()
        {
            Guid          managerInstanceId;
            TestDIContext customDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin"));
            IDataPortal <DataPortal.DpRoot> dataPortal = customDIContext.CreateDataPortal <DataPortal.DpRoot>();
            ApplicationContext applicationContext      = customDIContext.CreateTestApplicationContext();

            TestResults.Reinitialise();

            DataPortal.DpRoot root = dataPortal.Create(new DataPortal.DpRoot.Criteria());

            Assert.AreEqual(true, applicationContext.Principal.IsInRole("Admin"));

            root.Data = "Something new";

            root.BeginEdit();

            #region "Pre-Testing"

            root.Data = "Something new 1";

            //Is it denying read properly?
            managerInstanceId = ((ApplicationContextManagerUnitTests)applicationContext.ContextManager).InstanceId;
            Debug.WriteLine(managerInstanceId);
            string result = root.DenyReadOnProperty;
            //Assert.AreEqual(managerInstanceId.ToString(), result);
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");

            #endregion

            #region "Cancel Edit"

            //Cancel the edit and see if the authorization rules still work
            root.CancelEdit();

            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");

            #endregion

            #region "Apply Edit"

            //Apply this edit and see if the authorization rules still work
            //Is it denying read properly?
            Assert.AreEqual("[DenyReadOnProperty] Can't read property", root.DenyReadOnProperty,
                            "Read should have been denied");

            //Is it denying write properly?
            root.DenyWriteOnProperty = "DenyWriteOnProperty";

            Assert.AreEqual("[DenyWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it denying both read and write properly?
            Assert.AreEqual("[DenyReadWriteOnProperty] Can't read property", root.DenyReadWriteOnProperty,
                            "Read should have been denied");

            root.DenyReadWriteOnProperty = "DenyReadWriteONproperty";

            Assert.AreEqual("[DenyReadWriteOnProperty] Can't write variable", root.Auth,
                            "Write should have been denied");

            //Is it allowing both read and write properly?
            Assert.AreEqual(root.AllowReadWriteOnProperty, root.Auth,
                            "Read should have been allowed");

            root.AllowReadWriteOnProperty = "No value";
            Assert.AreEqual("No value", root.Auth,
                            "Write should have been allowed");


            #endregion
        }