mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
|
|
||
|
import validateUntrustedManifest from './validateUntrustedManifest';
|
||
|
|
||
|
const originalManifests = {
|
||
|
'joplin-plugin.this.is.a.test': {
|
||
|
id: 'joplin-plugin.this.is.a.test',
|
||
|
_npm_package_name: 'joplin-plugin-this-is-a-test',
|
||
|
version: '0.0.1',
|
||
|
},
|
||
|
};
|
||
|
|
||
|
// Note: Most of the checks below have additional tests in other files.
|
||
|
// This test suite is primarily to ensure that the checks are present.
|
||
|
|
||
|
describe('validateUntrustedManifest', () => {
|
||
|
test('should only allow valid plugin IDs', () => {
|
||
|
const badManifest = {
|
||
|
id: 'bad',
|
||
|
_npm_package_name: 'joplin-plugin-test',
|
||
|
version: '1.2.34',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(badManifest, originalManifests),
|
||
|
).toThrow('ID cannot be shorter than');
|
||
|
|
||
|
|
||
|
const goodManifest = {
|
||
|
...badManifest,
|
||
|
id: 'this.plugin.has.a.better.id',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(goodManifest, originalManifests),
|
||
|
).not.toThrow();
|
||
|
});
|
||
|
|
||
|
test('should only allow valid plugin versions', () => {
|
||
|
const badManifest = {
|
||
|
id: 'joplin-plugin.this.is.a.test',
|
||
|
_npm_package_name: 'joplin-plugin-this-is-a-test',
|
||
|
version: 'bad!',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(badManifest, originalManifests),
|
||
|
).toThrow();
|
||
|
|
||
|
|
||
|
const goodManifest = {
|
||
|
...badManifest,
|
||
|
version: '0.0.2',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(goodManifest, originalManifests),
|
||
|
).not.toThrow();
|
||
|
});
|
||
|
|
||
|
test('should not allow plugin authors to mark their own plugins as recommended', () => {
|
||
|
const newManifest1 = {
|
||
|
id: 'joplin-plugin.this.is.another.test',
|
||
|
_recommended: true,
|
||
|
_npm_package_name: 'joplin-plugin-another-test',
|
||
|
version: '1.2.3',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(newManifest1, originalManifests),
|
||
|
).toThrow('mark itself as recommended');
|
||
|
|
||
|
// Should also throw for falsey values
|
||
|
const newManifest2 = {
|
||
|
id: 'joplin-plugin.yet.another.test',
|
||
|
_recommended: '',
|
||
|
_npm_package_name: 'another-test',
|
||
|
version: '1.2.3',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(newManifest2, originalManifests),
|
||
|
).toThrow('mark itself as recommended');
|
||
|
});
|
||
|
|
||
|
test('should not allow changing the NPM package for an existing plugin', () => {
|
||
|
const newManifest = {
|
||
|
id: 'joplin-plugin.this.is.a.test',
|
||
|
_npm_package_name: 'joplin-plugin-test',
|
||
|
version: '0.0.2',
|
||
|
};
|
||
|
|
||
|
expect(
|
||
|
() => validateUntrustedManifest(newManifest, originalManifests),
|
||
|
).toThrow();
|
||
|
});
|
||
|
});
|