2022-10-11 08:56:12 +00:00
|
|
|
import { test } from '../../playwright/test';
|
2022-06-01 08:39:31 +00:00
|
|
|
|
|
|
|
test('Sign in with Gitlab', async ({ app, page }) => {
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('button', { name: 'Setup Git Sync' }).click();
|
|
|
|
await page.getByRole('tab', { name: 'GitLab' }).click();
|
2022-06-01 08:39:31 +00:00
|
|
|
|
|
|
|
const fakeGitLabOAuthWebFlow = app.evaluate(electron => {
|
|
|
|
return new Promise<{ redirectUrl: string }>(resolve => {
|
|
|
|
const webContents = electron.BrowserWindow.getAllWindows()[0].webContents;
|
|
|
|
// Remove all navigation listeners so that only the one we inject will run
|
|
|
|
webContents.removeAllListeners('will-navigate');
|
2022-06-15 03:41:19 +00:00
|
|
|
webContents.on('will-navigate', (event: Event, url: string) => {
|
|
|
|
event.preventDefault();
|
2022-06-01 08:39:31 +00:00
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
// We use the same state parameter that the app created to assert that we prevent CSRF
|
|
|
|
const stateSearchParam = parsedUrl.searchParams.get('state') || '';
|
|
|
|
const redirectUrl = `insomnia://oauth/gitlab/authenticate?code=12345&state=${stateSearchParam}`;
|
|
|
|
resolve({ redirectUrl });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const [{ redirectUrl }] = await Promise.all([
|
|
|
|
fakeGitLabOAuthWebFlow,
|
2023-01-20 14:49:52 +00:00
|
|
|
page.getByText('Authenticate with GitLab').click({
|
2022-06-01 08:39:31 +00:00
|
|
|
// When playwright clicks a link it waits for navigation to finish.
|
|
|
|
// In our case we are stubbing the navigation and we don't want to wait for it.
|
|
|
|
noWaitAfter: true,
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
await page.locator('input[name="link"]').click();
|
|
|
|
await page.locator('input[name="link"]').fill(redirectUrl);
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('button', { name: 'Add' }).click();
|
2022-06-01 08:39:31 +00:00
|
|
|
|
|
|
|
test.expect(await page.locator('text="Mark Kim"')).toBeTruthy();
|
|
|
|
test.expect(await page.locator('button[name="sign-out"]')).toBeTruthy();
|
|
|
|
});
|