Пример #1
0
def test_reset_reset():
    ''' Tests passwordreset_reset '''
    reset_data()
    res = auth_register("*****@*****.**", "testpass", "john",
                        "smith")
    token = res['token']

    with pytest.raises(ValueError):
        # when the user has not requested a reset
        auth_passwordreset_reset(token, "newpass")

    auth_passwordreset_request("*****@*****.**")
    reset_code = str(server_data.data["users"][0]['reset_token'])

    with pytest.raises(ValueError):
        # if the password entered is not valid
        auth_passwordreset_reset(reset_code, "s")
    with pytest.raises(ValueError):
        # if the token is invalid
        auth_passwordreset_reset("invalidtoken", "newpass")

    # Working reset
    print(server_data.data["users"][0]['reset_token'])
    print(reset_code)
    auth_passwordreset_reset(reset_code, "newpassword")
    assert server_data.data["users"][0]['password'] == hash_pw("newpassword")
Пример #2
0
def post_auth_reset():
    """ Reset the password of a user """
    reset_code = request.form.get('reset_code')
    new_password = request.form.get('new_password')
    try:
        auth_passwordreset_reset(reset_code, new_password)
    except ValueError as e:
        return str(e)
    except AccessError as e:
        return dumps({
            'code': 400,
            'name': 'AccessError',
            'message': str(e)
        }), 400
    save()
    return dumps({})
Пример #3
0
def test_auth_passwordreset_reset():
    '''
    assumption:
        [email protected] is the only registered email.
        2.all the value errors have been modified into specfic words.
        3.there is a reset code which is '12345' in the email dic.
        4.the old password of [email protected] is 1q2w3e4r.
    '''
    reset_data()
    #successful test:
    # hard to test the successful test,cause we cannot get the resetcode

    #test1: reset_code is not a valid reset code (hard to test, cuz we do not know reset_code

    with pytest.raises(ValueError):
        auth_passwordreset_reset('54321', 'r4e3w2q1')

    #test2: Password entered is not a valid password
    with pytest.raises(ValueError):
        auth_passwordreset_reset('12345', '1')

    reset_data()
Пример #4
0
def email_reset():
    reset_code = request.form.get('reset_code')
    new_password = request.form.get('new_password')
    dumpstring = auth.auth_passwordreset_reset(reset_code, new_password)
    return dumps(dumpstring)
Пример #5
0
def app_auth_password_reset():
    reset_code = get_args('reset_code')
    new_password = get_args('new_password')
    return dumps(auth_passwordreset_reset(reset_code, new_password))