mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-03 23:09:17 -05:00
fix: abort the stream to prevent overwriting existing tarbal
This commit is contained in:
parent
1f5479c75a
commit
2e5a4096f4
2 changed files with 23 additions and 23 deletions
|
@ -426,6 +426,7 @@ class LocalStorage implements IStorage {
|
||||||
writeStream.on('error', (err) => {
|
writeStream.on('error', (err) => {
|
||||||
if (err.code === fileExist) {
|
if (err.code === fileExist) {
|
||||||
uploadStream.emit('error', ErrorCode.getConflict());
|
uploadStream.emit('error', ErrorCode.getConflict());
|
||||||
|
uploadStream.abort();
|
||||||
} else if (err.code === noSuchFile) {
|
} else if (err.code === noSuchFile) {
|
||||||
// check if package exists to throw an appropriate message
|
// check if package exists to throw an appropriate message
|
||||||
this.getPackageMetadata(name, function(_err, res) {
|
this.getPackageMetadata(name, function(_err, res) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {readFile} from '../../functional/lib/test.utils';
|
||||||
import {generatePackageTemplate} from '../../../src/lib/storage-utils';
|
import {generatePackageTemplate} from '../../../src/lib/storage-utils';
|
||||||
import {generateNewVersion} from '../../lib/utils-test';
|
import {generateNewVersion} from '../../lib/utils-test';
|
||||||
|
|
||||||
|
|
||||||
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
|
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
|
||||||
|
|
||||||
import type {Config, MergeTags} from '@verdaccio/types';
|
import type {Config, MergeTags} from '@verdaccio/types';
|
||||||
|
@ -339,17 +338,18 @@ describe('LocalStorage', () => {
|
||||||
test('should fails on add a duplicated new tarball ', (done) => {
|
test('should fails on add a duplicated new tarball ', (done) => {
|
||||||
const tarballData = JSON.parse(readMetadata('addTarball'));
|
const tarballData = JSON.parse(readMetadata('addTarball'));
|
||||||
const stream = storage.addTarball(pkgName, tarballName);
|
const stream = storage.addTarball(pkgName, tarballName);
|
||||||
|
let spy;
|
||||||
|
// $FlowFixMe
|
||||||
|
spy = jest.spyOn(stream && stream._readableState && stream._readableState.pipes, 'abort');
|
||||||
stream.on('error', (err) => {
|
stream.on('error', (err) => {
|
||||||
expect(err).not.toBeNull();
|
expect(err).not.toBeNull();
|
||||||
expect(err.statusCode).toEqual(HTTP_STATUS.CONFLICT);
|
expect(err.statusCode).toEqual(HTTP_STATUS.CONFLICT);
|
||||||
expect(err.message).toMatch(/this package is already present/);
|
expect(err.message).toMatch(/this package is already present/);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('success', function(){
|
stream.on('success', function(){
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.end(new Buffer(tarballData.data, 'base64'));
|
stream.end(new Buffer(tarballData.data, 'base64'));
|
||||||
stream.done();
|
stream.done();
|
||||||
});
|
});
|
||||||
|
@ -397,6 +397,7 @@ describe('LocalStorage', () => {
|
||||||
stream.done();
|
stream.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
describe('LocalStorage::removeTarball', () => {
|
describe('LocalStorage::removeTarball', () => {
|
||||||
|
|
||||||
test('should remove a tarball', (done) => {
|
test('should remove a tarball', (done) => {
|
||||||
|
@ -417,8 +418,6 @@ describe('LocalStorage', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('LocalStorage::getTarball', () => {
|
describe('LocalStorage::getTarball', () => {
|
||||||
test('should get a existing tarball', (done) => {
|
test('should get a existing tarball', (done) => {
|
||||||
const stream = storage.getTarball(pkgName, tarballName);
|
const stream = storage.getTarball(pkgName, tarballName);
|
||||||
|
|
Loading…
Add table
Reference in a new issue