def test_teardown(): MAIL_CREDS = get_server_mail_cred() email = db.session.query(EmailAddress)\ .filter(EmailAddress.email_address == MAIL_CREDS[0])\ .first() user = db.session.query(User).filter(User.username == 'testuser123')\ .first() disable_user = db.session.query(User).filter(User.username == 'disableme')\ .first() reset_user = db.session.query(User).filter(User.username == 'resetmyaccount')\ .first() reset_email = db.session.query(EmailAddress)\ .filter(EmailAddress.email_address == MAIL_CREDS[2])\ .first() if email: db.session.delete(email) if user: db.session.delete(user) if disable_user: db.session.delete(disable_user) if reset_user: db.session.delete(reset_user) if reset_email: db.session.delete(reset_email) db.session.commit()
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()
def test_add_email(driver): MAIL_CREDS = get_server_mail_cred() EMAIL_ADDR = MAIL_CREDS[0] EMAIL_PASSWORD = MAIL_CREDS[1] add_email(driver, EMAIL_ADDR, EMAIL_PASSWORD) # Assert redirected to /emails page assert driver.current_url.split(sep='/')[-1] == 'emails' assert EMAIL_ADDR in driver.page_source
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
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
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_add_existing_email(driver): MAIL_CREDS = get_server_mail_cred() EMAIL_ADDR = MAIL_CREDS[0] EMAIL_PASSWORD = MAIL_CREDS[1] EXISITNG_EMAIL_ERR = EMAIL_ADDR + ' already exist in our database!' add_email(driver, EMAIL_ADDR, EMAIL_PASSWORD) # Assert redirected to /emails page assert driver.current_url.split(sep='/')[-1] == 'emails' assert EXISITNG_EMAIL_ERR in driver.page_source
def test_add_invalid_password(driver): MAIL_CREDS = get_server_mail_cred() EMAIL_ADDR = MAIL_CREDS[0] EMAIL_PASSWORD = '******' INVALID_PASSWORD_ERR = "Unable to connect to mailbox. Maybe you've entered a wrong email/password?" add_email(driver, EMAIL_ADDR, EMAIL_PASSWORD) # Assert redirected to /emails page assert driver.current_url.split(sep='/')[-1] == 'emails' assert INVALID_PASSWORD_ERR in driver.page_source
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_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_detection_history(driver): MAIL_CREDS = get_server_mail_cred() EMAIL_ADDR = MAIL_CREDS[0] sleep(2) wait_email_entry = WebDriverWait(driver, 5) wait_email_entry.until(EC.visibility_of_element_located((By.NAME\ , 'history-{}'.format(EMAIL_ADDR)))) driver.find_element_by_name('history-{}'.format(EMAIL_ADDR)).click() assert driver.current_url.split(sep='/')[-2] == 'history' assert 'Detection History' in driver.page_source # Wait for subscription button to appear and click wait_subscription = WebDriverWait(driver, 3) wait_subscription.until(EC.visibility_of_element_located((By.XPATH\ , '//*[@id="user-panel"]/a[3]'))) driver.find_element(By.XPATH, '//*[@id="user-panel"]/a[3]').click() # Assert redirected to /emails page assert driver.current_url.split(sep='/')[-1] == 'emails'
def test_daily_notification(driver): MAIL_CREDS = get_server_mail_cred() EMAIL_ADDR = MAIL_CREDS[0] sleep(2) wait_email_entry = WebDriverWait(driver, 5) wait_email_entry.until(EC.visibility_of_element_located((By.NAME\ , 'notif-{}'.format(EMAIL_ADDR)))) driver.find_element_by_name('notif-{}'.format(EMAIL_ADDR)).click() assert db.session.query(EmailAddress)\ .filter(EmailAddress.email_address == EMAIL_ADDR)\ .first().get_notification_pref() == True sleep(2) wait_email_entry = WebDriverWait(driver, 5) wait_email_entry.until(EC.visibility_of_element_located((By.NAME\ , 'notif-{}'.format(EMAIL_ADDR)))) driver.find_element_by_name('notif-{}'.format(EMAIL_ADDR)).click() assert db.session.query(EmailAddress)\ .filter(EmailAddress.email_address == EMAIL_ADDR)\ .first().get_notification_pref() == False
class Config(object): POSTGRES_USER = "******" POSTGRES_PASSWORD = "******" POSTGRES_URL = "localhost" POSTGRES_DB = "fyp-20s4-06p" SECRET_KEY = 'secret' uri_template = 'postgresql+psycopg2://{usr}:{pw}@{url}/{db}' SQLALCHEMY_DATABASE_URI = os.environ.get( 'DATABASE_URL') or uri_template.format(usr=POSTGRES_USER, pw=POSTGRES_PASSWORD, url=POSTGRES_URL, db=POSTGRES_DB) LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT') SQLALCHEMY_TRACK_MODIFICATIONS = False #Recaptcha RECAPTCHA_USE_SSL = False RECAPTCHA_PUBLIC_KEY = '6Lezk-IZAAAAABW4o03l4BBW8OpmmZ8p7GhUZQC0' RECAPTCHA_PRIVATE_KEY = get_recaptcha_secret() RECAPTCHA_OPTIONS = {'theme': 'black'} # Configures ReCAPTCHA and Contact Us # If TESTING = True, ReCAPTCHA will be inactive and Flask-Mail Contact us will NOT work # If TESTING = False, ReCAPTCHA will be active and Flask-Mail Contact us will work TESTING = os.environ.get('TESTING') or False # Flask-Mail Configs MAIL_CREDS = get_server_mail_cred() MAIL_SERVER = 'smtp.gmail.com' MAIL_PORT = 465 MAIL_USERNAME = MAIL_CREDS[0] MAIL_PASSWORD = MAIL_CREDS[1] MAIL_DEFAULT_SENDER = MAIL_CREDS[0] MAIL_USE_TSL = False MAIL_USE_SSL = True MAIL_SUPRRESS_SEND = False # Scheduled Tasks JOBS = [ { 'id': 'job1', 'func': 'app.utils.DBUtils:purge_user_tokens', 'trigger': 'interval', 'hours': 1 # 'seconds' : 10 }, { 'id': 'job2', 'func': 'app.utils.DBUtils:check_all_mailboxes', 'trigger': 'interval', 'hours': 4 }, { 'id': 'job3', 'func': 'app.utils.EmailUtils:send_daily_notice', 'trigger': 'interval', 'days': 1 }, { 'id': 'job4', 'func': 'app.utils.DBUtils:delete_inactive_emails', 'trigger': 'interval', 'days': 90 }, { 'id': 'job5', 'func': 'app.utils.DBUtils:delete_inactive_accounts', 'trigger': 'interval', 'days': 365 } ] SCHEDULER_API_ENABLED = True