public void Ctor_WHEN_User_Has_An_Id_THEN_Sets_IsAuthenticated_To_True() { var user = new User(); user.SetProperty(u => u.Id, 1); var identity = new JumbleblocksUserIdentity(user); identity.IsAuthenticated.ShouldBeTrue(); }
public void Ctor_WHEN_User_Has_UserName_Joe_THEN_Name_Property_Returns_Joe() { const string UserName = "******"; var user = new User { Username = UserName }; user.SetProperty(u => u.Id, 1); var identity = new JumbleblocksUserIdentity(user); identity.Name.ShouldEqual(UserName); }
public void CanPerformOperation_GIVEN_Ctor_user_Has_Operation_But_Identity_Is_Not_Authenticated_THEN_Returns_False() { const string OperationName = "ABC"; var operation = new Operation { Name = OperationName }; var role = new Role { Name = "role" }; role.AddOperation(operation); var user = new User(); user.SetProperty(u => u.Id, 1); user.AddRole(role); var mockedIdentity = new Mock<IJumbleblocksIdentity>(); mockedIdentity.Setup(i => i.IsAuthenticated).Returns(false); var principal = new JumbleblocksPrincipal(mockedIdentity.Object, user); var result = principal.CanPerformOperation(OperationName); result.ShouldBeFalse(); }
public void RetrievePrincipal_GIVEN_User_Contains_User_With_Username_ABC_Password_That_Is_An_MD5_Hash_Of_DEF_WHEN_Username_Is_ABC_AND_Password_EFG_THEN_Returns_Principal_With_Identity_Of_Type_JumbleblocksAnonymousIdentity() { const string Username = "******"; const string Password = "******"; var hasher = new MD5StringHasher(); string hashedPassword = hasher.GetHash(Password); var user = new User(); user.SetProperty(u => u.Id, 1); user.Username = Username; var mockedRepository = new Mock<IUserRepository>(); mockedRepository.Setup((r) => r.LoadForUsernameAndPassword(It.IsAny<string>(), hashedPassword)).Returns(user); var securityService = new SecurityService(mockedRepository.Object, hasher); var principal = securityService.RetrievePrincipal(Username, "EFG"); principal.Identity.ShouldBeInstanceOfType(typeof(JumbleblocksAnonymousIdentity)); }
public void IsInRole_GIVEN_Has_Role_ABC_WHEN_roleName_IS_DEF_THEN_Returns_False() { const string RoleName = "ABC"; const string CheckRoleName = "DEF"; var role = new Role { Name = RoleName }; var user = new User(); user.SetProperty(u => u.Id, 1); user.AddRole(role); var principal = new JumbleblocksPrincipal(new JumbleblocksUserIdentity(user), user); var result = principal.IsInRole(CheckRoleName); result.ShouldBeFalse(); }
public void HasOperation_GIVEN_Has_Operation_ABC_WHEN_operationName_IS_DEF_THEN_Returns_False() { const string OperationName = "ABC"; const string CheckOperationName = "DEF"; var role = new Role { Name = "role" }; role.AddOperation(new Operation { Name = OperationName }); var user = new User(); user.SetProperty(u => u.Id, 1); user.AddRole(role); var principal = new JumbleblocksPrincipal(new JumbleblocksUserIdentity(user), user); var result = principal.HasOperation(CheckOperationName); result.ShouldBeFalse(); }
public void CanPerformRole_GIVEN_Ctor_user_Has_Role_And_Identity_Is_Authenticated_THEN_Returns_True() { const string RoleName = "ABC"; var role = new Role { Name = RoleName }; var user = new User(); user.SetProperty(u => u.Id, 1); user.AddRole(role); var mockedIdentity = new Mock<IJumbleblocksIdentity>(); mockedIdentity.Setup(i => i.IsAuthenticated).Returns(true); var principal = new JumbleblocksPrincipal(mockedIdentity.Object, user); var result = principal.CanPerformRole(RoleName); result.ShouldBeTrue(); }