insomnia/packages/insomnia-smoke-test/tests/oauth-gitlab.test.ts
James Gatz 4dd89b14d2
add gitlab oauth provider and ui (#4727)
* add gitlab oauth provider and ui

* add gitlab remaining

* add graphql field in query

* add gitlab oauth provider and ui

* add gitlab remaining

* add graphql field in query

* add some changes for testing

* add gitlab oauth provider and ui

* add gitlab remaining

* add graphql field in query

* add some changes for testing

* add some changes

* modify test

* try to refresh the token on git auth failure

* use localStorage to retrieve the session token

* simplify e2e tests for gitlab

* read the gitlab config from the api

* refresh the token if unauthorised

* use the rest api to fetch the user's data

* add loading state for config and handle 4xx errors in the ui

Co-authored-by: jackkav <jackkav@gmail.com>

* improve config fetching

* fix(e2e): add mock route for config

* Fix fetching gitlab config from the API

* add src as dep to avatar component hook

Co-authored-by: Mark Kim <yowmark613@gmail.com>
Co-authored-by: jackkav <jackkav@gmail.com>
Co-authored-by: David Marby <david@dmarby.se>
2022-06-01 10:39:31 +02:00

40 lines
1.7 KiB
TypeScript

import { test } from '../playwright/test';
test('Sign in with Gitlab', async ({ app, page }) => {
await page.locator('text=Setup Git Sync').click();
await page.locator('button:has-text("Repository Settings")').click();
await page.locator('li[role="tab"]:has-text("GitLab")').click();
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');
webContents.on('will-navigate', (e, url) => {
e.preventDefault();
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,
page.locator('text=Authenticate with GitLab').click({
// 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);
await page.locator('button[name="add-token"]').click();
test.expect(await page.locator('text="Mark Kim"')).toBeTruthy();
test.expect(await page.locator('button[name="sign-out"]')).toBeTruthy();
});