public async Task VerifyAccessTokenUserIsVerified() { const string password = "******"; const string email = "*****@*****.**"; const string deviceId = "mydevice"; const string tokenString = "randomtokenstring12345"; AuthToken token; User user; using (var context = new QuizContext(ManagerTestHelper.Options)) { var sut = ManagerTestHelper.GetAuthManager(context); user = await ManagerTestHelper.AddUserAsync(context, 1, email, password); await ManagerTestHelper.AddAuthTokenAsync(context, user.Id, deviceId, tokenString, true); await context.SaveChangesAsync(); token = await sut.VerifyAccessToken(tokenString); } Assert.AreEqual(tokenString, token.Token); Assert.AreEqual(user.Id, token.UserId); Assert.IsTrue(token.IsVerified); }
public async Task GenerateTokenByIdExistingToken() { const string password = "******"; const string email = "*****@*****.**"; const string deviceId = "mydevice"; const string tokenString = "randomtokenstring12345"; AuthToken token; UserToken existingToken; using (var context = new QuizContext(ManagerTestHelper.Options)) { var sut = ManagerTestHelper.GetAuthManager(context); var user = await ManagerTestHelper.AddUserAsync(context, 1, email, password); await ManagerTestHelper.AddAuthTokenAsync(context, user.Id, deviceId, tokenString, true); await context.SaveChangesAsync(); token = await sut.GenerateTokenAsync(user.Id, deviceId); existingToken = await context.UserTokens.FindAsync(user.Id, deviceId); } Assert.AreNotEqual(tokenString, existingToken.Token); Assert.AreEqual(token.Token, existingToken.Token); }
private async Task <UserToken> GetAccessTokenInternal(bool isValid) { const string password = "******"; const string email = "*****@*****.**"; const string deviceId = "mydevice"; const string tokenString = "randomtokenstring12345"; UserToken token; using (var context = new QuizContext(ManagerTestHelper.Options)) { var sut = ManagerTestHelper.GetAuthManager(context); var user = await ManagerTestHelper.AddUserAsync(context, 1, email, password); await ManagerTestHelper.AddAuthTokenAsync(context, user.Id, deviceId, tokenString, isValid); await context.SaveChangesAsync(); token = await sut.GetAccessToken(tokenString); } return(token); }
public async Task VerifyAccessTokenTokenNotFound() { const string password = "******"; const string email = "*****@*****.**"; const string deviceId = "mydevice"; const string tokenString = "randomtokenstring12345"; AuthToken token; using (var context = new QuizContext(ManagerTestHelper.Options)) { var sut = ManagerTestHelper.GetAuthManager(context); var user = await ManagerTestHelper.AddUserAsync(context, 1, email, password); await ManagerTestHelper.AddAuthTokenAsync(context, user.Id, deviceId, tokenString + "somesuffix", true); await context.SaveChangesAsync(); token = await sut.VerifyAccessToken(tokenString); } Assert.IsNull(token); }
public async Task DeleteAccessTokenFalse() { const string password = "******"; const string email = "*****@*****.**"; const string deviceId = "mydevice"; const string tokenString = "randomtokenstring12345"; const bool isUserVerified = false; bool result; using (var context = new QuizContext(ManagerTestHelper.Options)) { var sut = ManagerTestHelper.GetAuthManager(context); var user = await ManagerTestHelper.AddUserAsync(context, 1, email, password, isUserVerified); await ManagerTestHelper.AddAuthTokenAsync(context, user.Id, deviceId, tokenString, true); await context.SaveChangesAsync(); result = await sut.DeleteAccessToken("someothertoken"); } Assert.IsFalse(result); }