[plugin cli] Add deprecation warning for file://

This commit is contained in:
Jonathan Budzenski 2017-02-14 13:49:19 -06:00
parent 6bb880165a
commit 051fcb1412
No known key found for this signature in database
GPG key ID: D28BF9418FA0F292
2 changed files with 32 additions and 5 deletions

View file

@ -6,7 +6,7 @@ import rimraf from 'rimraf';
import mkdirp from 'mkdirp';
import Logger from '../../lib/logger';
import { UnsupportedProtocolError } from '../../lib/errors';
import { download, _downloadSingle, _getFilePath } from '../download';
import { download, _downloadSingle, _getFilePath, _checkFilePathDeprecation } from '../download';
import { join } from 'path';
describe('kibana cli', function () {
@ -149,6 +149,21 @@ describe('kibana cli', function () {
});
describe('Windows file:// deprecation', function () {
it('should log a warning if a file:// path is used', function () {
const platform = Object.getOwnPropertyDescriptor(process, 'platform');
Object.defineProperty(process, 'platform', { value: 'win32' });
const logger = {
log: sinon.spy()
};
_checkFilePathDeprecation('file://foo/bar', logger);
_checkFilePathDeprecation('file:///foo/bar', logger);
expect(logger.log.callCount).to.be(1);
expect(logger.log.calledWith('Install paths with file:// are deprecated, use file:/// instead')).to.be(true);
Object.defineProperty(process, 'platform', platform);
});
});
describe('download', function () {
it('should loop through bad urls until it finds a good one.', function () {
const filePath = join(__dirname, 'replies/test_plugin.zip');

View file

@ -3,22 +3,34 @@ import downloadLocalFile from './downloaders/file';
import { UnsupportedProtocolError } from '../lib/errors';
import { parse } from 'url';
export function _getFilePath(filePath) {
function _isWindows() {
return /^win/.test(process.platform);
}
export function _getFilePath(filePath, sourceUrl) {
const decodedPath = decodeURI(filePath);
const isWindows = /^win/.test(process.platform);
const prefixedDrive = /^\/[a-zA-Z]:/.test(decodedPath);
if (isWindows && prefixedDrive) {
if (_isWindows() && prefixedDrive) {
return decodedPath.slice(1);
}
return decodedPath;
}
export function _checkFilePathDeprecation(sourceUrl, logger) {
const twoSlashes = /^file:\/\/(?!\/)/.test(sourceUrl);
if (_isWindows() && twoSlashes) {
logger.log('Install paths with file:// are deprecated, use file:/// instead');
}
}
export function _downloadSingle(settings, logger, sourceUrl) {
const urlInfo = parse(sourceUrl);
let downloadPromise;
if (/^file/.test(urlInfo.protocol)) {
downloadPromise = downloadLocalFile(logger, _getFilePath(urlInfo.path), settings.tempArchiveFile);
_checkFilePathDeprecation(sourceUrl, logger);
downloadPromise = downloadLocalFile(logger, _getFilePath(urlInfo.path, sourceUrl), settings.tempArchiveFile);
} else if (/^https?/.test(urlInfo.protocol)) {
downloadPromise = downloadHttpFile(logger, sourceUrl, settings.tempArchiveFile, settings.timeout);
} else {