Exemplo n.º 1
0
def test_can_add_many_users(memory_repo):
    original_user_count = len(memory_repo.get_all_users())
    new_username = "******"
    new_password = "******"
    authen_services.add_user(new_username, new_password, memory_repo)
    authen_services.add_user("qwe", "123Qweasd", memory_repo)
    assert len(memory_repo.get_all_users()) == original_user_count + 2
Exemplo n.º 2
0
def test_authentication_with_invalid_credentials(memory_repo):
    new_username = "******"
    new_password = "******"

    authen_services.add_user(new_username, new_password, memory_repo)
    try:
        authen_services.authenticate_user(new_username, 'qwertyuiop',
                                          memory_repo)
    except AuthenticationException:
        assert True
Exemplo n.º 3
0
def test_can_reject_user_with_existing_username(memory_repo):
    original_user_count = len(memory_repo.get_all_users())
    new_username = "******"
    new_password = "******"
    try:
        authen_services.add_user(new_username, new_password, memory_repo)
        authen_services.add_user(new_username, new_password, memory_repo)
    except NameNotUniqueException:
        assert len(memory_repo.get_all_users()) == original_user_count + 1
        assert True
Exemplo n.º 4
0
def test_can_add_user(memory_repo):
    original_user_count = len(memory_repo.get_all_users())
    new_username = "******"
    new_password = "******"

    authen_services.add_user(new_username, new_password, memory_repo)
    assert len(memory_repo.get_all_users()) == original_user_count + 1
    user_as_dict = authen_services.get_user(new_username, memory_repo)
    assert user_as_dict['user_name'] == new_username

    # Check that password has been encrypted.
    assert user_as_dict['password'].startswith('pbkdf2:sha256:')
Exemplo n.º 5
0
def register():
    error_list = []
    form = RegistrationForm()
    if request.method == 'POST':
        #print(request.form['user_name'])
        try:
            user_name = form.user_name.data
            password = form.password.data
            if len(user_name) < 3:
                #print("a")
                if len(user_name) == 0:
                    error_list.append('Your username is required.')
                else:
                    error_list.append('Your username is too short.')
            schema = PasswordValidator()
            schema.min(8) \
                .has().uppercase() \
                .has().lowercase() \
                .has().digits()
            if not schema.validate(password):
                #print("b")
                if len(password) == 0:
                    error_list.append("Your password is required.")
                error_list.append('Your password is invalid, please refer to Account notes.')
            #print(error_list)
            if len(error_list) == 0:
                services.add_user(user_name, password, repo.repo_instance)
                # All is well, redirect the user to the login page.
                return redirect(url_for('authen_bp.login'))
            else:
                return render_template(
                    'authen/credentials.html',
                    title='Register',
                    form=form,
                    error_list=error_list,
                    handler_url=url_for('authen_bp.register'),
                )
        except services.NameNotUniqueException:
            error_list.append("Your username is already taken - please supply another.")
    # For a GET or a failed POST request, return the Registration Web page.
    return render_template(
        'authen/credentials.html',
        title='Register',
        form=form,
        error_list=error_list,
        handler_url=url_for('authen_bp.register'),
    )
Exemplo n.º 6
0
def test_can_retrieve_user(memory_repo):
    new_username = "******"
    new_password = "******"
    authen_services.add_user(new_username, new_password, memory_repo)
    assert authen_services.get_user("qwerty",
                                    memory_repo)['user_name'] == "qwerty"