Skip to content

Commit

Permalink
Extend the ssh url check with the ssh://[<user>@]<host>[:<port>]/~<us…
Browse files Browse the repository at this point in the history
…er>/<path-to-git-repo> format
  • Loading branch information
vinokurig committed Nov 28, 2024
1 parent 930cd8a commit 22c8a44
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,32 @@ describe('Creating steps, fetching a devfile', () => {
const host = 'che-host';
const protocol = 'http://';
const factoryUrl = 'git@github.com:user/repository-name.git';
const emptyStore = new MockStoreBuilder().build();
const sshPrivateRepoAllertItem = expect.objectContaining({
title: 'Warning',
variant: AlertVariant.warning,
children: (
<ExpandableWarning
textBefore="Devfile resolve from a privatre repositry via an SSH url is not supported."
errorMessage="Could not reach devfile"
textAfter="Apply a Personal Access Token to fetch the devfile.yaml content."
/>
),
actionCallbacks: [
expect.objectContaining({
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Reload',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Open Documentation page',
callback: expect.any(Function),
}),
],
});

let spyWindowLocation: jest.SpyInstance;
let location: Location;
Expand Down Expand Up @@ -746,43 +772,31 @@ describe('Creating steps, fetching a devfile', () => {
});

it('should show warning on SSH url', async () => {
const expectAlertItem = expect.objectContaining({
title: 'Warning',
variant: AlertVariant.warning,
children: (
<ExpandableWarning
textBefore="Devfile resolve from a privatre repositry via an SSH url is not supported."
errorMessage="Could not reach devfile"
textAfter="Apply a Personal Access Token to fetch the devfile.yaml content."
/>
),
actionCallbacks: [
expect.objectContaining({
title: 'Continue with default devfile',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Reload',
callback: expect.any(Function),
}),
expect.objectContaining({
title: 'Open Documentation page',
callback: expect.any(Function),
}),
],
});
searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'git@github.com:user/repository.git',
});
const emptyStore = new MockStoreBuilder().build();

renderComponent(emptyStore, searchParams, location);

await jest.advanceTimersByTimeAsync(MIN_STEP_DURATION_MS);
await waitFor(() => expect(mockOnNextStep).not.toHaveBeenCalled);

expect(mockOpenOAuthPage).not.toHaveBeenCalled();
expect(mockOnError).toHaveBeenCalledWith(sshPrivateRepoAllertItem);
});

it('should show warning on bitbucket-server SSH url', async () => {
searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'ssh://git@bitbucket-server.com/~user/repository.git',
});

renderComponent(emptyStore, searchParams, location);

await jest.advanceTimersByTimeAsync(MIN_STEP_DURATION_MS);
await waitFor(() => expect(mockOnNextStep).not.toHaveBeenCalled);

expect(mockOpenOAuthPage).not.toHaveBeenCalled();
expect(mockOnError).toHaveBeenCalledWith(expectAlertItem);
expect(mockOnError).toHaveBeenCalledWith(sshPrivateRepoAllertItem);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type State = ProgressStepState & {

class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
protected readonly name = 'Inspecting repo';
private readonly sshPattern = new RegExp('(git@|(ssh|git)://).*');

constructor(props: Props) {
super(props);
Expand Down Expand Up @@ -232,7 +233,8 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
errorMessage === 'Failed to fetch devfile' ||
errorMessage.startsWith('Could not reach devfile')
) {
if (sourceUrl.startsWith('git@')) {
// check if the source url is an SSH url
if (this.sshPattern.test(sourceUrl)) {
throw new SSHPrivateRepositoryUrlError(errorMessage);
} else {
throw new UnsupportedGitProviderError(errorMessage);
Expand Down

0 comments on commit 22c8a44

Please sign in to comment.