diff --git a/src/cli_plugin/install/__tests__/kibana.js b/src/cli_plugin/install/__tests__/kibana.js index e3c860f82a22b..15d6b25d27410 100644 --- a/src/cli_plugin/install/__tests__/kibana.js +++ b/src/cli_plugin/install/__tests__/kibana.js @@ -45,7 +45,7 @@ describe('kibana cli', function () { tempArchiveFile: tempArchiveFilePath, plugin: 'test-plugin', version: '5.0.0-SNAPSHOT', - plugins: [ { name: 'foo', path: join(testWorkingPath, 'foo'), version: '5.0.0-SNAPSHOT' } ] + plugins: [ { name: 'foo', path: join(testWorkingPath, 'foo'), kibanaVersion: '5.0.0-SNAPSHOT' } ] }; const errorStub = sinon.stub(); @@ -59,7 +59,7 @@ describe('kibana cli', function () { expect(errorStub.called).to.be(false); }); - it('should throw an error if plugin does contain a version.', function () { + it('should throw an error if plugin is missing a kibana version.', function () { const errorStub = sinon.stub(); try { @@ -69,12 +69,12 @@ describe('kibana cli', function () { errorStub(err); } - expect(errorStub.firstCall.args[0]).to.match(/plugin version not found/i); + expect(errorStub.firstCall.args[0]).to.match(/plugin package\.json is missing both a version property/i); }); - it('should throw an error if plugin version does does not match kibana version', function () { + it('should throw an error if plugin kibanaVersion does not match kibana version', function () { const errorStub = sinon.stub(); - settings.plugins[0].version = '1.2.3.4'; + settings.plugins[0].kibanaVersion = '1.2.3.4'; try { assertVersion(settings); @@ -83,12 +83,12 @@ describe('kibana cli', function () { errorStub(err); } - expect(errorStub.firstCall.args[0]).to.match(/incorrect version/i); + expect(errorStub.firstCall.args[0]).to.match(/incorrect kibana version/i); }); - it('should not throw an error if plugin version matches kibana version', function () { + it('should not throw an error if plugin kibanaVersion matches kibana version', function () { const errorStub = sinon.stub(); - settings.plugins[0].version = '1.0.0'; + settings.plugins[0].kibanaVersion = '1.0.0'; try { assertVersion(settings); @@ -102,7 +102,7 @@ describe('kibana cli', function () { it('should ignore version info after the dash in checks on valid version', function () { const errorStub = sinon.stub(); - settings.plugins[0].version = '1.0.0-foo-bar-version-1.2.3'; + settings.plugins[0].kibanaVersion = '1.0.0-foo-bar-version-1.2.3'; try { assertVersion(settings); @@ -116,7 +116,7 @@ describe('kibana cli', function () { it('should ignore version info after the dash in checks on invalid version', function () { const errorStub = sinon.stub(); - settings.plugins[0].version = '2.0.0-foo-bar-version-1.2.3'; + settings.plugins[0].kibanaVersion = '2.0.0-foo-bar-version-1.2.3'; try { assertVersion(settings); @@ -125,7 +125,7 @@ describe('kibana cli', function () { errorStub(err); } - expect(errorStub.firstCall.args[0]).to.match(/incorrect version/i); + expect(errorStub.firstCall.args[0]).to.match(/incorrect kibana version/i); }); }); diff --git a/src/cli_plugin/install/__tests__/pack.js b/src/cli_plugin/install/__tests__/pack.js index 433df5bc0a0db..39a61e58a93d6 100644 --- a/src/cli_plugin/install/__tests__/pack.js +++ b/src/cli_plugin/install/__tests__/pack.js @@ -12,30 +12,41 @@ describe('kibana cli', function () { describe('pack', function () { - const testWorkingPath = join(__dirname, '.test.data'); - const tempArchiveFilePath = join(testWorkingPath, 'archive.part'); - const testPluginPath = join(testWorkingPath, '.installedPlugins'); + let testNum = 0; + const workingPathRoot = join(__dirname, '.test.data'); + let testWorkingPath; + let tempArchiveFilePath; + let testPluginPath; let logger; - - const settings = { - workingPath: testWorkingPath, - tempArchiveFile: tempArchiveFilePath, - pluginDir: testPluginPath, - plugin: 'test-plugin' - }; + let settings; beforeEach(function () { + //These tests are dependent on the file system, and I had some inconsistent + //behavior with rimraf.sync show up. Until these tests are re-written to not + //depend on the file system, I make sure that each test uses a different + //working directory. + testNum += 1; + testWorkingPath = join(workingPathRoot, testNum + ''); + tempArchiveFilePath = join(testWorkingPath, 'archive.part'); + testPluginPath = join(testWorkingPath, '.installedPlugins'); + + settings = { + workingPath: testWorkingPath, + tempArchiveFile: tempArchiveFilePath, + pluginDir: testPluginPath, + plugin: 'test-plugin' + }; + logger = new Logger(settings); sinon.stub(logger, 'log'); sinon.stub(logger, 'error'); - rimraf.sync(testWorkingPath); mkdirp.sync(testWorkingPath); }); afterEach(function () { logger.log.restore(); logger.error.restore(); - rimraf.sync(testWorkingPath); + rimraf.sync(workingPathRoot); }); function copyReplyFile(filename) { @@ -89,10 +100,33 @@ describe('kibana cli', function () { expect(settings.plugins[0].name).to.be('test-plugin'); expect(settings.plugins[0].folder).to.be('test-plugin'); expect(settings.plugins[0].version).to.be('1.0.0'); + expect(settings.plugins[0].kibanaVersion).to.be('1.0.0'); expect(settings.plugins[0].platform).to.be(undefined); }); }); + it('populate settings.plugin.kibanaVersion', function () { + //kibana.version is defined in this package.json and is different than plugin version + return copyReplyFile('test_plugin_different_version.zip') + .then(() => { + return getPackData(settings, logger); + }) + .then(() => { + expect(settings.plugins[0].kibanaVersion).to.be('5.0.1'); + }); + }); + + it('populate settings.plugin.kibanaVersion (default to plugin version)', function () { + //kibana.version is not defined in this package.json, defaults to plugin version + return copyReplyFile('test_plugin.zip') + .then(() => { + return getPackData(settings, logger); + }) + .then(() => { + expect(settings.plugins[0].kibanaVersion).to.be('1.0.0'); + }); + }); + it('populate settings.plugins with multiple plugins', function () { return copyReplyFile('test_plugin_many.zip') .then(() => { diff --git a/src/cli_plugin/install/__tests__/replies/test_plugin_different_version.zip b/src/cli_plugin/install/__tests__/replies/test_plugin_different_version.zip new file mode 100644 index 0000000000000..12baa165fdb56 Binary files /dev/null and b/src/cli_plugin/install/__tests__/replies/test_plugin_different_version.zip differ diff --git a/src/cli_plugin/install/kibana.js b/src/cli_plugin/install/kibana.js index 065808f658eaa..86992fadf7a10 100644 --- a/src/cli_plugin/install/kibana.js +++ b/src/cli_plugin/install/kibana.js @@ -46,14 +46,14 @@ export async function rebuildCache(settings, logger) { } export function assertVersion(settings) { - if (!settings.plugins[0].version) { - throw new Error (`Plugin version not found. Check package.json in archive`); + if (!settings.plugins[0].kibanaVersion) { + throw new Error (`Plugin package.json is missing both a version property (required) and a kibana.version property (optional).`); } - const actual = cleanVersion(settings.plugins[0].version); + const actual = cleanVersion(settings.plugins[0].kibanaVersion); const expected = cleanVersion(settings.version); if (!versionSatisfies(actual, expected)) { - throw new Error (`Incorrect version in plugin [${settings.plugins[0].name}]. ` + + throw new Error (`Incorrect Kibana version in plugin [${settings.plugins[0].name}]. ` + `Expected [${expected}]; found [${actual}]`); } } diff --git a/src/cli_plugin/install/pack.js b/src/cli_plugin/install/pack.js index 5df302d5a86ff..76056523a3121 100644 --- a/src/cli_plugin/install/pack.js +++ b/src/cli_plugin/install/pack.js @@ -55,10 +55,10 @@ function assertValidPackageName(plugin) { } } - /** * Examine each package.json file to determine the plugin name, - * version, and platform. Mutates the package objects in the packages array + * version, kibanaVersion, and platform. Mutates the package objects + * in the packages array * @param {object} settings - a plugin installer settings object * @param {array} packages - array of package objects from listPackages() */ @@ -71,6 +71,12 @@ async function mergePackageData(settings, packages) { pkg.name = _.get(packageInfo, 'name'); pkg.path = resolve(settings.pluginDir, pkg.name); + // Plugins must specify their version, and by default that version should match + // the version of kibana down to the patch level. If these two versions need + // to diverge, they can specify a kibana.version to indicate the version of + // kibana the plugin is intended to work with. + pkg.kibanaVersion = _.get(packageInfo, 'kibana.version', pkg.version); + const regExp = new RegExp(`${pkg.name}-(.+)`, 'i'); const matches = pkg.folder.match(regExp); pkg.platform = (matches) ? matches[1] : undefined;