Example #1
0
def test_pwreset_set_wrong_code():
    '''
    input error when entered code is not correct
    create a user and use wrong code for reset
    1. non-existing code
    2. empty string
    3. used code
    '''
    clear()
    auth.auth_register('*****@*****.**', 'password', 'first_name', 'last_name')
    assert users[0]['password'] == auth.pw_encode('password')
    auth.auth_pwreset_req('*****@*****.**')
    # non-existing code and empty string
    with pytest.raises(InputError):
        auth.auth_pwreset_set('wrong_code', 'newpassword')
    with pytest.raises(InputError):
        auth.auth_pwreset_set('', 'newpassword')
    # check database
    assert users[0]['password'] == auth.pw_encode('password')
    # 3. reset code
    code = auth.get_reset_code('*****@*****.**')
    auth.auth_pwreset_set(code, 'newpassword')
    assert users[0]['password'] != auth.pw_encode('password')
    assert users[0]['password'] == auth.pw_encode('newpassword')
    # 3. use used code to reset again
    with pytest.raises(InputError):
        auth.auth_pwreset_set(code, 'pppppp')
    assert users[0]['password'] == auth.pw_encode('newpassword')
Example #2
0
def test_pwreset_req_standard():
    '''
    standard test (no error)
    create a user and the user requests to reset password
    '''
    clear()
    auth.auth_register('*****@*****.**', 'password', 'first_name', 'last_name')
    assert users[0]['password'] == auth.pw_encode('password')
    auth.auth_pwreset_req('*****@*****.**')
    code = auth.get_reset_code('*****@*****.**')
    assert code is not None
    assert users[0]['reset_code'] == code
Example #3
0
def test_pwreset_set_invalid_newpw():
    '''
    input error when entered code is not correct
    create a user and use invalid new password for reset
    '''
    clear()
    auth.auth_register('*****@*****.**', 'password', 'first_name', 'last_name')
    assert users[0]['password'] == auth.pw_encode('password')
    auth.auth_pwreset_req('*****@*****.**')
    code = auth.get_reset_code('*****@*****.**')
    with pytest.raises(InputError):
        auth.auth_pwreset_set(code, 'newpa')
        auth.auth_pwreset_set(code, '')
Example #4
0
def send_code_email(email):
    mail = Mail(APP)
    APP.config['MAIL_SERVER'] = 'smtp.gmail.com'
    APP.config['MAIL_PORT'] = 465
    APP.config['MAIL_USERNAME'] = '******'
    APP.config['MAIL_PASSWORD'] = '******'
    APP.config['MAIL_USE_TLS'] = False
    APP.config['MAIL_USE_SSL'] = True
    mail = Mail(APP)
    msg = Message('Your UNSW Flockr password reset code',
                  sender='*****@*****.**',
                  recipients=[email])
    msg.body = get_reset_code(email)
    mail.send(msg)
    return
Example #5
0
def test_pwreset_set_standard():
    '''
    standard test (no error)
    create a user and the user resets his password
    logout and login with new password
    '''
    clear()
    auth.auth_register('*****@*****.**', 'password', 'first_name', 'last_name')
    assert users[0]['password'] == auth.pw_encode('password')
    auth.auth_pwreset_req('*****@*****.**')
    code = auth.get_reset_code('*****@*****.**')
    auth.auth_pwreset_set(code, 'newpassword')
    assert users[0]['password'] != auth.pw_encode('password')
    assert users[0]['password'] == auth.pw_encode('newpassword')
    auth.auth_logout(users[0]['token'])
    auth.auth_login('*****@*****.**', 'newpassword')