public void InvalidEmptySaltTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "*****@*****.**"; const string password = "******"; var user = CreateUserAccountWithStandardLogin(authDb, primaryEmail, password); Assert.IsNotNull(user); Assert.IsTrue(tAuthDb.SaveCalled); (tAuthDb.Backing[typeof(TestLogin)][0] as TestLogin).Salt = string.Empty; var loginManager = new LoginManager <TestUser, TestLogin>(authDb, DefaultSitePepper, _userNameValidator); var threw = false; try { loginManager.AttemptLogin(primaryEmail, password); } catch (InvalidOperationException) { threw = true; } Assert.IsTrue(threw); }
public StandardAccountManager(IAuthDb authDb, string applicationPepper) { var validator = new EmailAddressValidator(); _userManager = new UserManager <TUser>(authDb, validator); _loginManager = new LoginManager <TUser, TLogin>(authDb, applicationPepper, validator); }
public void MultipleAccountTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string user1Email = "*****@*****.**"; const string user2Email = "*****@*****.**"; const string password = "******"; var user1 = CreateUserAccountWithStandardLogin(authDb, user1Email, password); var user2 = CreateUserAccountWithStandardLogin(authDb, user2Email, password); Assert.IsNotNull(user1); Assert.IsTrue(tAuthDb.SaveCalled); ILoginManager <TestUser> loginManager = new LoginManager <TestUser, TestLogin>(authDb, DefaultSitePepper, _userNameValidator); var res = loginManager.AttemptLogin(user1Email, password); Assert.AreEqual(LoginResult <TestUser> .Type.success, res.ResultType, "LoginManager returned failiure."); Assert.AreEqual(user1, res.User, "User returned from LoginManager was not correct."); res = loginManager.AttemptLogin(user2Email, password); Assert.AreEqual(LoginResult <TestUser> .Type.success, res.ResultType, "LoginManager returned failiure."); Assert.AreEqual(user2, res.User); Assert.AreEqual(user2, res.User, "User returned from LoginManager was not correct."); }
private static TestUser CreateUserAccountWithStandardLogin(IAuthDb authDb, string primaryEmail, string password) { var user = UserManagerTests.CreateUserAccount(authDb, primaryEmail); ILoginManager <TestUser> loginManager = new LoginManager <TestUser, TestLogin>(authDb, DefaultSitePepper, _userNameValidator); loginManager.CreateLogin(user, user.PrimaryEmailAddress, password); return(user); }
public void UserPersists() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "*****@*****.**"; CreateUserAccount(authDb, primaryEmail); Assert.IsTrue(tAuthDb.SaveCalled, "Save was not called on db"); IUserManager <TestUser> otherUserManager = new UserManager <TestUser>(authDb, new EmailAddressValidator()); Assert.IsTrue(otherUserManager.UserExistsByEmail(primaryEmail), "New UserManager backed by same db, user did not exist."); }
public void AssureDistinctHashTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string password = "******"; var user1 = CreateUserAccountWithStandardLogin(authDb, "*****@*****.**", password); var user2 = CreateUserAccountWithStandardLogin(authDb, "*****@*****.**", password); var login1 = tAuthDb.Backing[typeof(TestLogin)][0] as Login <TestUser>; var login2 = tAuthDb.Backing[typeof(TestLogin)][1] as Login <TestUser>; Assert.AreNotEqual(login1.Hash, login2.Hash, "Two user accounts shared the same hash"); }
public void LoginNonAuthenticatePersists() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "*****@*****.**"; const string password = "******"; var user = CreateUserAccountWithStandardLogin(authDb, primaryEmail, password); Assert.IsTrue(tAuthDb.SaveCalled); ILoginManager <TestUser> otherLoginManager = new LoginManager <TestUser, TestLogin>(authDb, DefaultSitePepper, _userNameValidator); Assert.IsTrue(otherLoginManager.LoginExists(user), "LoginUsername did not persist through new LoginManager"); }
public void InvalidSitePepperLoginTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "*****@*****.**"; const string password = "******"; var user = CreateUserAccountWithStandardLogin(authDb, primaryEmail, password); Assert.IsNotNull(user); Assert.IsTrue(tAuthDb.SaveCalled); ILoginManager <TestUser> loginManager = new LoginManager <TestUser, TestLogin>(authDb, $"{DefaultSitePepper}1", _userNameValidator); var res = loginManager.AttemptLogin(primaryEmail, password); Assert.AreEqual(LoginResult <TestUser> .Type.failiure, res.ResultType, "LoginManager incorrectly authenticated login."); }
public void InvalidPrimaryEmailAddressTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "garethmu @gmail.com"; Assert.IsFalse(new EmailAddressValidator().IsValid(primaryEmail), "EmailAddressValidator accepted invalid username"); var threw = false; try { CreateUserAccount(authDb, primaryEmail); } catch (InvalidDataException) { threw = true; } Assert.IsTrue(threw, "Creating user account did not throw expected error with invalid email address"); }
public void InvalidLoginUserNameAddressTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "garethmu @gmail.com"; var lm = new LoginManager <TestUser, TestLogin>(authDb, DefaultSitePepper, _userNameValidator); var threw = false; try { lm.CreateLogin(null, primaryEmail, "password"); } catch (InvalidDataException) { threw = true; } Assert.IsTrue(threw, "LoginManager did not throw error with invalid login name"); }
public void NoDuplicatePrimaryEmailAddressTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "*****@*****.**"; CreateUserAccount(authDb, primaryEmail); var threw = false; try { CreateUserAccount(authDb, primaryEmail); } catch (DuplicateAccountException) { threw = true; } Assert.IsTrue(threw); }
public void InvalidIncorrectSaltTest() { var tAuthDb = new TestAuthDb(); IAuthDb authDb = tAuthDb; const string primaryEmail = "*****@*****.**"; const string password = "******"; var user = CreateUserAccountWithStandardLogin(authDb, primaryEmail, password); Assert.IsNotNull(user); Assert.IsTrue(tAuthDb.SaveCalled); var login = tAuthDb.Backing[typeof(TestLogin)][0] as TestLogin; login.Salt = $"{login.Salt}1"; ILoginManager <TestUser> loginManager = new LoginManager <TestUser, TestLogin>(authDb, DefaultSitePepper, _userNameValidator); var res = loginManager.AttemptLogin(primaryEmail, password); Assert.AreEqual(LoginResult <TestUser> .Type.failiure, res.ResultType, "LoginManager allowed user to login despite salt having changed"); }
/// <summary> /// Inject dependencies /// </summary> /// <param name="db">IAuthDb</param> /// <param name="log">ILog</param> public AuthUserRoleRepository(IAuthDb db, ILog <AuthUserRoleRepository> log) : base(db, log) { }
public UserManager(IAuthDb authDb, EmailAddressValidator emailValidator) { _authDb = authDb; _emailAddressValidator = emailValidator; }
public LoginManager(IAuthDb authDb, string sitePepper, IUserNameValidator userNameValidator) { _authDb = authDb; _sitePepper = sitePepper; _userNameValidator = userNameValidator; }
public static TestUser CreateUserAccount(IAuthDb authDb, string primaryEmail) { IUserManager <TestUser> userManager = new UserManager <TestUser>(authDb, new EmailAddressValidator()); return(userManager.CreateUser(primaryEmail)); }