public TestIsAuthorizedToConnect ( IPrincipal principal ) : bool | ||
principal | IPrincipal | |
return | bool |
public void AuthorizationServiceBase_IsAuthorizedToConnect_HasPermissionGivenInDefaultGuest_True() { var securityPermission = WindowsGroupPermission.CreateGuests(); securityPermission.View = true; var securityService = new Mock <ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List <WindowsGroupPermission> { securityPermission }); var user = new Mock <IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny <string>())).Returns(false); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsTrue(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_ToLocalServerWithNullIdentityName_WithOnlyBuiltInAdminGroup_UserIsNotAuthorized() { //------------Setup for test-------------------------- var resource = Guid.NewGuid(); var securityPermission = new WindowsGroupPermission { IsServer = false, ResourceID = resource, Permissions = Permissions.View, WindowsGroup = GlobalConstants.WarewolfGroup }; var securityService = new Mock <ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List <WindowsGroupPermission> { securityPermission }); var user = new Mock <IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny <string>())).Returns(true); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsFalse(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_UserHasNoPermissions_False() { //------------Setup for test-------------------------- var resource = Guid.NewGuid(); var securityPermission = new WindowsGroupPermission { IsServer = false, ResourceID = resource, Permissions = Permissions.View }; var securityService = new Mock <ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List <WindowsGroupPermission> { securityPermission }); var user = new Mock <IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny <string>())).Returns(false); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsFalse(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_ToLocalServer_WithBuiltInAdminstratorsOnlyWarewolfAdministratorsGroupMember_UserIsAuthorized() { //------------Setup for test-------------------------- // Setup rest of test ;) var resource = Guid.NewGuid(); var securityPermission = new WindowsGroupPermission { IsServer = false, ResourceID = resource, Permissions = Permissions.View, WindowsGroup = GlobalConstants.WarewolfGroup }; var securityService = new Mock <ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List <WindowsGroupPermission> { securityPermission }); var user = new Mock <IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny <string>())).Returns <string>(role => { if (role == "Warewolf Administrators") { return(false); } return(true); }); user.Setup(u => u.Identity.Name).Returns("TestUser"); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsTrue(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_HasPermissionGivenInDefaultGuest_True() { var securityPermission = WindowsGroupPermission.CreateGuests(); securityPermission.View = true; var securityService = new Mock<ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List<WindowsGroupPermission> { securityPermission }); var user = new Mock<IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny<string>())).Returns(false); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsTrue(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_UserHasNoPermissions_False() { //------------Setup for test-------------------------- var resource = Guid.NewGuid(); var securityPermission = new WindowsGroupPermission { IsServer = false, ResourceID = resource, Permissions = Permissions.View }; var securityService = new Mock<ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List<WindowsGroupPermission> { securityPermission }); var user = new Mock<IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny<string>())).Returns(false); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsFalse(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_ToLocalServerWithNullIdentityName_WithOnlyBuiltInAdminGroup_UserIsNotAuthorized() { //------------Setup for test-------------------------- var resource = Guid.NewGuid(); var securityPermission = new WindowsGroupPermission { IsServer = false, ResourceID = resource, Permissions = Permissions.View, WindowsGroup = GlobalConstants.WarewolfGroup }; var securityService = new Mock<ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List<WindowsGroupPermission> { securityPermission }); var user = new Mock<IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny<string>())).Returns(true); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsFalse(authorized); }
public void AuthorizationServiceBase_IsAuthorizedToConnect_ToLocalServer_WithBuiltInAdminstratorsOnlyWarewolfAdministratorsGroupMember_UserIsAuthorized() { //------------Setup for test-------------------------- // Setup rest of test ;) var resource = Guid.NewGuid(); var securityPermission = new WindowsGroupPermission { IsServer = false, ResourceID = resource, Permissions = Permissions.View, WindowsGroup = GlobalConstants.WarewolfGroup }; var securityService = new Mock<ISecurityService>(); securityService.SetupGet(p => p.Permissions).Returns(new List<WindowsGroupPermission> { securityPermission }); var user = new Mock<IPrincipal>(); user.Setup(u => u.IsInRole(It.IsAny<string>())).Returns<string>(role => { if(role == "Warewolf Administrators") { return false; } return true; }); user.Setup(u => u.Identity.Name).Returns("TestUser"); var authorizationService = new TestAuthorizationServiceBase(securityService.Object) { User = user.Object }; //------------Execute Test--------------------------- var authorized = authorizationService.TestIsAuthorizedToConnect(user.Object); //------------Assert Results------------------------- Assert.IsTrue(authorized); }