mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
makes filter property of zip options optional, also adds strip directory tests
This commit is contained in:
parent
c226848467
commit
8bfb2aeb2b
3 changed files with 70 additions and 4 deletions
BIN
src/cli_plugin/install/__tests__/replies/strip_test.zip
Normal file
BIN
src/cli_plugin/install/__tests__/replies/strip_test.zip
Normal file
Binary file not shown.
|
@ -80,6 +80,68 @@ describe('kibana cli', function () {
|
|||
|
||||
describe('extractFiles', function () {
|
||||
|
||||
describe('strip files parameter', function () {
|
||||
|
||||
it('strips specified number of directories', function () {
|
||||
|
||||
return copyReplyFile('strip_test.zip')
|
||||
.then(() => {
|
||||
return extractFiles(settings.tempArchiveFile, settings.workingPath, 1);
|
||||
})
|
||||
.then(() => {
|
||||
const files = glob.sync('**/*', { cwd: testWorkingPath });
|
||||
const expected = [
|
||||
'1 level deep.txt',
|
||||
'test-plugin',
|
||||
'test-plugin/2 levels deep.txt',
|
||||
'test-plugin/public',
|
||||
'test-plugin/public/3 levels deep.txt',
|
||||
'archive.part'
|
||||
];
|
||||
expect(files.sort()).to.eql(expected.sort());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('throws an exception if it tries to strip too many directories', function () {
|
||||
|
||||
return copyReplyFile('strip_test.zip')
|
||||
.then(() => {
|
||||
return extractFiles(settings.tempArchiveFile, settings.workingPath, 2);
|
||||
})
|
||||
.then(shouldReject, (err) => {
|
||||
expect(err.message).to.match(/You cannot strip more levels than there are directories/i);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('applies the filter before applying the strip directories logic', function () {
|
||||
|
||||
return copyReplyFile('strip_test.zip')
|
||||
.then(() => {
|
||||
const filter = {
|
||||
paths: [
|
||||
'test-plugin'
|
||||
]
|
||||
};
|
||||
|
||||
return extractFiles(settings.tempArchiveFile, settings.workingPath, 2, filter);
|
||||
})
|
||||
.then(() => {
|
||||
const files = glob.sync('**/*', { cwd: testWorkingPath });
|
||||
const expected = [
|
||||
'2 levels deep.txt',
|
||||
'public',
|
||||
'public/3 levels deep.txt',
|
||||
'archive.part'
|
||||
];
|
||||
expect(files.sort()).to.eql(expected.sort());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('extracts files using the files filter', function () {
|
||||
return copyReplyFile('test_plugin_many.zip')
|
||||
.then(() => {
|
||||
|
|
|
@ -63,11 +63,15 @@ export async function extractFiles(zipPath, targetPath, strip, filter) {
|
|||
|
||||
unzipper.on('error', reject);
|
||||
|
||||
unzipper.extract({
|
||||
const options = {
|
||||
path: targetPath,
|
||||
strip: strip,
|
||||
filter: extractFilter(filter)
|
||||
});
|
||||
strip: strip
|
||||
};
|
||||
if (filter) {
|
||||
options.filter = extractFilter(filter);
|
||||
}
|
||||
|
||||
unzipper.extract(options);
|
||||
|
||||
unzipper.on('extract', resolve);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue