2022-01-09 20:51:50 +01:00
|
|
|
import crypto from 'crypto';
|
2017-12-02 11:19:08 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2022-01-09 20:51:50 +01:00
|
|
|
|
2023-01-28 14:39:37 +01:00
|
|
|
import { createTarballHash } from '@verdaccio/utils';
|
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
import { HTTP_STATUS } from '../../../src/lib/constants';
|
2022-01-09 20:51:50 +01:00
|
|
|
import { TARBALL } from '../config.functional';
|
2019-07-16 08:40:01 +02:00
|
|
|
import requirePackage from '../fixtures/package';
|
2022-01-09 20:51:50 +01:00
|
|
|
import { readFile } from '../lib/test.utils';
|
2017-08-06 21:54:15 +02:00
|
|
|
|
|
|
|
function getBinary() {
|
2017-12-02 11:19:08 +01:00
|
|
|
return readFile('../fixtures/binary');
|
2017-08-06 21:54:15 +02:00
|
|
|
}
|
|
|
|
|
2018-06-19 22:02:29 +02:00
|
|
|
const STORAGE = '../store/test-storage3';
|
2017-07-02 00:05:58 +02:00
|
|
|
const PKG_GH131 = 'pkg-gh131';
|
|
|
|
const PKG_GH1312 = 'pkg-gh1312';
|
|
|
|
|
|
|
|
function isCached(pkgName, tarballName) {
|
2019-07-16 08:40:01 +02:00
|
|
|
const pathCached = path.join(__dirname, STORAGE, pkgName, tarballName);
|
|
|
|
|
|
|
|
return fs.existsSync(pathCached);
|
2017-07-02 00:05:58 +02:00
|
|
|
}
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
export default function (server, server2, server3) {
|
|
|
|
describe('storage tarball cache test', () => {
|
2019-12-23 09:29:27 +01:00
|
|
|
// more info #131
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.addPackage(PKG_GH131);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2023-01-18 22:49:28 +01:00
|
|
|
return server
|
|
|
|
.putTarball(PKG_GH131, TARBALL, getBinary())
|
|
|
|
.status(HTTP_STATUS.CREATED)
|
|
|
|
.body_ok(/.*/);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2019-07-16 08:40:01 +02:00
|
|
|
const pkg = requirePackage(PKG_GH131);
|
2018-10-03 22:39:45 +01:00
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
|
2017-07-02 00:05:58 +02:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
return server
|
|
|
|
.putVersion(PKG_GH131, '0.0.1', pkg)
|
2018-06-19 22:02:29 +02:00
|
|
|
.status(HTTP_STATUS.CREATED)
|
2017-07-02 00:05:58 +02:00
|
|
|
.body_ok(/published/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2018-06-19 22:02:29 +02:00
|
|
|
return server3.getPackage(PKG_GH131).status(HTTP_STATUS.OK);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server3.getTarball(PKG_GH131, TARBALL).status(HTTP_STATUS.OK);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('should be caching packages from uplink server1', () => {
|
2018-10-03 22:39:45 +01:00
|
|
|
expect(isCached(PKG_GH131, TARBALL)).toEqual(true);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server2.addPackage(PKG_GH1312);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2023-01-18 22:49:28 +01:00
|
|
|
return server2
|
|
|
|
.putTarball(PKG_GH1312, TARBALL, getBinary())
|
|
|
|
.status(HTTP_STATUS.CREATED)
|
|
|
|
.body_ok(/.*/);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2019-07-16 08:40:01 +02:00
|
|
|
const pkg = requirePackage(PKG_GH1312);
|
2018-08-21 08:05:34 +02:00
|
|
|
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
|
2017-07-02 00:05:58 +02:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
return server2
|
|
|
|
.putVersion(PKG_GH1312, '0.0.1', pkg)
|
2018-06-19 22:02:29 +02:00
|
|
|
.status(HTTP_STATUS.CREATED)
|
2017-07-02 00:05:58 +02:00
|
|
|
.body_ok(/published/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server3.getPackage(PKG_GH1312).status(HTTP_STATUS.OK);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2021-03-14 08:42:46 +01:00
|
|
|
return server3.getTarball(PKG_GH1312, TARBALL).status(HTTP_STATUS.OK);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('must not be caching packages from uplink server2', () => {
|
2018-10-03 22:39:45 +01:00
|
|
|
expect(isCached(PKG_GH1312, TARBALL)).toEqual(false);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
});
|
2017-12-02 11:19:08 +01:00
|
|
|
}
|