Fix loading pack extensions without path and source fields (#8563)

This commit is contained in:
Nicola Krumschmidt
2021-10-05 17:28:29 +02:00
committed by GitHub
parent 79361e3d42
commit 887c97b8c2
2 changed files with 49 additions and 13 deletions

View File

@@ -1,16 +1,16 @@
import { validateExtensionManifest } from './validate-extension-manifest';
describe('', () => {
it('returns false when passed item with is no name or version', () => {
it('returns false when passed item has no name or version', () => {
expect(validateExtensionManifest({})).toBe(false);
});
it('returns false when passed item with is no EXTENSION_PKG_KEY', () => {
it('returns false when passed item has no EXTENSION_PKG_KEY', () => {
const mockExtension = { name: 'test', version: '0.1' };
expect(validateExtensionManifest(mockExtension)).toBe(false);
});
it('returns false when passed item with is no type, path, source, host, or hidden', () => {
it('returns false when passed item has no type', () => {
const mockExtension = { name: 'test', version: '0.1', 'directus:extension': {} };
expect(validateExtensionManifest(mockExtension)).toBe(false);
});
@@ -19,16 +19,43 @@ describe('', () => {
const mockExtension = {
name: 'test',
version: '0.1',
'directus:extension': { type: 'not_extension_type', path: './', source: 'test', host: 'localhost', hidden: true },
'directus:extension': { type: 'not_extension_type' },
};
expect(validateExtensionManifest(mockExtension)).toBe(false);
});
it('returns true when passed an valid ExtensionManifestRaw', () => {
it('returns false when passed item has a type other than pack and has no path, source, host, or hidden', () => {
const mockExtension = {
name: 'test',
version: '0.1',
'directus:extension': { type: 'pack', path: './', source: 'test', host: 'localhost', hidden: true },
'directus:extension': { type: 'interface' },
};
expect(validateExtensionManifest(mockExtension)).toBe(false);
});
it('returns false when passed item has a type of pack and has no host or hidden', () => {
const mockExtension = {
name: 'test',
version: '0.1',
'directus:extension': { type: 'pack' },
};
expect(validateExtensionManifest(mockExtension)).toBe(false);
});
it('returns true when passed a valid ExtensionManifestRaw with a type other than pack', () => {
const mockExtension = {
name: 'test',
version: '0.1',
'directus:extension': { type: 'interface', path: './', source: 'test', host: '^9.0.0', hidden: true },
};
expect(validateExtensionManifest(mockExtension)).toBe(true);
});
it('returns true when passed a valid ExtensionManifestRaw with a type of pack', () => {
const mockExtension = {
name: 'test',
version: '0.1',
'directus:extension': { type: 'pack', host: '^9.0.0', hidden: true },
};
expect(validateExtensionManifest(mockExtension)).toBe(true);
});

View File

@@ -15,13 +15,7 @@ export function validateExtensionManifest(
return false;
}
if (
extensionOptions.type === undefined ||
extensionOptions.path === undefined ||
extensionOptions.source === undefined ||
extensionOptions.host === undefined ||
extensionOptions.hidden === undefined
) {
if (extensionOptions.type === undefined) {
return false;
}
@@ -29,5 +23,20 @@ export function validateExtensionManifest(
return false;
}
if (extensionOptions.type !== 'pack') {
if (
extensionOptions.path === undefined ||
extensionOptions.source === undefined ||
extensionOptions.host === undefined ||
extensionOptions.hidden === undefined
) {
return false;
}
} else {
if (extensionOptions.host === undefined || extensionOptions.hidden === undefined) {
return false;
}
}
return true;
}