mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix loading pack extensions without path and source fields (#8563)
This commit is contained in:
committed by
GitHub
parent
79361e3d42
commit
887c97b8c2
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user