Ejemplo n.º 1
0
def test_flockr_owner_remover(channel_with_user):
    clear()
    # Creating the flockr owner
    auth_register("*****@*****.**", "flockr_ownerpassword",
                  "flockr_ownerFirstname", "flockr_ownerLastname")
    flockr_owner = auth_login("*****@*****.**", "flockr_ownerpassword")

    # Creating the owner and their own channel
    auth_register("*****@*****.**", "ownerpassword", "ownerFirstname",
                  "ownerLastname")
    owner = auth_login("*****@*****.**", "ownerpassword")
    public = True
    channel_id = channels_create(owner['token'], "Channel", public)

    # Creating the message via the owner
    message_id = message_send(owner['token'], channel_id['channel_id'],
                              "Test Message 1")
    message = channel_messages(owner['token'], channel_id['channel_id'],
                               0)['messages']
    # assert message == [
    #     {'message_id': 0, 'u_id': 1, 'message': 'Test Message 1', 'time_created': timestamp}
    # ]
    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 1
    assert message[0]['message'] == 'Test Message 1'

    # Removing the message via the flockr owner
    message_remove(flockr_owner['token'], message_id['message_id'])
    messages = channel_messages(owner['token'], channel_id['channel_id'],
                                0)['messages']
    assert not messages
Ejemplo n.º 2
0
def test_flockr_owner_permissions(register_login, create_channel):
    flockr_owner = register_login

    # Creates a new user who is the owner of a channel
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user_2 = auth_login("*****@*****.**", "password2")

    c_id = channels_create(user_2["token"], "Channel", True)['channel_id']

    # Create a new user who is not flockr owner, and is a member of a channel,
    # sends a message
    auth_register("*****@*****.**", "password3", "Richard3", "Shen3")
    user_3 = auth_login("*****@*****.**", "password3")
    channel_join(user_3['token'], c_id)
    channel_join(flockr_owner['token'], c_id)

    m_id = message_send(user_3['token'], c_id, "First Message")['message_id']

    message_edit(flockr_owner['token'], m_id, "Edited Message")

    # Check the message was edited correctly
    updated_message = channel_messages(flockr_owner['token'], c_id,
                                       0)['messages'][0]['message']

    assert updated_message == "Edited Message"
Ejemplo n.º 3
0
def test_flockr_owner():
    clear()

    # Register and login the global owner
    auth_register("*****@*****.**", "password", "First", "Last")
    flockr_owner = auth_login("*****@*****.**", "password")

    # Register and login 2 other users
    auth_register("*****@*****.**", "password", "First", "Last")
    owner_1 = auth_login("*****@*****.**", "password")

    auth_register("*****@*****.**", "password", "First", "Last")
    owner_2 = auth_login("*****@*****.**", "password")

    # Create a channel for owner_1
    public = True
    owner_1_c_id = channels_create(owner_1['token'], "Channel",
                                   public)['channel_id']
    channel_join(owner_2['token'], owner_1_c_id)

    # Make owner_2 actually an owner
    channel_addowner(owner_1['token'], owner_1_c_id, owner_2['u_id'])

    # The flockr_owner removes owner_2 as an owner
    channel_removeowner(flockr_owner['token'], owner_1_c_id, owner_2['u_id'])

    details = channel_details(owner_1['token'], owner_1_c_id)
    assert len(details['owner_members']) == 1
    assert details['owner_members'][0]['u_id'] == 1
Ejemplo n.º 4
0
def test_password_reset_invalid_password():
    clear()
    # Register a user
    auth_register("*****@*****.**", "password", "Wilson", "Doe")
    auth_login("*****@*****.**", "password")
    # Retrieve the reset code
    reset_code = encoded_resetcode("*****@*****.**")
    invalid_password = "******"
    # Fails as the password is not valid
    with pytest.raises(InputError):
        auth_passwordreset_reset(reset_code, invalid_password)
Ejemplo n.º 5
0
def test_channel_leave_member(register_new_user):

    # Create the user
    new_user = register_new_user
    token = new_user['token']

    # Create the channel
    public = True
    channels_create(token, "Test Channel 2", public) 
    test_channel = channels_create(token, "Test Channel", public)
    c_id = test_channel['channel_id']
    in_channel = True

    # Create a new user who joins the channel
    auth_register("*****@*****.**", "password1", "Bilson", "Doe")
    user2 = auth_login("*****@*****.**", "password1")
    token2 = user2['token']
    channel_join(token2, c_id)
    
    # 2nd member leaves, check if they are in the channel
    channel_leave(token2, c_id)
    member_check = channel_details(token, c_id)
    in_channel = user2['u_id'] in member_check['all_members']
    
    assert in_channel == False
Ejemplo n.º 6
0
def register_login():
    # Using the clear function in the register_login fixture so it won't have to be called after
    clear()
    # registers and logs in a user
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    user = auth_login("*****@*****.**", "password")
    return {"u_id": user["u_id"], "token": user["token"]}
Ejemplo n.º 7
0
def test_invalid_channel_id(register_login):
    token = register_login
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    token2 = auth_login("*****@*****.**", "password2")
    invalid_c_id = -1
    with pytest.raises(InputError):
        channel_addowner(token['token'], invalid_c_id, token2['u_id'])
Ejemplo n.º 8
0
def test_details_valid(register_and_login_user):
    token = register_and_login_user

    # Create another user and a channel before it to not retrieve it
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    login = auth_login("*****@*****.**", "password")
    channels_create(login['token'], "ignore channel", True)

    channels_create(token, "test channel", True)
    result = channel_details(token, 1)

    assert result == {
        'name':
        'test channel',
        'owner_members': [{
            'u_id': 0,
            'name_first': 'Angus',
            'name_last': 'Doe',
            'profile_img_url': 'default.jpg',
        }],
        'all_members': [{
            'u_id': 0,
            'name_first': 'Angus',
            'name_last': 'Doe',
            'profile_img_url': 'default.jpg',
        }]
    }
Ejemplo n.º 9
0
def auth_login_flask():
    payload = request.get_json()

    email = payload['email']
    password = payload['password']

    return dumps(a.auth_login(email, password))
Ejemplo n.º 10
0
def test_member_edits_own_message(register_login, create_channel):
    owner = register_login
    owner_c_id = create_channel['c_id']

    # Creating a new user who is not the owner, and joins the channel as a member
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    user_2 = auth_login("*****@*****.**", "password2")
    channel_join(user_2['token'], owner_c_id)

    # Verify the new user is not an owner
    channel = channel_details(owner['token'], owner_c_id)
    assert user_2['u_id'] not in channel['owner_members']

    # User 2's message id
    user_2_m_id = message_send(user_2['token'], owner_c_id,
                               "Member's Message")['message_id']

    # Ensure that it is user 2's message
    messages = channel_messages(user_2['token'], owner_c_id, 0)['messages']
    assert user_2['u_id'] == messages[0]['u_id']

    # User 2 edits the message
    new_message = "user_2 can edit their own message"
    message_edit(user_2['token'], user_2_m_id, new_message)

    # Ensure the message is edited
    messages = channel_messages(user_2['token'], owner_c_id, 0)['messages']
    assert new_message == messages[0]['message']
Ejemplo n.º 11
0
def register_login_user2():
    # register
    auth_register("*****@*****.**", "password", "Bingus", "Doe")
    login = auth_login("*****@*****.**", "password")
    token = login['token']

    return token
Ejemplo n.º 12
0
def test_details_valid_after_invite(register_and_login_user):
    token = register_and_login_user
    channels_create(token, "test channel", True)

    auth_register("*****@*****.**", "password", "Lmao", "Bus")
    login = auth_login("*****@*****.**", "password")
    token = login['token']

    channel_invite(token, 0, 1)

    result = channel_details(token, 0)
    assert result == {
        'name':
        'test channel',
        'owner_members': [{
            'u_id': 0,
            'name_first': 'Angus',
            'name_last': 'Doe',
            'profile_img_url': 'default.jpg',
        }],
        'all_members': [
            {
                'u_id': 0,
                'name_first': 'Angus',
                'name_last': 'Doe',
                'profile_img_url': 'default.jpg',
            },
            {
                'u_id': 1,
                'name_first': 'Lmao',
                'name_last': 'Bus',
                'profile_img_url': 'default.jpg',
            },
        ]
    }
Ejemplo n.º 13
0
def test_sender_message_remove_success(channel_with_user, ):
    owner = channel_with_user

    # Create second user who will send the message
    auth_register("*****@*****.**", "password", "First", "Last")
    sender = auth_login("*****@*****.**", "password")
    channel_join(sender['token'], owner['c_id'])

    # Ensure there's no messages in the channel to begin with
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages

    # Send the message with a user other than the owner
    message_id = message_send(sender['token'], owner['c_id'], "Test Message")

    # Verify the message was sent inbetween creating and removing
    message = channel_messages(owner['token'], owner['c_id'], 0)['messages']

    assert message[0]['message_id'] == 0
    assert message[0]['u_id'] == 1
    assert message[0]['message'] == 'Test Message'

    # Remove message
    message_remove(sender['token'], message_id['message_id'])

    # Verify that the message was removed
    messages = channel_messages(owner['token'], owner['c_id'], 0)['messages']
    assert not messages
Ejemplo n.º 14
0
def test_no_channels_joined():
    # Register a second user who is not part of the channel
    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    user_2 = auth_login("*****@*****.**", "password")

    query_str = "Query String"
    with pytest.raises(AccessError):
        search(user_2['token'], query_str)
Ejemplo n.º 15
0
def test_unauthorised_user(channel_with_user, create_messages):
    owner = channel_with_user

    auth_register("*****@*****.**", "password", "Sam", "Wu")
    unaurthorised_user = auth_login("*****@*****.**", "password")

    with pytest.raises(AccessError):
        channel_messages(unaurthorised_user['token'], owner['c_id'], 5)
Ejemplo n.º 16
0
def test_invalid_owner_remove_2(channel_with_2_owners):
    owner = channel_with_2_owners
    auth_register("*****@*****.**", "password", "First", "Last")
    not_owner = auth_login("*****@*****.**", "password")
    channel_join(not_owner['token'], owner['c_id']['channel_id'])
    with pytest.raises(AccessError):
        channel_removeowner(not_owner['token'], owner['c_id']['channel_id'],
                            owner['token_2']['u_id'])
Ejemplo n.º 17
0
def register_login():
    # Using the clear function in the register_login fixture so it won't have to be called after
    clear()
    auth_register("*****@*****.**", "password", "Richard", "Shen")
    user = auth_login("*****@*****.**", "password")
    return {
        "u_id": user["u_id"],
        "token": user["token"]
    }
Ejemplo n.º 18
0
def test_invalid_sender(channel_with_user):
    owner = channel_with_user

    # Seperate user who is not in the channel
    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    invalid_sender = auth_login("*****@*****.**", "password")
    
    with pytest.raises(AccessError):
        message_send(invalid_sender['token'], owner['c_id'], "Test Message")
Ejemplo n.º 19
0
def test_unauthorised_member(register_and_login_user):
    token = register_and_login_user
    channels_create(token, "test channel", True)

    auth_register("*****@*****.**", "password", "Abus", "Doe")
    user = auth_login("*****@*****.**", "password")
    token = user['token']

    with pytest.raises(AccessError):
        channel_details(token, 0)
Ejemplo n.º 20
0
def test_invalid_owner_add(register_login):
    # Register the first user who is the owner of the channel
    token = register_login
    public = True
    c_id = channels_create(token['token'], "Channel", public)
    # Create a second user
    auth_register("*****@*****.**", "password2", "Richard2", "Shen2")
    token2 = auth_login("*****@*****.**", "password2")
    # Create a third user
    auth_register("*****@*****.**", "password3", "Richard3", "Shen3")
    token3 = auth_login("*****@*****.**", "password3")
    # Make both new users join the channel
    channel_join(token2['token'], c_id['channel_id'])
    channel_join(token3['token'], c_id['channel_id'])
    details = channel_details(token['token'], c_id['channel_id'])
    assert details['all_members'][1]['u_id'] == 1
    # Should raise AccessError if the newly joined member tries to make the other member an owner
    with pytest.raises(AccessError):
        channel_addowner(token3['token'], c_id['channel_id'], token2['u_id'])
Ejemplo n.º 21
0
def test_user_not_in_channel(register_login, create_channel_and_message_react):
    message_id = create_channel_and_message_react['message_id']
    # Creating a second channel which will not have the messages, and make a new user
    auth_register("*****@*****.**", "password2", "angus2", "doe2")
    user2 = auth_login("*****@*****.**", "password2")
    user2_token = user2['token']

    react_id = 1
    with pytest.raises(InputError):
        message_unreact(user2_token, message_id, react_id)
Ejemplo n.º 22
0
def test_is_flockr_owner(register_login):
    # Creating the flockr owner, which is the first user to be registered
    flockr_owner = register_login
    flockr_token = flockr_owner['token']
    # Creating a new user who will be the channel owner
    auth_register("*****@*****.**", "ownerpassword", "ownerRichard",
                  "ownerShen")
    owner = auth_login("*****@*****.**", "ownerpassword")
    public = True
    c_id = channels_create(owner['token'], "Channel", public)
    # Creating a new user who will be just a member of the channel
    auth_register("*****@*****.**", "memberpassword", "memberRichard",
                  "memberShen")
    member = auth_login("*****@*****.**", "memberpassword")
    channel_join(member['token'], c_id['channel_id'])
    # Making the member the owner via the permissions of the flockr owner
    channel_addowner(flockr_token, c_id['channel_id'], member['u_id'])
    details = channel_details(owner['token'], c_id['channel_id'])
    assert details['owner_members'][1]['u_id'] == member['u_id']
Ejemplo n.º 23
0
def test_password_reset_success():
    clear()
    # Register 2 users for coverage
    auth_register("*****@*****.**", "password", "Wilson", "Doe")['u_id']
    auth_register("*****@*****.**", "password", "Wilson", "Doe")['u_id']
    user = auth_login("*****@*****.**", "password")

    # Retrieve the reset code
    reset_code = encoded_resetcode("*****@*****.**")
    # Reset the password
    auth_passwordreset_reset(reset_code, "newpassword")
    # Assert that the new password is updated by checking if the hashed versions are the same

    auth_logout(user['token'])
    user = auth_login("*****@*****.**", "newpassword")
    assert user == {
        'u_id': 1,
        'token': user['token'],
    }
Ejemplo n.º 24
0
def register_login_create_channel():
    clear()
    # register and login a user
    auth_register("*****@*****.**", "password", "Angus", "Doe")
    login = auth_login("*****@*****.**", "password")
    token = login['token']

    # create channel using that user
    channels_create(token, "test channel", True)

    return token
Ejemplo n.º 25
0
def register_login():
    # Fixture registers a user and then logs them in
    # Returns dictionary containing their u_id and token.
    clear()
    
    # Create dummy user to make sure right user is being targetted
    auth_register("*****@*****.**", "password", "Anguss", "Doee")

    auth_register("*****@*****.**", "password", "Angus", "Doe")
    user = auth_login("*****@*****.**", "password")
    return user
Ejemplo n.º 26
0
def test_invalid_external_user_unpin(channel_user_message_pin):
    owner = channel_user_message_pin

    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    member = auth_login("*****@*****.**", "password")

    owner_channel = channel_details(owner['token'], owner['c_id'])
    assert member['u_id'] not in owner_channel['all_members']

    with pytest.raises(AccessError):
        message_unpin(member['token'], owner['message_id'])
Ejemplo n.º 27
0
def test_private_channel(register_login_user):
    owner = register_login_user 

    # Register and login a new user who plans to join the channel
    auth_register("*****@*****.**", "password", "First", "Last")
    member = auth_login("*****@*****.**", "password")

    private = False
    c_id = channels_create(owner['token'], "Channel", private)
    with pytest.raises(AccessError):
        channel_join(member['token'], c_id['channel_id'])
Ejemplo n.º 28
0
def test_channel_leave_unauthorised(register_new_user):
    new_user = register_new_user
    token = new_user['token']
    public = True
    test_channel = channels_create(token, "Test Channel", public)
    c_id = test_channel['channel_id']

    auth_register("*****@*****.**", "password1", "Bilson", "Doe")
    user2 = auth_login("*****@*****.**", "password1")

    with pytest.raises(AccessError):
        channel_leave(user2['token'], c_id)
Ejemplo n.º 29
0
def channel_with_user():
    clear()
    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    user = auth_login("*****@*****.**", "password")
    public = True
    c_id = channels_create(user['token'], "Channel", public)

    return {
        'u_id': user['u_id'], 
        'token': user['token'], 
        'c_id': c_id['channel_id'],
    }
Ejemplo n.º 30
0
def test_external_user(channel_with_user, standup):
    assert standup['is_active']
    sender = channel_with_user

    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    member = auth_login("*****@*****.**", "password")
    
    sender_channel = channel_details(sender['token'], sender['c_id'])
    assert member['u_id'] not in sender_channel['all_members']

    with pytest.raises(AccessError):
        standup_send(member['token'], sender['c_id'], "Test Message")