def test_login_invalid_email(): """ tests if error handling in login is still valid for emails. """ clear() with pytest.raises(InputError): auth.auth_login('testemail.com', 'abcdef') clear()
def test_login_invalid_user(): """ should not be able to login because email does not belong to a user """ clear() auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'abcdefg') clear()
def test_login_invalid_password_chars(): """ Checks if the password inputted contains valid characters """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'h $ e L ( 0') clear()
def test_login_invalid_password(): """ checks if the password inputted is correct, and that the user exists in the active users data """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'abcde') clear()
def test_login_incorrect_password(): """ testing using the incorrect password """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'abcdef') clear()
def test_valid_passwords(): """ passwords can contain all visible characters on the keyboard, except space """ clear() result = auth.auth_register('*****@*****.**', '!@#$%^&*()_+-=][<>w;:"', 'who', 'where') auth.auth_logout(result['token']) auth.auth_login('*****@*****.**', '!@#$%^&*()_+-=][<>w;:"') with pytest.raises(InputError): auth.auth_register('*****@*****.**', 'h el$l o', 'who', 'where') clear()
def test_login_reset_password(): """ Testing that a user should not be able to login when they have requested a password reset. """ clear() auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') user = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(user['token']) auth.auth_passwordreset_request('*****@*****.**') with pytest.raises(AccessError): auth.auth_login('*****@*****.**', 'abcdefg') clear()
def test_output_admin_owner_change_owner_to_member_logout(user_1, user_2, private_channel_1): """Test whether permission change carry through after logout """ admin_userpermission_change(user_1["token"], user_2["u_id"], OWNER) admin_userpermission_change(user_1["token"], user_2["u_id"], MEMBER) auth.auth_logout(user_2['token']) user_2 = auth.auth_login('*****@*****.**', 'password') with pytest.raises(AccessError): channel.channel_join(user_2['token'], private_channel_1['channel_id']) clear()
def test_output_admin_owner_change_member_to_owner_logout(user_1, user_2, public_channel_1): """Testing whether the permission change carry through after user logout and logs back in. """ admin_userpermission_change(user_1["token"], user_2["u_id"], OWNER) auth.auth_logout(user_2["token"]) user_2 = auth.auth_login('*****@*****.**', 'password') # Owner can join any channels including private # Testing user, with now as flockr owner to join private channel channel.channel_join(user_2['token'], public_channel_1['channel_id']) clear()
def test_logout_basic(): """ testing the basics of loging out and logging back in. """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) result2 = auth.auth_login('*****@*****.**', 'abcdefg') auth.auth_logout(result2['token']) clear() result3 = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result3['token']) clear()
def route_auth_login(): """Given a registered users' email and password and generates a valid token for the user to remain authenticated Args: email (string) password (string) Returns: (dict): { u_id, token } """ payload = request.get_json() try: return dumps(auth.auth_login(payload['email'], payload['password'])) except (InputError, AccessError) as e: return e
def test_login_loggedin(): """ testing that a user can login when already logged in in another session. """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') result_2 = auth.auth_login('*****@*****.**', 'abcdefg') count = 0 data = pickle.load(open("data.p", "rb")) for user in data.get_active_users(): if user['u_id'] == result['u_id']: count += 1 assert count == 1 assert result['token'] == result_2['token'] assert result['u_id'] == result_2['u_id']