Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update playwright tests to use "api-key" for authentication [DEV-4071] #557

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
RESOLVER_URL: ${{ vars.RESOLVER_URL }}
TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }}
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
TEST_USER_API_KEY: ${{ secrets.TEST_USER_API_KEY }}
TESTNET_RPC_URL: ${{ vars.TESTNET_RPC_URL }}
VERIDA_PRIVATE_KEY: ${{ secrets.VERIDA_PRIVATE_KEY }}
CREDS_DECRYPTION_SECRET: ${{ secrets.CREDS_DECRYPTION_SECRET }}
Expand Down
6 changes: 6 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ ISSUER_PRIVATE_KEY_HEX="akjvncanv....avoa"
ISSUER_PUBLIC_KEY_HEX="alnvca...dvncioa"
ISSUER_DID="did:cheqd:testnet:afcnoa...adv"
DEFAULT_FEE_PAYER_MNEMONIC="sketch mountain ....."


# TEST_RUNNER
TEST_USER_EMAIL='test@cheqd.io'
TEST_USER_PASSWORD='...'
TEST_USER_API_KEY='caas_...'
4 changes: 4 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default defineConfig({
...devices['Desktop Chrome'],
// Use prepared auth state.
storageState: STORAGE_STATE_AUTHENTICATED,
extraHTTPHeaders: {
// Add x-api-key token to all authenticated requests.
'x-api-key': `${process.env.TEST_USER_API_KEY}`,
},
},
dependencies: ['Setup authenticated user'],
},
Expand Down
41 changes: 23 additions & 18 deletions tests/e2e/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@ setup('Authenticate as user', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
// Push Log-in button
await page.goto(`${process.env.APPLICATION_BASE_URL}/swagger`);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL(`${process.env.LOGTO_ENDPOINT}/sign-in`, {
waitUntil: 'domcontentloaded',
});

// Fill out the form and submit
await page.getByPlaceholder('Email / Username').fill(process.env.TEST_USER_EMAIL);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByPlaceholder('Password').fill(process.env.TEST_USER_PASSWORD);
await page.getByRole('button', { name: 'Continue' }).click();
await page.waitForURL(`${process.env.APPLICATION_BASE_URL}/swagger/`, {
waitUntil: 'domcontentloaded',
timeout: 45000,
});
await expect(page.getByRole('button', { name: 'Log out' })).toBeVisible();

const response = await page.goto(`${process.env.APPLICATION_BASE_URL}/account`);
expect(response.ok()).toBe(true);

// step 1: click on "Authorize" button
await page.locator('button.btn.authorize.unlocked:has(span:has-text("Authorize"))').click();

// step 2: Wait for a modal to pop up
await page.waitForSelector('div.modal-ux');

// step 3: find a input and write "TEST_USER_API_KEY"

await page.fill('div.wrapper section input[type="text"]', process.env.TEST_USER_API_KEY);

// step 4: click on "Authorize" button
await page.click('button.btn.modal-btn.auth.authorize.button[aria-label="Apply credentials"][type="submit"]');

// step 5: assert "Logout" button is visible
const logOutButton = await page.locator(
'button.btn.modal-btn.auth.button[aria-label="Remove authorization"]:has-text("Logout")'
);

await expect(logOutButton).toBeVisible();

// Step 5: click on "Close" button
await page.locator('button.btn.modal-btn.auth.btn-done.button').click();

// End of authentication steps.

Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/no-auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { StatusCodes } from 'http-status-codes';

dotenv.config();

setup('Unauthenticated user', async ({ page }) => {
setup('Unauthenticated user', async ({ page, request }) => {
// Check that current user is really unauthenticated

await page.goto(`${process.env.APPLICATION_BASE_URL}/swagger`);
await expect(page.getByRole('button', { name: 'Log in' })).toBeVisible();
const authorizeButton = await page.locator('button.btn.authorize.unlocked:has(span:has-text("Authorize"))');
await expect(authorizeButton).toBeVisible();

const response = await page.goto(`${process.env.APPLICATION_BASE_URL}/account`);
expect(response.ok()).not.toBe(true);
Expand Down
Loading