public void Answer_Is_Encrypted() { IMember createdMember = null; var memberType = MockedContentTypes.CreateSimpleMemberType(); foreach (var p in Constants.Conventions.Member.GetStandardPropertyTypeStubs()) { memberType.AddPropertyType(p.Value); } var mServiceMock = new Mock <IMembershipMemberService>(); mServiceMock.Setup(service => service.Exists("test")).Returns(false); mServiceMock.Setup(service => service.GetByEmail("*****@*****.**")).Returns(() => null); mServiceMock.Setup(service => service.GetDefaultMemberType()).Returns("Member"); mServiceMock.Setup( service => service.CreateWithIdentity(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Callback((string u, string e, string p, string m) => { createdMember = new Member("test", e, u, p, memberType); }) .Returns(() => createdMember); var provider = new MembersMembershipProvider(mServiceMock.Object); provider.Initialize("test", new NameValueCollection()); MembershipCreateStatus status; provider.CreateUser("test", "test", "testtest$1", "*****@*****.**", "test", "test", true, "test", out status); Assert.AreNotEqual("test", createdMember.RawPasswordAnswerValue); Assert.AreEqual(provider.EncryptString("test"), createdMember.RawPasswordAnswerValue); }
public void Create_User_Already_Exists() { var mServiceMock = new Mock <IMembershipMemberService>(); mServiceMock.Setup(service => service.Exists("test")).Returns(true); mServiceMock.Setup(service => service.GetDefaultMemberType()).Returns("Member"); var provider = new MembersMembershipProvider(mServiceMock.Object); provider.Initialize("test", new NameValueCollection()); MembershipCreateStatus status; var user = provider.CreateUser("test", "test", "testtest$1", "*****@*****.**", "test", "test", true, "test", out status); Assert.IsNull(user); }
public void Create_User_Requires_Unique_Email() { var mServiceMock = new Mock <IMembershipMemberService>(); mServiceMock.Setup(service => service.GetByEmail("*****@*****.**")).Returns(() => new Member("test", MockedContentTypes.CreateSimpleMemberType())); mServiceMock.Setup(service => service.GetDefaultMemberType()).Returns("Member"); var provider = new MembersMembershipProvider(mServiceMock.Object); provider.Initialize("test", new NameValueCollection { { "requiresUniqueEmail", "true" } }); MembershipCreateStatus status; var user = provider.CreateUser("test", "test", "testtest$1", "*****@*****.**", "test", "test", true, "test", out status); Assert.IsNull(user); }
public void Password_Hashed_With_Salt() { IMember createdMember = null; var memberType = MockedContentTypes.CreateSimpleMemberType(); foreach (var p in ConventionsHelper.GetStandardPropertyTypeStubs()) { memberType.AddPropertyType(p.Value); } var memberTypeServiceMock = new Mock <IMemberTypeService>(); memberTypeServiceMock.Setup(x => x.GetDefault()).Returns("Member"); var membershipServiceMock = new Mock <IMembershipMemberService>(); membershipServiceMock.Setup(service => service.Exists("test")).Returns(false); membershipServiceMock.Setup(service => service.GetByEmail("*****@*****.**")).Returns(() => null); membershipServiceMock.Setup( service => service.CreateWithIdentity(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())) .Callback((string u, string e, string p, string m, bool isApproved) => { createdMember = new Member("test", e, u, p, memberType, isApproved); }) .Returns(() => createdMember); var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object); provider.Initialize("test", new NameValueCollection { { "passwordFormat", "Hashed" }, { "hashAlgorithmType", "HMACSHA256" } }); MembershipCreateStatus status; provider.CreateUser("test", "test", "testtest$1", "*****@*****.**", "test", "test", true, "test", out status); Assert.AreNotEqual("test", createdMember.RawPasswordValue); string salt; var storedPassword = provider.StoredPassword(createdMember.RawPasswordValue, out salt); var hashedPassword = provider.EncryptOrHashPassword("testtest$1", salt); Assert.AreEqual(hashedPassword, storedPassword); }
public void CanDeleteUser() { MembershipCreateStatus status; var user = Provider.CreateUser("test user", "test password", "email", "question", "answer", true, Guid.NewGuid(), out status); Assert.That(status, Is.EqualTo(MembershipCreateStatus.Success)); var check = Provider.GetUser("test user", false); Assert.That(check, Is.Not.Null); Provider.DeleteUser("test user", true); check = Provider.GetUser("test user", false); Assert.That(check, Is.Null); }