2022-10-11 08:56:12 +00:00
|
|
|
import { test } from '../../playwright/test';
|
2023-07-13 17:09:02 +00:00
|
|
|
test('Clone from github', async ({ page }) => {
|
|
|
|
await page.getByRole('button', { name: 'Git Clone' }).click();
|
|
|
|
await page.getByRole('tab', { name: ' Git' }).click();
|
|
|
|
await page.getByPlaceholder('https://github.com/org/repo.git').fill('https://github.com/gatzjames/insomnia-git-example.git');
|
|
|
|
await page.getByPlaceholder('Name').fill('J');
|
|
|
|
await page.getByPlaceholder('Email').fill('J');
|
|
|
|
await page.getByPlaceholder('MyUser').fill('J');
|
|
|
|
await page.getByPlaceholder('88e7ee63b254e4b0bf047559eafe86ba9dd49507').fill('J');
|
|
|
|
await page.getByTestId('git-repository-settings-modal__sync-btn').click();
|
|
|
|
await page.getByRole('button', { name: 'Toggle Preview' }).click();
|
|
|
|
});
|
2022-03-18 09:57:12 +00:00
|
|
|
test('Sign in with GitHub', async ({ app, page }) => {
|
2023-06-27 18:46:43 +00:00
|
|
|
await page.getByRole('button', { name: 'New Document' }).click();
|
|
|
|
await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click();
|
2023-07-05 16:51:55 +00:00
|
|
|
await page.getByRole('button', { name: 'Git Sync' }).click();
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('button', { name: 'Setup Git Sync' }).click();
|
2022-03-18 09:57:12 +00:00
|
|
|
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('tab', { name: 'Github' }).click();
|
2022-03-18 09:57:12 +00:00
|
|
|
|
|
|
|
// Prevent the app from opening the browser to the authorization page
|
|
|
|
// and return the url that would be created by following the GitHub OAuth flow.
|
|
|
|
// https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#web-application-flow
|
|
|
|
const fakeGitHubOAuthWebFlow = 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-03-18 09:57:12 +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/github/authenticate?state=${stateSearchParam}&code=12345`;
|
|
|
|
resolve({ redirectUrl });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const [{ redirectUrl }] = await Promise.all([
|
|
|
|
fakeGitHubOAuthWebFlow,
|
2023-01-20 14:49:52 +00:00
|
|
|
page.getByText('Authenticate with GitHub').click({
|
2022-03-18 09:57:12 +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-08-11 11:54:39 +00:00
|
|
|
await page.getByRole('button', { name: 'Authenticate' }).click();
|
2022-03-18 09:57:12 +00:00
|
|
|
|
|
|
|
await page
|
|
|
|
.locator('input[name="uri"]')
|
|
|
|
.fill('https://github.com/insomnia/example-repo');
|
|
|
|
|
2022-05-19 14:17:02 +00:00
|
|
|
await page.locator('data-testid=git-repository-settings-modal__sync-btn').click();
|
2022-03-18 09:57:12 +00:00
|
|
|
});
|