public void TestAuthExecute() { Assert.Reset(); Csla.ApplicationContext.GlobalContext.Clear(); Csla.Test.Security.TestPrincipal.SimulateLogin(); PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //should work, because we are now logged in as an admin pr.DoWork(); #if SILVERLIGHT Assert.AreEqual(true, Csla.ApplicationContext.User.IsInRole("Admin")); #else Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); #endif //set to null so the other testmethods continue to throw exceptions Csla.Test.Security.TestPrincipal.SimulateLogout(); #if SILVERLIGHT Assert.AreEqual(false, Csla.ApplicationContext.User.IsInRole("Admin")); #else Assert.AreEqual(false, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); #endif }
public void TestAuthRuleSetsOnStaticHasPermissionMethodsWhenAddingAuthzRuleSetExplicitly() { var root = PermissionsRoot.NewPermissionsRoot(); Csla.ApplicationContext.User = GetPrincipal("Admin"); Assert.IsTrue(System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); Assert.IsFalse(System.Threading.Thread.CurrentPrincipal.IsInRole("User")); // implicit usage of ApplicationContext.RuleSet ApplicationContext.RuleSet = ApplicationContext.DefaultRuleSet; Assert.IsFalse(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = "custom1"; Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = "custom2"; Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = ApplicationContext.DefaultRuleSet; // directly specifying which ruleset to use Assert.IsFalse(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), ApplicationContext.DefaultRuleSet)); Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), "custom1")); Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), "custom2")); Csla.ApplicationContext.User = new ClaimsPrincipal(); }
public void TestUnauthorizedAccessToSet() { PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //will cause an exception, because only admins can write to property pr.FirstName = "test"; }
public void TestAuthRuleSetsOnStaticHasPermissionMethodsWhenAddingAuthzRuleSetExplicitly() { var root = PermissionsRoot.NewPermissionsRoot(); Csla.Test.Security.TestPrincipal.SimulateLogin(); #if SILVERLIGHT Assert.IsTrue(Csla.ApplicationContext.User.IsInRole("Admin")); Assert.IsFalse(Csla.ApplicationContext.User.IsInRole("User")); #else Assert.IsTrue(System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); Assert.IsFalse(System.Threading.Thread.CurrentPrincipal.IsInRole("User")); #endif //BusinessRules.AddRule(typeof(PermissionsRoot), new IsInRole(AuthorizationActions.DeleteObject, "User"), ApplicationContext.DefaultRuleSet); //BusinessRules.AddRule(typeof(PermissionsRoot), new IsInRole(AuthorizationActions.DeleteObject, "Admin"), "custom1"); //BusinessRules.AddRule(typeof(PermissionsRoot), new IsInRole(AuthorizationActions.DeleteObject, "User", "Admin"), "custom2"); // implicit usage of ApplicationContext.RuleSet ApplicationContext.RuleSet = ApplicationContext.DefaultRuleSet; Assert.IsFalse(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = "custom1"; Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = "custom2"; Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = ApplicationContext.DefaultRuleSet; // directly specifying which ruleset to use Assert.IsFalse(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), ApplicationContext.DefaultRuleSet)); Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), "custom1")); Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), "custom2")); Csla.Test.Security.TestPrincipal.SimulateLogout(); }
public void TestAuthRuleSetsOnStaticHasPermissionMethodsWhenAddingAuthzRuleSetExplicitly() { var root = PermissionsRoot.NewPermissionsRoot(); #pragma warning disable CS0436 // Type conflicts with imported type Csla.Test.Security.TestPrincipal.SimulateLogin(); #pragma warning restore CS0436 // Type conflicts with imported type Assert.IsTrue(System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); Assert.IsFalse(System.Threading.Thread.CurrentPrincipal.IsInRole("User")); // implicit usage of ApplicationContext.RuleSet ApplicationContext.RuleSet = ApplicationContext.DefaultRuleSet; Assert.IsFalse(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = "custom1"; Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = "custom2"; Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot))); ApplicationContext.RuleSet = ApplicationContext.DefaultRuleSet; // directly specifying which ruleset to use Assert.IsFalse(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), ApplicationContext.DefaultRuleSet)); Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), "custom1")); Assert.IsTrue(BusinessRules.HasPermission(AuthorizationActions.DeleteObject, typeof(PermissionsRoot), "custom2")); #pragma warning disable CS0436 // Type conflicts with imported type Csla.Test.Security.TestPrincipal.SimulateLogout(); #pragma warning restore CS0436 // Type conflicts with imported type }
public void TestUnauthorizedAccessToGet() { Csla.ApplicationContext.GlobalContext.Clear(); PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //this should throw an exception, since only admins have access to this property string something = pr.FirstName; }
public void TestUnauthorizedAccessToSet() { IDataPortal <PermissionsRoot> dataPortal = _anonymousDIContext.CreateDataPortal <PermissionsRoot>(); PermissionsRoot pr = dataPortal.Create(); //will cause an exception, because only admins can write to property pr.FirstName = "test"; }
public void TestUnAuthExecute() { Csla.ApplicationContext.GlobalContext.Clear(); Assert.AreEqual(false, Csla.ApplicationContext.User.IsInRole("Admin")); PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //should fail, because we're not an admin pr.DoWork(); }
public void TestUnauthorizedAccessToGet() { IDataPortal <PermissionsRoot> dataPortal = _anonymousDIContext.CreateDataPortal <PermissionsRoot>(); TestResults.Reinitialise(); PermissionsRoot pr = dataPortal.Create(); //this should throw an exception, since only admins have access to this property string something = pr.FirstName; }
public void TestUnAuthExecute() { IDataPortal <PermissionsRoot> dataPortal = _anonymousDIContext.CreateDataPortal <PermissionsRoot>(); ApplicationContext applicationContext = _anonymousDIContext.CreateTestApplicationContext(); TestResults.Reinitialise(); Assert.AreEqual(false, applicationContext.User.IsInRole("Admin")); PermissionsRoot pr = dataPortal.Create(); //should fail, because we're not an admin pr.DoWork(); }
public void TestAuthExecute() { Csla.ApplicationContext.GlobalContext.Clear(); Csla.ApplicationContext.User = GetPrincipal("Admin"); PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //should work, because we are now logged in as an admin pr.DoWork(); Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); //set to null so the other testmethods continue to throw exceptions Csla.ApplicationContext.User = new ClaimsPrincipal(); Assert.AreEqual(false, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); }
public void TestAuthorizedAccess() { Csla.ApplicationContext.GlobalContext.Clear(); Csla.Test.Security.TestPrincipal.SimulateLogin(); PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //should work, because we are now logged in as an admin pr.FirstName = "something"; string something = pr.FirstName; Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); //set to null so the other testmethods continue to throw exceptions Csla.Test.Security.TestPrincipal.SimulateLogout(); Assert.AreEqual(false, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); }
public void TestAuthExecute() { Csla.ApplicationContext.GlobalContext.Clear(); #pragma warning disable CS0436 // Type conflicts with imported type Csla.Test.Security.TestPrincipal.SimulateLogin(); #pragma warning restore CS0436 // Type conflicts with imported type PermissionsRoot pr = PermissionsRoot.NewPermissionsRoot(); //should work, because we are now logged in as an admin pr.DoWork(); Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); //set to null so the other testmethods continue to throw exceptions #pragma warning disable CS0436 // Type conflicts with imported type Csla.Test.Security.TestPrincipal.SimulateLogout(); #pragma warning restore CS0436 // Type conflicts with imported type Assert.AreEqual(false, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); }
public void TestAuthExecute() { IDataPortal <PermissionsRoot> dataPortal = _adminDIContext.CreateDataPortal <PermissionsRoot>(); TestResults.Reinitialise(); PermissionsRoot pr = dataPortal.Create(); //should work, because we are now logged in as an admin pr.DoWork(); Assert.AreEqual(true, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); // TODO: This no longer makes sense; can't do this anymore? //set to null so the other testmethods continue to throw exceptions //Csla.ApplicationContext.User = new ClaimsPrincipal(); Assert.AreEqual(false, System.Threading.Thread.CurrentPrincipal.IsInRole("Admin")); }
public void TestAuthExecute() { TestDIContext customDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin")); IDataPortal <PermissionsRoot> dataPortal = customDIContext.CreateDataPortal <PermissionsRoot>(); ApplicationContext applicationContext = customDIContext.CreateTestApplicationContext(); TestResults.Reinitialise(); PermissionsRoot pr = dataPortal.Create(); //should work, because we are now logged in as an admin pr.DoWork(); Assert.AreEqual(true, applicationContext.Principal.IsInRole("Admin")); //set to null so the other testmethods continue to throw exceptions applicationContext.User = new ClaimsPrincipal(); Assert.AreEqual(false, applicationContext.Principal.IsInRole("Admin")); }
public void TestAuthorizationAfterEditCycle() { IDataPortal <PermissionsRoot> dataPortal = _adminDIContext.CreateDataPortal <PermissionsRoot>(); TestResults.Reinitialise(); PermissionsRoot pr = dataPortal.Create(); pr.FirstName = "something"; pr.BeginEdit(); pr.FirstName = "ba"; pr.CancelEdit(); // TODO: This test no longer makes any sense; can't do this can we? // Csla.ApplicationContext.User = new ClaimsPrincipal(); PermissionsRoot prClone = pr.Clone(); // Csla.ApplicationContext.User = GetPrincipal("Admin"); prClone.FirstName = "somethiansdfasdf"; }
public void TestAuthorizationAfterEditCycle() { TestDIContext customDIContext = TestDIContextFactory.CreateContext(GetPrincipal("Admin")); IDataPortal <PermissionsRoot> dataPortal = customDIContext.CreateDataPortal <PermissionsRoot>(); ApplicationContext applicationContext = customDIContext.CreateTestApplicationContext(); TestResults.Reinitialise(); PermissionsRoot pr = dataPortal.Create(); pr.FirstName = "something"; pr.BeginEdit(); pr.FirstName = "ba"; pr.CancelEdit(); applicationContext.User = new ClaimsPrincipal(); PermissionsRoot prClone = pr.Clone(); applicationContext.User = GetPrincipal("Admin"); prClone.FirstName = "somethiansdfasdf"; }