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

INS-2497: prevent git sync parse failure #5954

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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,58 @@ test('Clone Repo with bad values', async ({ page }) => {
await expect(page.locator('.app')).toContainText('Error Pushing Repository');
});

test('Clone Bitbucket Repo with bad values', async ({ page }) => {
await page.click('[data-testid="project"] >> text=Insomnia');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('menuitem', { name: 'Git Clone' }).click();
await page.getByRole('tab', { name: 'Git' }).nth(2).click();

// Fill in Git Sync details and clone repository
await page.getByText('Git URI (https)').fill('https://bitbucket.org/atlassian/bitbucket-example-plugin.git');
await page.getByText('Author Name').fill('test');
await page.getByText('Author Email').fill('test');
await page.getByText('Username').fill('test');
await page.getByText('Authentication Token').fill('test');
await page.getByRole('button', { name: 'Clone' }).click();

// Create a branch and try to push with bad Git token
await page.getByRole('button', { name: 'master' }).click();
await page.getByRole('menuitem', { name: 'Branches' }).click();
await page.getByPlaceholder('testing-branch').fill('test123');
await page.getByRole('button', { name: '+ Create' }).click();
await page.getByRole('cell', { name: 'test123(current)' }).click();
await page.getByRole('button', { name: 'Done' }).click();
await page.getByRole('button', { name: 'test123' }).click();
await page.getByRole('menuitem', { name: 'Push' }).click();
await expect(page.locator('.app')).toContainText('Error Pushing Repository');
});

test('Clone Gitlab Repo with bad values', async ({ page }) => {
await page.click('[data-testid="project"] >> text=Insomnia');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('menuitem', { name: 'Git Clone' }).click();
await page.getByRole('tab', { name: 'Git' }).nth(2).click();

// Fill in Git Sync details and clone repository
await page.getByText('Git URI (https)').fill('https://gitlab.com/gitlab-examples/gitlab-examples.gitlab.io.git');
await page.getByText('Author Name').fill('test');
await page.getByText('Author Email').fill('test');
await page.getByText('Username').fill('test');
await page.getByText('Authentication Token').fill('test');
await page.getByRole('button', { name: 'Clone' }).click();

// Create a branch and try to push with bad Git token
await page.getByRole('button', { name: 'master' }).click();
await page.getByRole('menuitem', { name: 'Branches' }).click();
await page.getByPlaceholder('testing-branch').fill('test123');
await page.getByRole('button', { name: '+ Create' }).click();
await page.getByRole('cell', { name: 'test123(current)' }).click();
await page.getByRole('button', { name: 'Done' }).click();
await page.getByRole('button', { name: 'test123' }).click();
await page.getByRole('menuitem', { name: 'Push' }).click();
await expect(page.locator('.app')).toContainText('Error Pushing Repository');
});

// TODO(kreosus): more git sync prerelease tests will be added when gh auth secrets are properly setup for CI use

// TODO(kreosus): more preferences scenarios will be added in the followup iterations of increasing app test coverage
64 changes: 56 additions & 8 deletions packages/insomnia/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"fs-extra": "^5.0.0",
"grpc-reflection-js": "github:Kong/grpc-reflection-js#01fcce0",
"hawk": "9.0.1",
"hosted-git-info": "5.2.1",
"hkdf": "^0.0.2",
"html-entities": "^1.2.0",
"httpsnippet": "^2.0.0",
Expand Down Expand Up @@ -132,6 +133,7 @@
"@types/dompurify": "^2.3.3",
"@types/fs-extra": "^5.1.0",
"@types/hawk": "9.0.2",
"@types/hosted-git-info": "3.0.2",
"@types/js-yaml": "^4.0.1",
"@types/jshint": "^2.12.1",
"@types/license-checker": "^25.0.1",
Expand Down
24 changes: 1 addition & 23 deletions packages/insomnia/src/sync/git/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';

import { addDotGit, translateSSHtoHTTP } from '../utils';
import { addDotGit } from '../utils';

const links = {
scp: {
Expand All @@ -21,28 +21,6 @@ const links = {
},
};

describe('translateSSHtoHTTP', () => {
it('fixes up scp-style', () => {
expect(translateSSHtoHTTP(links.scp.bare)).toEqual(links.https.bare);
expect(translateSSHtoHTTP(links.scp.dotGit)).toEqual(links.https.dotGit);
});

it('fixes up ssh-style', () => {
expect(translateSSHtoHTTP(links.ssh.bare)).toEqual('https://a@github.com/b');
expect(translateSSHtoHTTP(links.ssh.dotGit)).toEqual('https://a@github.com/b.git');
});

it('leaves http alone', () => {
expect(translateSSHtoHTTP(links.http.bare)).toEqual(links.http.bare);
expect(translateSSHtoHTTP(links.http.dotGit)).toEqual(links.http.dotGit);
});

it('leaves https alone', () => {
expect(translateSSHtoHTTP(links.https.bare)).toEqual(links.https.bare);
expect(translateSSHtoHTTP(links.https.dotGit)).toEqual(links.https.dotGit);
});
});

describe('addDotGit', () => {
it('adds the .git to bare links', () => {
expect(addDotGit(links.scp.bare)).toEqual(links.scp.dotGit);
Expand Down
8 changes: 0 additions & 8 deletions packages/insomnia/src/sync/git/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import type { GitCredentials } from './git-vcs';
import { getAccessToken as getGitHubAccessToken } from './github-oauth-provider';
import { getAccessToken as getGitlabAccessToken, refreshToken as refreshGitlabToken } from './gitlab-oauth-provider';

export const translateSSHtoHTTP = (url: string) => {
// handle "shorter scp-like syntax"
url = url.replace(/^git@([^:]+):/, 'https://$1/');
// handle proper SSH URLs
url = url.replace(/^ssh:\/\//, 'https://');
return url;
};

export const addDotGit = (url: string): string => (url.endsWith('.git') ? url : `${url}.git`);

const onMessage: MessageCallback = message => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const CustomRepositorySettingsFormGroup: FunctionComponent<Props> = ({
<label>
Git URI (https)
<input
type="url"
required
autoFocus
name="uri"
Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia/src/ui/routes/git-actions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { invariant } from '@remix-run/router';
import { fromUrl } from 'hosted-git-info';
import { Errors } from 'isomorphic-git';
import path from 'path';
import { ActionFunction, LoaderFunction, redirect } from 'react-router-dom';
Expand Down Expand Up @@ -32,7 +33,6 @@ import { shallowClone } from '../../sync/git/shallow-clone';
import {
addDotGit,
getOauth2FormatName,
translateSSHtoHTTP,
} from '../../sync/git/utils';
import { SegmentEvent, trackSegmentEvent, vcsSegmentEventProperties } from '../analytics';

Expand Down Expand Up @@ -324,7 +324,7 @@ export const cloneGitRepoAction: ActionFunction = async ({
vcsSegmentEventProperties('git', 'clone')
);
repoSettingsPatch.needsFullClone = true;
repoSettingsPatch.uri = translateSSHtoHTTP(repoSettingsPatch.uri || '');
repoSettingsPatch.uri = fromUrl(repoSettingsPatch.uri)?.https() || '';
let fsClient = MemClient.createClient();

const providerName = getOauth2FormatName(repoSettingsPatch.credentials);
Expand Down