def test_invalid_change_no_password(client, db):
    USERNAME = '******'
    CURRENT_PW = 'password'
    login(client, USERNAME, CURRENT_PW)
    change_user_settings_password(client, USERNAME, '', '', '')
    user = get_user_by_name(USERNAME)
    assert not (user.check_password(''))
def test_disable_account_without_slider(client, db):
    USERNAME = '******'
    CURRENT_PW = 'newpassword'
    DISABLE_ACCOUNT = "off"
    login(client, USERNAME, CURRENT_PW)
    change_user_settings_disable_acc(client, USERNAME, CURRENT_PW,
                                     DISABLE_ACCOUNT)
    user = get_user_by_name(USERNAME)
    assert user.get_active_status()
def test_valid_change_password(client, db):
    USERNAME = '******'
    CURRENT_PW = 'password'
    NEW_PW = 'newpassword'
    CONF_NEW_PW = 'newpassword'
    login(client, USERNAME, CURRENT_PW)
    change_user_settings_password(client, USERNAME, CURRENT_PW, NEW_PW,
                                  CONF_NEW_PW)
    assert get_user_by_name(USERNAME).check_password(NEW_PW)
Beispiel #4
0
def test_invalid_add_mail(client, db):
    USERNAME = '******'
    PASSWORD = '******'
    EMAIL_ADDR = '*****@*****.**'
    EMAIL_PASSWORD = '******'

    login(client, USERNAME, PASSWORD)
    response = add_mail(client, EMAIL_ADDR, EMAIL_PASSWORD)
    assert response.status_code == 200
    assert b'Unable to connect to mailbox.' in response.data
def test_invalid_change_mismatched_password(client, db):
    USERNAME = '******'
    CURRENT_PW = 'password'
    NEW_PW = 'newpassword'
    CONF_NEW_PW = 'newpassword123'
    login(client, USERNAME, CURRENT_PW)
    change_user_settings_password(client, USERNAME, CURRENT_PW, NEW_PW,
                                  CONF_NEW_PW)
    user = get_user_by_name(USERNAME)
    assert not (user.check_password(NEW_PW))
def test_disable_account_wrong_password(client, db):
    USERNAME = '******'
    CURRENT_PW = 'newpassword'
    DISABLE_ACCOUNT = "on"
    WRONG_CURRENT_PW = 'password'
    login(client, USERNAME, CURRENT_PW)
    change_user_settings_disable_acc(client, USERNAME, WRONG_CURRENT_PW\
    , DISABLE_ACCOUNT)
    user = get_user_by_name(USERNAME)
    assert user.get_active_status()
Beispiel #7
0
def test_detection_history(client, db):
    USERNAME = '******'
    PASSWORD = '******'
    MAIL_CREDS = get_server_mail_cred()
    EMAIL_ADDR = MAIL_CREDS[0]

    login(client, USERNAME, PASSWORD)
    mail_id = get_email_id_by_mail_address(EMAIL_ADDR)
    response = detection_history(client, mail_id)
    assert response.status_code == 200
    assert b'Detection History' in response.data
Beispiel #8
0
def test_valid_add_existing_mail(client, db):
    USERNAME = '******'
    PASSWORD = '******'
    MAIL_CREDS = get_server_mail_cred()
    EMAIL_ADDR = MAIL_CREDS[0]
    EMAIL_PASSWORD = MAIL_CREDS[1]

    login(client, USERNAME, PASSWORD)
    response = add_mail(client, EMAIL_ADDR, EMAIL_PASSWORD)
    assert response.status_code == 200
    assert b'[email protected] already exist in our database!' in response.data
Beispiel #9
0
def test_invalid_add_mail_password(client, db):
    USERNAME = '******'
    PASSWORD = '******'
    MAIL_CREDS = get_server_mail_cred()
    EMAIL_ADDR = MAIL_CREDS[0]
    EMAIL_PASSWORD = '******'

    login(client, USERNAME, PASSWORD)
    response = add_mail(client, EMAIL_ADDR, EMAIL_PASSWORD)
    assert response.status_code == 200
    assert b'Unable to connect to mailbox.' in response.data
def test_invalid_change_wrong_current_password(client, db):
    USERNAME = '******'
    CURRENT_PW = 'password'
    WRONG_CURRENT_PW = 'password123'
    NEW_PW = 'newpassword'
    CONF_NEW_PW = 'newpassword'
    login(client, USERNAME, CURRENT_PW)
    change_user_settings_password(client, USERNAME, WRONG_CURRENT_PW, \
    NEW_PW, CONF_NEW_PW)
    user = get_user_by_name(USERNAME)
    assert not (user.check_password(NEW_PW))
Beispiel #11
0
def test_valid_add_mail(client, db):
    USERNAME = '******'
    PASSWORD = '******'
    MAIL_CREDS = get_server_mail_cred()
    EMAIL_ADDR = MAIL_CREDS[0]
    EMAIL_PASSWORD = MAIL_CREDS[1]

    login(client, USERNAME, PASSWORD)
    response = add_mail(client, EMAIL_ADDR, EMAIL_PASSWORD)
    assert response.status_code == 200
    assert get_email_address_by_address(EMAIL_ADDR)
    assert b'*****@*****.**' in response.data
def test_update_forgotten_password(client, db):
    TEST_RESET_USER = '******'
    NEW_PASSWORD = '******'
    USER_ENTITY = get_user_by_name(TEST_RESET_USER)
    TOKEN_VALUE = USER_ENTITY.get_reset_token()

    # Creates a session variable for id to be passed in to route
    with client.session_transaction() as sess:
        sess['reset_user_id'] = USER_ENTITY.get_id()

    # Sends a post request to change_password with retrieved token
    r = client.post('/reset/change_password',
                    data={
                        'token': TOKEN_VALUE,
                        'new_password': NEW_PASSWORD
                    },
                    follow_redirects=True)

    login_response = login(client, TEST_RESET_USER, NEW_PASSWORD)

    # Assert TEST_RESET_USER token is None
    assert not get_user_by_name(TEST_RESET_USER).get_reset_token()
    # Assert successful login with new password
    assert login_response.status_code == 200
    assert b'dashboard' in login_response.data
def test_request_reset_password(client, db):
    # Creates a new user
    TEST_RESET_USER = '******'
    TEST_RESET_PASSWORD = '******'

    new_user = User(username=TEST_RESET_USER)
    new_user.set_password(TEST_RESET_PASSWORD)
    db.session.add(new_user)
    db.session.commit()

    # Logs in to user and add an email address and log out
    login_response = login(client, TEST_RESET_USER, TEST_RESET_PASSWORD)
    assert login_response.status_code == 200
    assert b'dashboard' in login_response.data

    MAIL_CREDS = get_server_mail_cred()
    TEST_EMAIL_ADDRESS = MAIL_CREDS[2]
    TEST_EMAIL_PASSWORD = MAIL_CREDS[3]
    response = add_mail(client, TEST_EMAIL_ADDRESS, TEST_EMAIL_PASSWORD)
    assert response.status_code == 200
    assert get_email_address_by_address(TEST_EMAIL_ADDRESS)
    assert b'*****@*****.**' in response.data

    logout(client)

    reset_response = request_reset_password(client, db, TEST_RESET_USER\
    , TEST_EMAIL_ADDRESS)
    # Assert redirected to update password page
    assert b'token' in reset_response.data
    # Assert token is generated
    assert get_user_by_name(TEST_RESET_USER).get_reset_token()
Beispiel #14
0
def test_valid_disable_enable_daily_notif(client, db):
    USERNAME = '******'
    PASSWORD = '******'
    MAIL_CREDS = get_server_mail_cred()
    EMAIL_ADDR = MAIL_CREDS[0]

    login(client, USERNAME, PASSWORD)
    mail_id = get_email_id_by_mail_address(EMAIL_ADDR)
    response = enable_disable_notif(client, mail_id)
    updated_pref = get_email_address_by_address('*****@*****.**')\
    .get_notification_pref()
    assert response.status_code == 200
    assert updated_pref == True

    response = enable_disable_notif(client, mail_id)
    updated_pref = get_email_address_by_address('*****@*****.**')\
    .get_notification_pref()
    assert response.status_code == 200
    assert updated_pref == False
def test_valid_login(client):
    USERNAME = '******'
    PASSWORD = '******'
    response = login(client, USERNAME, PASSWORD)
    assert response.status_code == 200
    assert b'Administrator Dashboard' in response.data