def test_authentication_with_invalid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) with pytest.raises(auth_services.AuthenticationException): auth_services.authenticate_user(new_username, '123456789', in_memory_repo)
def test_cannot_add_user_with_existing_name(empty_memory_repo): username = '******' password = '******' auth_services.add_user(username, password, empty_memory_repo) with pytest.raises(auth_services.NameNotUniqueException): auth_services.add_user(username, password, empty_memory_repo)
def test_can_add_user(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) user_as_dict = auth_services.get_user(new_username, in_memory_repo) assert user_as_dict['username'] == new_username assert user_as_dict['password'].startswith( 'pbkdf2:sha256:') # Check password is encrypted.
def test_authentication_with_valid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) try: auth_services.authenticate_user(new_username, new_password, in_memory_repo) except AuthenticationException: assert False
def test_authentication_with_invalid_credentials(empty_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, empty_memory_repo) with pytest.raises(auth_services.AuthenticationException): auth_services.authenticate_user(new_username, 'hacked_password', empty_memory_repo)
def test_can_add_user(empty_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, empty_memory_repo) user_as_dict = auth_services.get_user(new_username, empty_memory_repo) assert user_as_dict['username'] == new_username # Check that password has been encrypted. assert user_as_dict['password'].startswith('pbkdf2:sha256:')
def test_authentication_with_valid_credentials(empty_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, empty_memory_repo) try: auth_services.authenticate_user(new_username, new_password, empty_memory_repo) except auth_services.AuthenticationException: assert False
def register(): form = RegistrationForm() username_not_unique = None if form.validate_on_submit(): # Successful POST, i.e. the username and password have passed validation checking. # Use the service layer to attempt to add the new user. try: services.add_user(form.username.data, form.password.data, repo.repo_instance) # All is well, redirect the user to the login page. return redirect(url_for('authentication_bp.login')) except services.NameNotUniqueException: username_not_unique = 'That username is already taken - please try another' # For a GET or a failed POST request, return the Registration Web page. return render_template('authentication/credentials.html', title='Register', form=form, username_error_message=username_not_unique, handler_url=url_for('authentication_bp.register'))
def test_cannot_add_user_with_existing_name(in_memory_repo): username = '******' password = '******' with pytest.raises(auth_services.NameNotUniqueException): auth_services.add_user(username, password, in_memory_repo)