Skip to content
Snippets Groups Projects
test_e2e_auth.py 3.18 KiB
Newer Older
kaiyou's avatar
kaiyou committed
from playwright import sync_api as pw

import requests
def do_login(page, username, password):
    """Logs into hiboo"""
kaiyou's avatar
kaiyou committed
    page.get_by_label("Username").fill(username)
    page.get_by_label("Password").fill(password)
    page.get_by_role("button", name="Sign in").click()


def test_login(app, context, username, password):
    """Test that logs in as default test user"""
    page = context.new_page()
    page.goto(app)
    do_login(page, username, password)
kaiyou's avatar
kaiyou committed
    pw.expect(page.get_by_text("Sign out")).to_be_visible()

    
def test_saml_auth(app, context, username, password, service_name, httpd, httpd_saml, temp):
    # First create a SAML service
    page = context.new_page()
    page.goto(app + "/service/create/saml")
    do_login(page, username, password)
    page.get_by_label("Service name").fill(service_name)
    page.get_by_label("Provider").fill("test")
    page.get_by_label("Description").fill("test")
    page.get_by_label("Profile policy").select_option("open")
    page.get_by_label("Maximum profile count").fill("10")
    page.get_by_label("SP entity id").fill("http://localhost:8123/mellon/metadata")
    page.get_by_label("SP ACS").fill("http://localhost:8123/mellon/postResponse")
    page.get_by_role("button", name="submit").click()
    # Then access the service and extract useful data
    page.get_by_text(service_name).click()
    httpd(httpd_saml.format(
        metadata=temp(requests.get(page.get_by_label("SAML Metadata").text_content()).content),
        key=temp(page.get_by_label("SP private key").text_content()),
        cert=temp(page.get_by_label("SP certificate").text_content())
    ))
    # Finally log into the service provider, validate a new profile and get in
    page.goto("http://localhost:8123/")
    page.get_by_role("button", name="Sign up").click()
    pw.expect(page.get_by_text("Hello world")).to_be_visible()


def test_oidc_auth(app, context, username, password, service_name, httpd, httpd_oidc, temp):
    # First create an OIDC service
    page = context.new_page()
    page.goto(app + "/service/create/oidc")
    do_login(page, username, password)
    page.get_by_label("Service name").fill(service_name)
    page.get_by_label("Provider").fill("test")
    page.get_by_label("Description").fill("test")
    page.get_by_label("Profile policy").select_option("open")
    page.get_by_label("Maximum profile count").fill("10")
    page.get_by_label("Redirect URI").fill("http://localhost:8123/redirect_uri")
    page.get_by_label("OpenID Connect grant type").select_option("authorization_code")
    page.get_by_label("Allowed response types").select_option("code")
    page.get_by_role("button", name="submit").click()
    # Then access the service and extract useful data
    page.get_by_text(service_name).click()
    httpd(httpd_oidc.format(
        metadata=page.get_by_label("OIDC discovery endpoint").text_content(),
        client_id=page.get_by_label("Client ID").text_content(),
        client_secret=page.get_by_label("Client secret").text_content()
    ))
    # Finally log into the client app, validate a new profile and get in
    page.goto("http://localhost:8123/")
    page.get_by_role("button", name="Sign up").click()
    pw.expect(page.get_by_text("Hello world")).to_be_visible()