acceptance tests can login to site
This commit is contained in:
parent
04b0b1db0d
commit
5195b2d32d
@ -11,6 +11,14 @@ from .live_server import LiveServer
|
|||||||
from .browsers import BROWSERSTACK_CONFIG
|
from .browsers import BROWSERSTACK_CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function", autouse=True)
|
||||||
|
def session(db, request):
|
||||||
|
"""
|
||||||
|
Override base test session
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def live_app(app):
|
def live_app(app):
|
||||||
handler = RotatingFileHandler("log/acceptance.log", maxBytes=10000, backupCount=1)
|
handler = RotatingFileHandler("log/acceptance.log", maxBytes=10000, backupCount=1)
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
import requests
|
||||||
|
from flask import url_for
|
||||||
|
from urllib.parse import urljoin
|
||||||
from .browsers import BROWSERSTACK_CONFIG
|
from .browsers import BROWSERSTACK_CONFIG
|
||||||
|
from atst.domain.users import Users
|
||||||
|
import atst.domain.exceptions as exceptions
|
||||||
|
from tests.test_auth import _login
|
||||||
|
|
||||||
|
import cryptography.x509 as x509
|
||||||
|
from cryptography.hazmat.backends import default_backend
|
||||||
|
|
||||||
|
|
||||||
|
USER_CERT = "ssl/client-certs/atat.mil.crt"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("browser_type", BROWSERSTACK_CONFIG.keys())
|
@pytest.mark.parametrize("browser_type", BROWSERSTACK_CONFIG.keys())
|
||||||
@ -7,3 +19,51 @@ def test_can_get_title(browser_type, live_app, drivers):
|
|||||||
driver = drivers[browser_type]
|
driver = drivers[browser_type]
|
||||||
driver.get(live_app.server_url)
|
driver.get(live_app.server_url)
|
||||||
assert "JEDI" in driver.title
|
assert "JEDI" in driver.title
|
||||||
|
|
||||||
|
|
||||||
|
def _get_common_name(cert_path):
|
||||||
|
with open(USER_CERT, "rb") as cert_file:
|
||||||
|
cert = x509.load_pem_x509_certificate(cert_file.read(), default_backend())
|
||||||
|
common_names = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)
|
||||||
|
return common_names[0].value
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def valid_user_from_cert():
|
||||||
|
cn = _get_common_name(USER_CERT)
|
||||||
|
cn_parts = cn.split(".")
|
||||||
|
user_info = {
|
||||||
|
"last_name": cn_parts[0],
|
||||||
|
"first_name": cn_parts[1],
|
||||||
|
"dod_id": cn_parts[-1],
|
||||||
|
"atat_role_name": "developer",
|
||||||
|
}
|
||||||
|
return Users.get_or_create_by_dod_id(**user_info)
|
||||||
|
|
||||||
|
|
||||||
|
def _valid_login(client, driver):
|
||||||
|
with open(USER_CERT) as cert:
|
||||||
|
response = _login(client, cert=cert.read())
|
||||||
|
cookie = [cookie for cookie in client.cookie_jar][0]
|
||||||
|
driver.add_cookie(
|
||||||
|
{
|
||||||
|
"domain": None,
|
||||||
|
"name": cookie.name,
|
||||||
|
"value": cookie.value,
|
||||||
|
"path": cookie.path,
|
||||||
|
"secure": cookie.secure,
|
||||||
|
"expiry": cookie.expires,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_login(live_app, drivers, client, valid_user_from_cert):
|
||||||
|
driver = drivers["win10_chrome62"]
|
||||||
|
driver.get(live_app.server_url)
|
||||||
|
cookie = _valid_login(client, driver)
|
||||||
|
requests_page = urljoin(
|
||||||
|
live_app.server_url, url_for("requests.requests_form_new", screen=1)
|
||||||
|
)
|
||||||
|
driver.get(requests_page)
|
||||||
|
user = valid_user_from_cert
|
||||||
|
assert user.last_name in driver.page_source
|
||||||
|
Loading…
x
Reference in New Issue
Block a user