mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 14:31:02 +00:00 
			
		
		
		
	**Backport:** https://codeberg.org/forgejo/forgejo/pulls/8400 - This test is the source of many transient errors https://codeberg.org/forgejo/forgejo/issues/8359#issuecomment-5655557 and is semi-reproducible locally. Any debugging code that is added will result in the error no longer being reproducible, making it hard to say why this is failing. - It no longer seems necessary to add this `waitForURL` call as Playwright now seems to gracefully handle the case where we want to go to a specific page while playwright might still be navigating to another URL that was initiated by clicking on a button - thus removing the source of the transient error altogether. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8402 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: Beowulf <beowulf@beocode.eu> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
		
			
				
	
	
		
			66 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| // Copyright 2024 The Forgejo Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| // @watch start
 | |
| // templates/user/auth/**
 | |
| // templates/user/settings/**
 | |
| // web_src/js/features/user-**
 | |
| // @watch end
 | |
| 
 | |
| import {expect} from '@playwright/test';
 | |
| import {test, save_visual, create_temp_user, login_user} from './utils_e2e.ts';
 | |
| 
 | |
| test('WebAuthn register & login flow', async ({browser, request}, workerInfo) => {
 | |
|   test.skip(workerInfo.project.name !== 'chromium', 'Uses Chrome protocol');
 | |
|   const {context, username} = await create_temp_user(browser, workerInfo, request);
 | |
|   const page = await context.newPage();
 | |
| 
 | |
|   // Register a security key.
 | |
|   let response = await page.goto('/user/settings/security');
 | |
|   expect(response?.status()).toBe(200);
 | |
| 
 | |
|   // https://github.com/microsoft/playwright/issues/7276#issuecomment-1516768428
 | |
|   const cdpSession = await page.context().newCDPSession(page);
 | |
|   await cdpSession.send('WebAuthn.enable');
 | |
|   await cdpSession.send('WebAuthn.addVirtualAuthenticator', {
 | |
|     options: {
 | |
|       protocol: 'ctap2',
 | |
|       ctap2Version: 'ctap2_1',
 | |
|       hasUserVerification: true,
 | |
|       transport: 'usb',
 | |
|       automaticPresenceSimulation: true,
 | |
|       isUserVerified: true,
 | |
|     },
 | |
|   });
 | |
| 
 | |
|   await page.locator('input#nickname').fill('Testing Security Key');
 | |
|   await save_visual(page);
 | |
|   await page.getByText('Add security key').click();
 | |
| 
 | |
|   // Logout.
 | |
|   await expect(async () => {
 | |
|     await page.locator('div[aria-label="Profile and settings…"]').click();
 | |
|     await page.getByText('Sign out').click();
 | |
|   }).toPass();
 | |
| 
 | |
|   // Login.
 | |
|   response = await page.goto('/user/login');
 | |
|   expect(response?.status()).toBe(200);
 | |
| 
 | |
|   await page.getByLabel('Username or email address').fill(username);
 | |
|   await page.getByLabel('Password').fill('password');
 | |
|   await page.getByRole('button', {name: 'Sign in'}).click();
 | |
|   await page.waitForURL(`${workerInfo.project.use.baseURL}/user/webauthn`);
 | |
|   await page.waitForURL(`${workerInfo.project.use.baseURL}/`);
 | |
| 
 | |
|   // Cleanup.
 | |
|   response = await page.goto('/user/settings/security');
 | |
|   expect(response?.status()).toBe(200);
 | |
|   await page.getByRole('button', {name: 'Remove'}).click();
 | |
|   await save_visual(page);
 | |
|   await page.getByRole('button', {name: 'Yes'}).click();
 | |
|   await page.waitForLoadState();
 | |
| 
 | |
|   // verify the user can login without a key
 | |
|   await login_user(browser, workerInfo, username);
 | |
| });
 |