feat: throw if given a search url on awsS3, awsCodeCommit, fetch, gerrit, gitea and harness url readers
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
This commit is contained in:
@@ -651,5 +651,13 @@ describe('AwsCodeCommitUrlReader', () => {
|
||||
'site_name: Test\n',
|
||||
);
|
||||
});
|
||||
|
||||
it('throws if given URL with wildcard', async () => {
|
||||
await expect(
|
||||
reader.search(
|
||||
'https://eu-west-1.console.aws.amazon.com/codesuite/codecommit/repositories/my-repo/browse/--/catalog-*.yaml',
|
||||
),
|
||||
).rejects.toThrow('Unsupported search pattern URL');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -389,6 +389,12 @@ export class AwsCodeCommitUrlReader implements UrlReaderService {
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { path } = parseUrl(url, true);
|
||||
|
||||
if (path.match(/[*?]/)) {
|
||||
throw new Error('Unsupported search pattern URL');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
|
||||
@@ -572,5 +572,13 @@ describe('AwsS3UrlReader', () => {
|
||||
'site_name: Test\n',
|
||||
);
|
||||
});
|
||||
|
||||
it('throws if given URL with wildcard', async () => {
|
||||
await expect(
|
||||
reader.search(
|
||||
'https://test-bucket.s3.us-east-2.amazonaws.com/awsS3-mock-*.yaml',
|
||||
),
|
||||
).rejects.toThrow('Unsupported search pattern URL');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -366,6 +366,12 @@ export class AwsS3UrlReader implements UrlReaderService {
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { path } = parseUrl(url, this.integration.config);
|
||||
|
||||
if (path.match(/[*?]/)) {
|
||||
throw new Error('Unsupported search pattern URL');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
|
||||
@@ -287,5 +287,13 @@ describe('FetchUrlReader', () => {
|
||||
expect(data.etag).toBe('');
|
||||
expect(data.files.length).toBe(0);
|
||||
});
|
||||
|
||||
it('throws if given URL with wildcard', async () => {
|
||||
await expect(
|
||||
fetchUrlReader.search(`https://backstage.io/some-resource*`, {
|
||||
etag: 'etag',
|
||||
}),
|
||||
).rejects.toThrow('Unsupported search pattern URL');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -171,6 +171,12 @@ export class FetchUrlReader implements UrlReaderService {
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { pathname } = new URL(url);
|
||||
|
||||
if (pathname.match(/[*?]/)) {
|
||||
throw new Error('Unsupported search pattern URL');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
|
||||
@@ -466,5 +466,13 @@ describe.skip('GerritUrlReader', () => {
|
||||
expect(data.etag).toBe('');
|
||||
expect(data.files.length).toBe(0);
|
||||
});
|
||||
|
||||
it('throws if given URL with wildcard', async () => {
|
||||
await expect(
|
||||
gerritProcessor.search(
|
||||
'https://gerrit.com/web/project/+/refs/heads/master/*.yaml',
|
||||
),
|
||||
).rejects.toThrow('Unsuppported search pattern URL');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -150,6 +150,12 @@ export class GerritUrlReader implements UrlReaderService {
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { pathname } = new URL(url);
|
||||
|
||||
if (pathname.match(/[*?]/)) {
|
||||
throw new Error('Unsupported search pattern URL');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
|
||||
@@ -387,5 +387,13 @@ describe('GiteaUrlReader', () => {
|
||||
expect(data.etag).toBe('');
|
||||
expect(data.files.length).toBe(0);
|
||||
});
|
||||
|
||||
it('throws if given URL with wildcard', async () => {
|
||||
await expect(
|
||||
giteaProcessor.search(
|
||||
'https://gitea.com/owner/project/src/branch/branch2/*.yaml',
|
||||
),
|
||||
).rejects.toThrow('Unsupported search pattern URL');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
} from '@backstage/errors';
|
||||
import { Readable } from 'stream';
|
||||
import { parseLastModified } from './util';
|
||||
import parseGitUrl from 'git-url-parse';
|
||||
|
||||
/**
|
||||
* Implements a {@link @backstage/backend-plugin-api#UrlReaderService} for the Gitea v1 api.
|
||||
@@ -161,6 +162,12 @@ export class GiteaUrlReader implements UrlReaderService {
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { filepath } = parseGitUrl(url);
|
||||
|
||||
if (filepath.match(/[*?]/)) {
|
||||
throw new Error('Unsupported search pattern URL');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
|
||||
@@ -280,5 +280,13 @@ describe('HarnessUrlReader', () => {
|
||||
expect(data.etag).toBe('');
|
||||
expect(data.files.length).toBe(0);
|
||||
});
|
||||
|
||||
it('throws if given URL with wildcard', async () => {
|
||||
await expect(
|
||||
harnessProcessor.search(
|
||||
'https://app.harness.io/ng/account/accountId/module/code/orgs/orgName/projects/projName/repos/repoName/files/refMain/~/*.yaml',
|
||||
),
|
||||
).rejects.toThrow('Unsupported search pattern URL');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -160,6 +160,12 @@ export class HarnessUrlReader implements UrlReaderService {
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { path } = parseHarnessUrl(this.integration.config, url);
|
||||
|
||||
if (path.match(/[*?]/)) {
|
||||
throw new Error('Unsupported search pattern URL');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user