From caa2f42e2c0f39cd58ba35378dc5d40fafec9346 Mon Sep 17 00:00:00 2001 From: pedro Date: Sat, 9 Mar 2024 20:30:36 +0100 Subject: [PATCH] WIP pilot tests: basic OIDC flow works --- src/constants/env_constants.ts | 5 ++- tests/pilot-tests.spec.ts | 82 ++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/pilot-tests.spec.ts diff --git a/src/constants/env_constants.ts b/src/constants/env_constants.ts index c294edb..380c39b 100644 --- a/src/constants/env_constants.ts +++ b/src/constants/env_constants.ts @@ -3,6 +3,9 @@ export const ENCRYPTION_KEY = "1234" export const ADMIN_EMAIL = "idhub_admin@pangea.org" export const ADMIN_K = "1234" export const KO_ADMIN_K = "876" + +export const IDHUB_WALLET = process.env.IDHUB_WALLET || "https://idhub1-autotest.demo.pangea.org" +export const IDHUB_VERIFIER = process.env.IDHUB_VERIFIER || "https://idhub2-autotest.demo.pangea.org" export const URL_IDHUB = "https://idhub1-autotest.demo.pangea.org" //export const URL_IDHUB = "https://idhub1-nightly.demo.pangea.org" @@ -16,4 +19,4 @@ export const USER_K = "1234" export const KO_USER_K = "876" export const URL_PASS_RESET = URL_IDHUB + "/auth/password_reset/" -export const URL_SCHEMAS = URL_IDHUB + "/admin/schemas/" \ No newline at end of file +export const URL_SCHEMAS = URL_IDHUB + "/admin/schemas/" diff --git a/tests/pilot-tests.spec.ts b/tests/pilot-tests.spec.ts new file mode 100644 index 0000000..4ecd546 --- /dev/null +++ b/tests/pilot-tests.spec.ts @@ -0,0 +1,82 @@ +import { test, expect } from '@playwright/test'; +// TODO import domain WALLET y VERIFIER +// TODO env var + +// optional page (decrypt) +// src https://playwright.dev/docs/locators#matching-one-of-the-two-alternative-locators +async function accept_data_protection(page) { + // TODO cannot be, because of this inconsistency: Data Protection (user) vs Data protection (admin) + //const data_protection = await page.getByRole('heading', { name: 'Data protection', exact: true }) + const data_protection = await page.getByRole('heading', { name: 'Data protection' }) + if (await data_protection.isVisible()) { + await page.locator('#id_accept_privacy').check(); + await page.locator('#id_accept_legal').check(); + await page.locator('#id_accept_cookies').check(); + await page.getByRole('link', { name: 'Confirm' }).click(); + } +} + + +// useful for DEBUG +// await page.pause(); + +test('test', async ({ page }) => { + // TODO hardcoded domain WALLET + await page.goto('http://localhost/login/'); + await page.getByPlaceholder('Email address').click(); + await page.getByPlaceholder('Email address').fill('idhub_admin@pangea.org'); + await page.getByPlaceholder('Password').fill('1234'); + await page.getByRole('button', { name: 'Log in' }).click(); + + //const encryption_key_page = page.getByText('Encryption Key') + const encryption_key_page_admin = await page.getByRole('heading', { name: 'Encryption Key', exact: true }) + if (await encryption_key_page_admin.isVisible()) { + await page.getByPlaceholder('Key for encrypt the secrets').click(); + await page.getByPlaceholder('Key for encrypt the secrets').fill('1234'); + await page.getByRole('button', { name: 'Save' }).click(); + } + + await accept_data_protection(page); + + await page.getByRole('link', { name: ' Data' }).click(); + await page.getByRole('link', { name: 'Import data ' }).click(); + // src https://playwright.dev/docs/input#select-options + await page.getByLabel('Schema').selectOption('Financial Vulnerability Credential'); + // src https://playwright.dev/docs/input#upload-files + // TODO hardcoded URL + await page.getByLabel('File to import').setInputFiles('/home/music/trustchain-oc1-orchestral-docker/IdHub/examples/excel_examples/financial-vulnerability.xlsx'); + //await page.setInputFiles('input[type="file"]', '/home/music/trustchain-oc1-orchestral-docker/IdHub/examples/excel_examples/financial-vulnerability.xlsx'); + await page.getByRole('button', { name: 'Save' }).click(); + await page.getByRole('link', { name: '', exact: true }).click(); + await page.getByPlaceholder('Email address').click(); + await page.getByPlaceholder('Email address').fill('user1@example.org'); + await page.getByPlaceholder('Password').click(); + await page.getByPlaceholder('Password').fill('1234'); + await page.getByRole('button', { name: 'Log in' }).click(); + + await accept_data_protection(page); + + await page.getByRole('link', { name: 'Identities (DIDs)' }).click(); + await page.getByRole('link', { name: 'Add Identity ' }).click(); + await page.getByPlaceholder('Label').click(); + await page.getByPlaceholder('Label').fill('default'); + await page.getByLabel('Type').selectOption('1'); + await page.getByRole('button', { name: 'Save' }).click(); + await page.getByRole('link', { name: 'Request a credential' }).click(); + await page.getByRole('button', { name: 'Request' }).click(); + // TODO hardcoded domain VERIFIER + await page.goto('http://idhub2/promotion/'); + await page.getByRole('link', { name: 'Contractar amb credencial' }).click(); + await page.getByRole('button', { name: 'Go' }).click(); + await page.getByRole('radio').first().check(); + await page.getByRole('checkbox').check(); + await page.getByRole('button', { name: 'Present' }).click(); + await page.pause(); + // TODO averiguar si devuelve código es final 1 (OIDC_REDIRECT=false) + + // TODO averiguar si hace redirección a 2 es final 2 (OIDC_REDIRECT=true) +}); + +// TODO test que hace la presentación de la credencial al revés + +// TODO test que hace la presentación de la credencial al revés