def test_email_not_belong():
    '''
    Email entered does not belong to a user
    '''
    clear_v1()
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'asdjf~!')
Пример #2
0
def test_login_multiple():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result2 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result3 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result1a = auth_login_v2('*****@*****.**', '123abc!@#')
    result2a = auth_login_v2('*****@*****.**', '123abc!@#')
    result3a = auth_login_v2('*****@*****.**', '123abc!@#')
    assert result1 != result1a
    assert result2 != result2a
    assert result3 != result3a
    assert result1 != result2
    assert result2 != result3
    assert result1a != result2a
    assert result3a != result2a
    assert result1['auth_user_id'] == result1a['auth_user_id']
    assert result2['auth_user_id'] == result2a['auth_user_id']
    assert result2['auth_user_id'] == result2a['auth_user_id']
    assert result1['token'] != result1a['token']
    assert result2['token'] != result2a['token']
    assert result2['token'] != result2a['token']
    clear_v1()
def test_incorrect_password():
    '''
    Password is not correct
    '''
    clear_v1()
    auth_register_v2('*****@*****.**', 'asdjf~!', 'Rengoku', 'Kyojuro')
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'wakanda123')
Пример #4
0
def test_invalid_email_login():
    clear_v1()
    auth_register_v2('*****@*****.**', '123abc!@#', 'Comp', 'Student')
    with pytest.raises(InputError):
        auth_login_v2('invalidemailgmail.com', '123abc!@#')
    with pytest.raises(InputError):
        auth_login_v2('invalid#[email protected]', '123abc!@#')
    clear_v1()
Пример #5
0
def test_auth_login_v2_incorrect_password(user_details):
    clear_v2()
    email, pwd, fName, lName = user_details
    auth_register_v2(email, pwd, fName, lName)
    password = "******"

    with pytest.raises(InputError):
        auth_login_v2(email, password)
Пример #6
0
def test_auth_login_v2_invalid_email(user_details):
    clear_v2()
    email, pwd, fName, lName = user_details
    auth_register_v2(email, pwd, fName, lName)
    invalid_email = "ankitrai326.com"
    test_password = "******"

    with pytest.raises(InputError):
        auth_login_v2(invalid_email, test_password)
Пример #7
0
def test_auth_login_v2_no_user(user_details):
    clear_v2()
    email, pwd, fName, lName = user_details
    auth_register_v2(email, pwd, fName, lName)
    unused_email = "*****@*****.**"
    unused_password = "******"

    with pytest.raises(InputError):
        auth_login_v2(unused_email, unused_password)
def test_removed_user():
    clear_v1()

    a_data = auth_register_v2('*****@*****.**', 'asdjf~!', 'Rengoku',
                              'Kyojuro')
    b_data = auth_register_v2('*****@*****.**', 'asdjf~!', 'Rengoku',
                              'Kyojuro')

    auth_logout_v2(b_data["token"])

    user_remove_v1(a_data["token"], b_data["auth_user_id"])

    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'asdjf~!')
def test_invalid_email():
    '''
    Email entered is not a valid email
    '''
    clear_v1()
    user_1 = auth_register_v2('*****@*****.**', 'asdjf~!', 'Rengoku',
                              'Kyojuro')
    auth_logout_v2(user_1["token"])

    with pytest.raises(InputError):
        auth_login_v2('invalid.email.gmail.com', 'asdjf~!')
        auth_login_v2('*****@*****.**', 'asdjf~!')
        auth_login_v2('inval [email protected]', 'asdjf~!')
        auth_login_v2('[email protected]', 'asdjf~!')
        auth_login_v2('129%_.$@[email protected]', 'asdjf~!')
Пример #10
0
def login():
    info = request.get_json()
    email = info["email"]
    password = info["password"]

    user_login = auth_login_v2(email, password)
    return dumps(user_login)
Пример #11
0
def us_init():
    """
    Logs in or Registers the scrambler user
    """

    # Need to make sure the user hasnt been deleted
    # check if the scrambler is an existing user
    #   if not,
    #       register the scrambler
    #   if yes,
    #       login

    with open("data.json") as json_file:
        data = load(json_file)

    is_exist = False
    for user in data["users"]:
        if user["name_first"] == "Sinister" and user[
                "name_last"] == "Scrambler":
            is_exist = True

    if is_exist == True:
        scrambler_data = auth_login_v2("*****@*****.**", "sspassword")

    else:  # is_exist != True:
        scrambler_data = auth_register_v2("*****@*****.**", "sspassword",
                                          "Sinister", "Scrambler")

    with open("data.json") as json_file:
        data = load(json_file)

    return scrambler_data
Пример #12
0
def auth_login():
    data = request.get_json()
    password = data['password']
    email = data['email']

    output = auth_login_v2(email, password)

    return dumps(output)
Пример #13
0
def user_setup():
    '''
    Clear history of all current users then register and login new users
    '''
    clear_v1()
    # register 4 users with email, password, first name and last name
    auth_register_v2("*****@*****.**", "password", "Gungeet", "Singh")
    auth_register_v2("*****@*****.**", "password", "Peter", "Tran")
    auth_register_v2("*****@*****.**", "password", "Christopher",
                     "Luong")
    auth_register_v2("*****@*****.**", "password", "Tal", "Avrahami"),
    auth_register_v2("*****@*****.**", "password", "Eyal", "Dorfan")
    # login the 4 users who have been registered
    auth_login_v2("*****@*****.**", "password")
    auth_login_v2("*****@*****.**", "password")
    auth_login_v2("*****@*****.**", "password")
    auth_login_v2("*****@*****.**", "password")
    auth_login_v2("*****@*****.**", "password")
Пример #14
0
def test_successful_logout_after_login(
        reg_user,
        user_details):  # Test that token generated by login can be logged out
    clear_v2()
    user_token = reg_user(0)['token']
    email, pword, *_ = user_details(0)
    auth_logout_v1(user_token)
    user_token = auth_login_v2(email, pword)['token']
    assert auth_logout_v1(user_token)
Пример #15
0
def test_clear_everything():
    """ Tests that calling clear on database filled with channels and channel
        members does indeed clear everything.
    """
    clear_v1()
    user_1 = auth_register_v2("*****@*****.**", "peterpiper", "Eric",
                              "Zheng")
    user_2 = auth_register_v2("*****@*****.**", "maryreider", "Josh",
                              "Hatton")
    user_3 = auth_register_v2("*****@*****.**", "runescape4lyfe",
                              "Dean", "Zworestine")
    user_4 = auth_register_v2("*****@*****.**", "iheartnewyork",
                              "Jordan", "Milch")

    channel_1 = channels_create_v2(user_1["token"], "Party Channel", True)
    channel_2 = channels_create_v2(user_3["token"], "General", True)

    channel_join_v2(user_2["token"], channel_2['channel_id'])
    channel_join_v2(user_3["token"], channel_1['channel_id'])
    channel_join_v2(user_4["token"], channel_1['channel_id'])

    assert clear_v1() == {}

    with pytest.raises(InputError):
        # All data should have been reset so no users should be able to log in
        auth_login_v2("*****@*****.**", "peterpiper")
        auth_login_v2("*****@*****.**", "maryreider")
        auth_login_v2("*****@*****.**", "globalempire4")
        auth_login_v2("*****@*****.**", "runescape4lyfe")
        auth_login_v2("*****@*****.**", "iheartnewyork")

    with pytest.raises(AccessError):
        # Should also be unable to access list of channels as there are no valid
        # tokens
        channels_listall_v2(user_1["token"])

    # Should be able to open a list of channels with a new valid token
    user_1 = auth_register_v2("*****@*****.**", "peterpiper", "Eric",
                              "Zheng")

    channels_listall_v2(user_1["token"])

    clear_v1()
def test_valid_user():
    clear_v1()
    user_1_session1 = auth_register_v2('*****@*****.**', 'asdjf~!',
                                       'Rengoku', 'Kyojuro')
    auth_logout_v2(user_1_session1["token"])

    user_1_session2 = auth_login_v2('*****@*****.**', 'asdjf~!')

    assert user_1_session1["auth_user_id"] == user_1_session2["auth_user_id"]

    assert channels_create_v2(user_1_session2["token"], "test name", True)
Пример #17
0
def test_login_basic():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result2 = auth_login_v2('*****@*****.**', '123abc!@#')
    assert result1 != result2
    assert type(result1) == dict
    assert type(result1['auth_user_id']) == int
    assert type(result2) == dict
    assert type(result2['auth_user_id']) == int
    assert result1['auth_user_id'] == result2['auth_user_id']
    assert result1['token'] != result2['token']
    clear_v1()
Пример #18
0
def test_password_doesnt_match(register_three_users):
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'incorrect')
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'wrongpass')
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'errorexpect')
    clear_v1()
Пример #19
0
def test_email_doesnt_belong(register_three_users):
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'random')
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'random')
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'random')
    clear_v1()
def test_successful_reset():
    '''
    password has succesfully changed given reset_code and new_password
    '''
    clear_v1()
    user = auth_register_v2('*****@*****.**', 'asdjf~!', 'Rengoku',
                            'Kyojuro')
    auth_logout_v2(user['token'])
    auth_passwordreset_request_v1('*****@*****.**')
    with open("email.json") as e_file:
        email = load(e_file)
    auth_passwordreset_reset_v1(email['reset_code'], 'babus1337')
    user_session_1 = auth_login_v2('*****@*****.**', 'babus1337')
    assert user_session_1['auth_user_id'] == user['auth_user_id']
Пример #21
0
def test_logout_with_login():
    clear_v1()
    result1 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result2 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result3 = auth_register_v2('*****@*****.**', '123abc!@#', 'Comp',
                               'Student')
    result1a = auth_login_v2('*****@*****.**', '123abc!@#')
    result1a = auth_login_v2('*****@*****.**', '123abc!@#')
    result2a = auth_login_v2('*****@*****.**', '123abc!@#')
    result3a = auth_login_v2('*****@*****.**', '123abc!@#')
    result1b = auth_logout_v1(result1['token'])
    result2b = auth_logout_v1(result2['token'])
    result3b = auth_logout_v1(result3['token'])
    result1c = auth_logout_v1(result1a['token'])
    result2c = auth_logout_v1(result2a['token'])
    result3c = auth_logout_v1(result3a['token'])
    assert result1b == {
        'is_success': True,
    }
    assert result2b == {
        'is_success': True,
    }
    assert result3b == {
        'is_success': True,
    }
    assert result1c == {
        'is_success': True,
    }
    assert result2c == {
        'is_success': True,
    }
    assert result3c == {
        'is_success': True,
    }
    clear_v1()
Пример #22
0
def test_clear_user_login():
    """ Tests that calling clear on registered users will not let them login 
        as their data has been cleared.
    """
    clear_v1()
    auth_register_v2("*****@*****.**", "asdfg123456", "Bunny", "Dong")
    auth_register_v2("*****@*****.**", "asdfg123456", "James", "Dong")
    auth_register_v2("*****@*****.**", "asdfg123456", "gerht", "grg")
    auth_register_v2("*****@*****.**", "asdfg123456", "fwef", "erggre")

    assert (clear_v1() == {})

    # Users should not be able to login because data has been cleared
    with pytest.raises(InputError):
        auth_login_v2("*****@*****.**", "asdfg123456")
        auth_login_v2("*****@*****.**", "asdfg123456")
        auth_login_v2("*****@*****.**", "asdfg123456")
        auth_login_v2("*****@*****.**", "asdfg123456")

    clear_v1()
Пример #23
0
def test_auth_logout_v2():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]

    is_success_data = auth_logout_v2(auth_user_1_token)
    assert is_success_data["is_success"] == True

    is_success_data = auth_logout_v2(auth_user_1_token)
    assert is_success_data["is_success"] == False

    auth_user_1_data = auth_login_v2("*****@*****.**", "123456")
    auth_user_1_token = auth_user_1_data["token"]

    is_success_data = auth_logout_v2(auth_user_1_token)
    assert is_success_data["is_success"] == True

    is_success_data = auth_logout_v2(auth_user_1_token)
    assert is_success_data["is_success"] == False
Пример #24
0
def test_logout_and_login_valid():
    result = auth_logout_v1(make_token(0))
    assert result == {'is_success': True}
    result = auth_login_v2('*****@*****.**', '123abc!@#')
    assert result == {'token': make_token(0),'auth_user_id': 0}
Пример #25
0
def test_empty_login():
    clear_v1()
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'incorrect')
    clear_v1()
Пример #26
0
def test_login_incorrect_password():
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'incorrectPassword')
Пример #27
0
def test_login_unregistered_email():
    with pytest.raises(InputError):
        auth_login_v2('*****@*****.**', 'password')
Пример #28
0
def test_login_invalid_email():
    with pytest.raises(InputError):
        auth_login_v2('invalidemail', '123456')
Пример #29
0
def login():
    parameters = request.get_json()
    email = parameters['email']
    password = parameters['password']
    output = auth_login_v2(email, password)
    return dumps(output)
Пример #30
0
def test_auth_login_v2_correct_password(user_details):
    clear_v2()
    email, pwd, fName, lName = user_details
    user = auth_register_v2(email, pwd, fName, lName)

    assert auth_login_v2(email, pwd)['auth_user_id'] == user['auth_user_id']