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

Extend the ssh url pattern check #1268

Merged
merged 1 commit into from
Dec 2, 2024
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 @@ -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
Loading