catalog-backend: disallow non-url location registration

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-06-13 16:16:51 +02:00
parent 8539bf9273
commit 8838b13038
3 changed files with 22 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Disallow anything but `'url'` locations from being registered via the location service.
@@ -17,6 +17,7 @@
import { DefaultLocationService } from './DefaultLocationService';
import { CatalogProcessingOrchestrator } from '../processing/types';
import { LocationStore } from './types';
import { InputError } from '@backstage/errors';
describe('DefaultLocationServiceTest', () => {
const orchestrator: jest.Mocked<CatalogProcessingOrchestrator> = {
@@ -251,6 +252,18 @@ describe('DefaultLocationServiceTest', () => {
type: 'url',
});
});
it('should not allow locations of unknown types', async () => {
await expect(
locationService.createLocation(
{
type: 'unknown',
target: 'https://backstage.io/catalog-info.yaml',
},
false,
),
).rejects.toThrow(InputError);
});
});
describe('listLocations', () => {
@@ -27,6 +27,7 @@ import {
} from '../processing/types';
import { LocationInput, LocationService, LocationStore } from './types';
import { locationSpecToMetadataName } from '../util/conversion';
import { InputError } from '@backstage/errors';
export class DefaultLocationService implements LocationService {
constructor(
@@ -38,6 +39,9 @@ export class DefaultLocationService implements LocationService {
input: LocationInput,
dryRun: boolean,
): Promise<{ location: Location; entities: Entity[]; exists?: boolean }> {
if (input.type !== 'url') {
throw new InputError(`Registered locations must be of type 'url'`);
}
if (dryRun) {
return this.dryRunCreateLocation(input);
}