2022-08-19 13:25:20 -05:00
|
|
|
import { pseudoRandomBytes } from 'crypto';
|
|
|
|
import fs from 'fs';
|
2022-07-29 13:51:45 -05:00
|
|
|
import MockDate from 'mockdate';
|
2021-12-12 12:00:19 -05:00
|
|
|
import nock from 'nock';
|
|
|
|
import * as httpMocks from 'node-mocks-http';
|
2022-08-19 13:25:20 -05:00
|
|
|
import os from 'os';
|
2022-07-29 13:51:45 -05:00
|
|
|
import path from 'path';
|
2021-12-12 12:00:19 -05:00
|
|
|
|
2022-08-19 13:25:20 -05:00
|
|
|
import { Config, getDefaultConfig } from '@verdaccio/config';
|
2022-09-30 17:14:20 -05:00
|
|
|
import {
|
|
|
|
API_ERROR,
|
|
|
|
API_MESSAGE,
|
|
|
|
DIST_TAGS,
|
|
|
|
HEADERS,
|
|
|
|
HEADER_TYPE,
|
|
|
|
errorUtils,
|
|
|
|
fileUtils,
|
|
|
|
} from '@verdaccio/core';
|
2021-12-12 12:00:19 -05:00
|
|
|
import { setup } from '@verdaccio/logger';
|
2022-07-29 13:51:45 -05:00
|
|
|
import {
|
|
|
|
addNewVersion,
|
2022-08-27 05:52:23 -05:00
|
|
|
generateLocalPackageMetadata,
|
2022-07-29 13:51:45 -05:00
|
|
|
generatePackageMetadata,
|
|
|
|
generateRemotePackageMetadata,
|
2022-09-18 14:47:23 -05:00
|
|
|
getDeprecatedPackageMetadata,
|
2022-07-29 13:51:45 -05:00
|
|
|
} from '@verdaccio/test-helper';
|
2024-06-13 05:06:01 -05:00
|
|
|
import {
|
|
|
|
AbbreviatedManifest,
|
|
|
|
Author,
|
|
|
|
ConfigYaml,
|
|
|
|
Manifest,
|
|
|
|
PackageUsers,
|
|
|
|
Version,
|
|
|
|
} from '@verdaccio/types';
|
2021-12-12 12:00:19 -05:00
|
|
|
|
|
|
|
import { Storage } from '../src';
|
2022-07-29 13:51:45 -05:00
|
|
|
import manifestFooRemoteNpmjs from './fixtures/manifests/foo-npmjs.json';
|
2022-08-19 13:25:20 -05:00
|
|
|
import { configExample } from './helpers';
|
|
|
|
|
2022-08-27 05:52:23 -05:00
|
|
|
function generateRandomStorage() {
|
2022-08-19 13:25:20 -05:00
|
|
|
const tempStorage = pseudoRandomBytes(5).toString('hex');
|
|
|
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), '/verdaccio-test'));
|
|
|
|
|
|
|
|
return path.join(tempRoot, tempStorage);
|
|
|
|
}
|
2021-12-12 12:00:19 -05:00
|
|
|
|
2022-07-29 13:51:45 -05:00
|
|
|
setup({ type: 'stdout', format: 'pretty', level: 'trace' });
|
2021-12-12 12:00:19 -05:00
|
|
|
|
2022-08-27 05:52:23 -05:00
|
|
|
const domain = 'https://registry.npmjs.org';
|
2021-12-12 12:00:19 -05:00
|
|
|
const fakeHost = 'localhost:4873';
|
|
|
|
const fooManifest = generatePackageMetadata('foo', '1.0.0');
|
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
const getConfig = (file, override: Partial<ConfigYaml> = {}): Config => {
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
...override,
|
|
|
|
},
|
|
|
|
`./fixtures/config/${file}`,
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return config;
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultRequestOptions = {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
};
|
|
|
|
|
2022-09-30 17:14:20 -05:00
|
|
|
const executeStarPackage = async (
|
|
|
|
storage,
|
|
|
|
options: {
|
|
|
|
users: PackageUsers;
|
|
|
|
username: string;
|
|
|
|
name: string;
|
|
|
|
_rev: string;
|
|
|
|
_id?: string;
|
|
|
|
}
|
|
|
|
) => {
|
|
|
|
const { name, _rev, _id, users, username } = options;
|
|
|
|
const starManifest = {
|
|
|
|
_rev,
|
|
|
|
_id,
|
|
|
|
users,
|
|
|
|
};
|
|
|
|
return storage.updateManifest(starManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: { ...defaultRequestOptions, username },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-06-13 05:06:01 -05:00
|
|
|
const executeChangeOwners = async (
|
|
|
|
storage,
|
|
|
|
options: {
|
|
|
|
maintainers: Author[];
|
|
|
|
username: string;
|
|
|
|
name: string;
|
|
|
|
_rev: string;
|
|
|
|
_id?: string;
|
|
|
|
}
|
|
|
|
) => {
|
|
|
|
const { name, _rev, _id, maintainers, username } = options;
|
|
|
|
const ownerManifest = {
|
|
|
|
_rev,
|
|
|
|
_id,
|
|
|
|
maintainers,
|
|
|
|
};
|
|
|
|
return storage.updateManifest(ownerManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: { ...defaultRequestOptions, username },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-12-12 12:00:19 -05:00
|
|
|
describe('storage', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
nock.cleanAll();
|
|
|
|
nock.abortPendingRequests();
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
2022-07-29 13:51:45 -05:00
|
|
|
|
|
|
|
describe('updateManifest', () => {
|
2022-09-18 14:47:23 -05:00
|
|
|
describe('publishing', () => {
|
|
|
|
test('create private package', async () => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const requestOptions = {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
};
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
},
|
|
|
|
'./fixtures/config/updateManifest-1.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions,
|
|
|
|
});
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest.name).toEqual(pkgName);
|
|
|
|
expect(manifest._id).toEqual(pkgName);
|
|
|
|
expect(Object.keys(manifest.versions)).toEqual(['1.0.0']);
|
|
|
|
expect(manifest.time).toEqual({
|
|
|
|
'1.0.0': mockDate,
|
|
|
|
created: mockDate,
|
|
|
|
modified: mockDate,
|
|
|
|
});
|
|
|
|
expect(manifest[DIST_TAGS]).toEqual({ latest: '1.0.0' });
|
2024-02-12 07:50:58 -05:00
|
|
|
// verdaccio keeps latest version of readme on manifest level but not by version
|
|
|
|
expect(manifest.versions['1.0.0'].readme).not.toBeDefined();
|
2022-09-18 14:47:23 -05:00
|
|
|
expect(manifest.readme).toEqual('# test');
|
|
|
|
expect(manifest._attachments).toEqual({});
|
|
|
|
expect(typeof manifest._rev).toBeTruthy();
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
2022-09-18 14:47:23 -05:00
|
|
|
|
|
|
|
// TODO: Review triggerUncaughtException exception on abort
|
|
|
|
test.skip('abort creating a private package', async () => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
},
|
|
|
|
'./fixtures/config/updateManifest-1.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const ac = new AbortController();
|
|
|
|
setTimeout(() => {
|
|
|
|
ac.abort();
|
|
|
|
}, 10);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await expect(
|
|
|
|
storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: ac.signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
).rejects.toThrow('should throw here');
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
test('create private package with multiple consecutive versions', async () => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const settings = {
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
2022-09-18 14:47:23 -05:00
|
|
|
};
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
// const storage = generateRandomStorage();
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
storage: await fileUtils.createTempStorageFolder('storage-test'),
|
|
|
|
},
|
|
|
|
'./fixtures/config/updateManifest-1.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
// create a package
|
|
|
|
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest1, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
...settings,
|
|
|
|
});
|
|
|
|
// publish second version
|
|
|
|
const bodyNewManifest2 = generatePackageMetadata(pkgName, '1.0.1');
|
|
|
|
await storage.updateManifest(bodyNewManifest2, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
...settings,
|
|
|
|
});
|
|
|
|
// retrieve package metadata
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
},
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest.name).toEqual(pkgName);
|
|
|
|
expect(manifest._id).toEqual(pkgName);
|
|
|
|
expect(Object.keys(manifest.versions)).toEqual(['1.0.0', '1.0.1']);
|
|
|
|
expect(manifest.time).toEqual({
|
|
|
|
'1.0.0': mockDate,
|
|
|
|
'1.0.1': mockDate,
|
|
|
|
created: mockDate,
|
|
|
|
modified: mockDate,
|
|
|
|
});
|
|
|
|
expect(manifest[DIST_TAGS]).toEqual({ latest: '1.0.1' });
|
|
|
|
expect(manifest.readme).toEqual('# test');
|
|
|
|
expect(manifest._attachments).toEqual({});
|
|
|
|
expect(typeof manifest._rev).toBeTruthy();
|
|
|
|
// verify the version structure is correct
|
|
|
|
const manifestVersion = (await storage.getPackageByOptions({
|
2022-07-29 13:51:45 -05:00
|
|
|
name: pkgName,
|
2022-09-18 14:47:23 -05:00
|
|
|
version: '1.0.1',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
},
|
|
|
|
})) as Version;
|
|
|
|
expect(manifestVersion.name).toEqual(pkgName);
|
|
|
|
expect(manifestVersion.version).toEqual('1.0.1');
|
|
|
|
expect(manifestVersion._id).toEqual(`${pkgName}@1.0.1`);
|
|
|
|
expect(manifestVersion.description).toEqual('package generated');
|
|
|
|
expect(manifestVersion.dist).toEqual({
|
2024-05-28 17:11:42 -05:00
|
|
|
fileCount: 4,
|
2022-09-18 14:47:23 -05:00
|
|
|
integrity:
|
|
|
|
'sha512-6gHiERpiDgtb3hjqpQH5/i7zRmvYi9pmCjQf2ZMy3QEa9wVk9RgdZaPWUt7ZOnWUPFjcr9cmE6dUBf+XoPoH4g==',
|
|
|
|
shasum: '2c03764f651a9f016ca0b7620421457b619151b9',
|
|
|
|
tarball: 'http://localhost:5555/upstream/-/upstream-1.0.1.tgz',
|
2024-05-28 17:11:42 -05:00
|
|
|
unpackedSize: 543,
|
2022-09-18 14:47:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(manifestVersion.contributors).toEqual([]);
|
|
|
|
expect(manifestVersion.main).toEqual('index.js');
|
|
|
|
expect(manifestVersion.author).toEqual({ name: 'User NPM', email: 'user@domain.com' });
|
|
|
|
expect(manifestVersion.dependencies).toEqual({ verdaccio: '^2.7.2' });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('fails if version already exist', async () => {
|
|
|
|
const settings = {
|
2022-07-29 13:51:45 -05:00
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
},
|
2022-09-18 14:47:23 -05:00
|
|
|
};
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
},
|
2024-03-10 11:58:39 -05:00
|
|
|
'./fixtures/config/getTarball-getupstream.yaml',
|
2022-09-18 14:47:23 -05:00
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest1 = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
const bodyNewManifest2 = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest1, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
...settings,
|
|
|
|
});
|
|
|
|
await expect(
|
|
|
|
storage.updateManifest(bodyNewManifest2, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
...settings,
|
|
|
|
})
|
|
|
|
).rejects.toThrow(API_ERROR.PACKAGE_EXIST);
|
|
|
|
});
|
2024-02-12 07:50:58 -05:00
|
|
|
|
|
|
|
test('create private package with readme only in manifest', async () => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const requestOptions = {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
};
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
},
|
|
|
|
'./fixtures/config/updateManifest-1.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
|
|
|
|
// Remove readme from version to simulate behaviour of older package managers like npm6
|
|
|
|
bodyNewManifest.versions['1.0.0'].readme = '';
|
|
|
|
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions,
|
|
|
|
});
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
|
|
|
|
// verdaccio keeps latest version of readme on manifest level but not by version
|
|
|
|
expect(manifest.versions['1.0.0'].readme).not.toBeDefined();
|
|
|
|
expect(manifest.readme).toEqual('# test');
|
|
|
|
});
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
2022-09-18 14:47:23 -05:00
|
|
|
describe('deprecate', () => {
|
|
|
|
test.each([['foo'], ['@scope/foo']])('deprecate package %s', async (pkgName) => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest1.versions['1.0.0'].deprecated).toBeUndefined();
|
2022-07-29 13:51:45 -05:00
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
const deprecatedManifest = getDeprecatedPackageMetadata(
|
|
|
|
pkgName,
|
|
|
|
'1.0.0',
|
2022-07-29 13:51:45 -05:00
|
|
|
{
|
2022-09-18 14:47:23 -05:00
|
|
|
['latest']: '1.0.0',
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
2022-09-18 14:47:23 -05:00
|
|
|
'some deprecation message',
|
|
|
|
manifest1._rev
|
|
|
|
);
|
|
|
|
await storage.updateManifest(deprecatedManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest.name).toEqual(pkgName);
|
|
|
|
expect(manifest.versions['1.0.0'].deprecated).toEqual('some deprecation message');
|
|
|
|
// important revision is updated
|
|
|
|
expect(manifest._rev !== deprecatedManifest._rev).toBeTruthy();
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
2022-09-18 14:47:23 -05:00
|
|
|
test.each([['foo'], ['@scope/foo']])('undeprecate package %s', async (pkgName) => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
// publish new package
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
2022-07-29 13:51:45 -05:00
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
// verify not deprecated
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest1.versions['1.0.0'].deprecated).toBeUndefined();
|
2022-07-29 13:51:45 -05:00
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
// deprecate version
|
|
|
|
const deprecatedManifest = getDeprecatedPackageMetadata(
|
|
|
|
pkgName,
|
|
|
|
'1.0.0',
|
2022-07-29 13:51:45 -05:00
|
|
|
{
|
2022-09-18 14:47:23 -05:00
|
|
|
['latest']: '1.0.0',
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
2022-09-18 14:47:23 -05:00
|
|
|
'some deprecation message',
|
|
|
|
manifest1._rev
|
|
|
|
);
|
|
|
|
await storage.updateManifest(deprecatedManifest, {
|
2022-07-29 13:51:45 -05:00
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
2022-09-18 14:47:23 -05:00
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest.name).toEqual(pkgName);
|
|
|
|
expect(manifest.versions['1.0.0'].deprecated).toEqual('some deprecation message');
|
|
|
|
// important revision is updated
|
|
|
|
expect(manifest._rev !== deprecatedManifest._rev).toBeTruthy();
|
|
|
|
|
|
|
|
// un deprecated the previous deprecated
|
|
|
|
const undeprecatedManifest = {
|
|
|
|
...manifest,
|
|
|
|
};
|
|
|
|
undeprecatedManifest.versions['1.0.0'].deprecated = '';
|
|
|
|
await storage.updateManifest(undeprecatedManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
|
|
|
|
const manifest3 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest3.name).toEqual(pkgName);
|
|
|
|
expect(manifest3.versions['1.0.0'].deprecated).toBeUndefined();
|
|
|
|
// important revision is updated
|
|
|
|
expect(manifest3._rev !== deprecatedManifest._rev).toBeTruthy();
|
|
|
|
});
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
2022-09-30 17:14:20 -05:00
|
|
|
describe('star', () => {
|
|
|
|
test.each([['foo']])('star package %s', async (pkgName) => {
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const message = await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'fooUser',
|
|
|
|
users: { fooUser: true },
|
|
|
|
});
|
|
|
|
expect(message).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
|
|
|
|
expect(manifest1?.users).toEqual({
|
|
|
|
fooUser: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([['foo']])('should add multiple users to package %s', async (pkgName) => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const message = await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'fooUser',
|
|
|
|
users: { fooUser: true },
|
|
|
|
});
|
|
|
|
expect(message).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
|
|
|
|
await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'owner',
|
|
|
|
users: { owner: true },
|
|
|
|
});
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
|
|
|
|
expect(manifest1?.users).toEqual({
|
|
|
|
fooUser: true,
|
|
|
|
owner: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([['foo']])('should ignore duplicate users to package %s', async (pkgName) => {
|
|
|
|
const mockDate = '2018-01-14T11:17:40.712Z';
|
|
|
|
MockDate.set(mockDate);
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const message = await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'fooUser',
|
|
|
|
users: { fooUser: true },
|
|
|
|
});
|
|
|
|
expect(message).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
|
|
|
|
await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'fooUser',
|
|
|
|
users: { fooUser: true },
|
|
|
|
});
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
|
|
|
|
expect(manifest1?.users).toEqual({
|
|
|
|
fooUser: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([['foo']])('should unstar a package %s', async (pkgName) => {
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const message = await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'fooUser',
|
|
|
|
users: { fooUser: true },
|
|
|
|
});
|
|
|
|
expect(message).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
|
|
|
|
await executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: 'fooUser',
|
|
|
|
users: {},
|
|
|
|
});
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
|
|
|
|
expect(manifest1?.users).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([['foo']])('should handle missing username %s', async (pkgName) => {
|
|
|
|
const config = getConfig('deprecate.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
await expect(
|
|
|
|
executeStarPackage(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
// @ts-expect-error
|
|
|
|
username: undefined,
|
|
|
|
users: { fooUser: true },
|
|
|
|
})
|
|
|
|
).rejects.toThrow();
|
|
|
|
});
|
|
|
|
});
|
2024-06-13 05:06:01 -05:00
|
|
|
describe('owner', () => {
|
|
|
|
test.each([
|
|
|
|
['foo', 'publishWithOwnerDefault.yaml'],
|
|
|
|
['foo', 'publishWithOwnerAndCheck.yaml'],
|
|
|
|
])('new package %s, %s (anonymous)', async (pkgName, configFile) => {
|
|
|
|
const config = getConfig(configFile);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
});
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest?.maintainers).toEqual([{ name: 'Anonymous', email: '' }]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
['foo', 'publishWithOwnerDefault.yaml'],
|
|
|
|
['foo', 'publishWithOwnerAndCheck.yaml'],
|
|
|
|
])('new package %s, %s (logged in)', async (pkgName, configFile) => {
|
|
|
|
const config = getConfig(configFile);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const owner = { name: 'fooUser', email: '' };
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
const options = { ...defaultRequestOptions, username: owner.name };
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest?.maintainers).toEqual([owner]);
|
|
|
|
expect(manifest?.versions['1.0.0'].maintainers).toEqual([owner]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
['foo', 'publishWithOwnerDefault.yaml'],
|
|
|
|
['foo', 'publishWithOwnerAndCheck.yaml'],
|
|
|
|
])('add/remove owner %s, %s', async (pkgName, configFile) => {
|
|
|
|
const config = getConfig(configFile);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const firstOwner = { name: 'fooUser', email: '' };
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
const options = { ...defaultRequestOptions, username: firstOwner.name };
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
|
|
|
|
// add owner
|
|
|
|
const secondOwner = { name: 'barUser', email: '' };
|
|
|
|
const maintainers = [firstOwner, secondOwner];
|
|
|
|
|
|
|
|
const message = await executeChangeOwners(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: firstOwner.name,
|
|
|
|
maintainers: maintainers,
|
|
|
|
});
|
|
|
|
expect(message).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest?.maintainers).toEqual(maintainers);
|
|
|
|
// published version should not be affected
|
|
|
|
expect(manifest?.versions['1.0.0'].maintainers).toEqual([firstOwner]);
|
|
|
|
|
|
|
|
// remove owner
|
|
|
|
const maintainers2 = [secondOwner];
|
|
|
|
const message2 = await executeChangeOwners(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: firstOwner.name,
|
|
|
|
maintainers: maintainers2,
|
|
|
|
});
|
|
|
|
expect(message2).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
|
|
|
|
const manifest2 = (await storage.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
})) as Manifest;
|
|
|
|
expect(manifest2?.maintainers).toEqual(maintainers2);
|
|
|
|
// published version should not be affected
|
|
|
|
expect(manifest2?.versions['1.0.0'].maintainers).toEqual([firstOwner]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
['foo', 'publishWithOwnerDefault.yaml'],
|
|
|
|
['foo', 'publishWithOwnerAndCheck.yaml'],
|
|
|
|
])('should fail removing last owner %s, %s', async (pkgName, configFile) => {
|
|
|
|
const config = getConfig(configFile);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
const owner = 'fooUser';
|
|
|
|
const options = { ...defaultRequestOptions, username: owner };
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
|
|
|
|
// no owners
|
|
|
|
await expect(
|
|
|
|
executeChangeOwners(storage, {
|
|
|
|
_rev: bodyNewManifest._rev,
|
|
|
|
_id: bodyNewManifest._id,
|
|
|
|
name: pkgName,
|
|
|
|
username: owner,
|
|
|
|
maintainers: [],
|
|
|
|
})
|
|
|
|
).rejects.toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.each([['foo', 'publishWithOwnerDefault.yaml']])(
|
|
|
|
'ok to publish as non-owner without check %s, %s',
|
|
|
|
async (pkgName, configFile) => {
|
|
|
|
const config = getConfig(configFile);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
const owner = 'fooUser';
|
|
|
|
const options = { ...defaultRequestOptions, username: owner };
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
|
|
|
|
// try to publish as user who's not an owner
|
|
|
|
const bodyNewManifest2 = generatePackageMetadata(pkgName, '1.0.1');
|
|
|
|
const nonOwner = 'barUser';
|
|
|
|
const options2 = { ...defaultRequestOptions, username: nonOwner };
|
|
|
|
const message2 = await storage.updateManifest(bodyNewManifest2, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options2,
|
|
|
|
});
|
|
|
|
expect(message2).toEqual(API_MESSAGE.PKG_CHANGED);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
test.each([['foo', 'publishWithOwnerAndCheck.yaml']])(
|
|
|
|
'should fail publishing as non-owner with check %s, %s',
|
|
|
|
async (pkgName, configFile) => {
|
|
|
|
const config = getConfig(configFile);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
const owner = 'fooUser';
|
|
|
|
const options = { ...defaultRequestOptions, username: owner };
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
|
|
|
|
// try to publish as user who's not an owner
|
|
|
|
const bodyNewManifest2 = generatePackageMetadata(pkgName, '1.0.1');
|
|
|
|
const nonOwner = 'barUser';
|
|
|
|
const options2 = { ...defaultRequestOptions, username: nonOwner };
|
|
|
|
await expect(
|
|
|
|
storage.updateManifest(bodyNewManifest2, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options2,
|
|
|
|
})
|
|
|
|
).rejects.toThrow();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
describe('getTarball', () => {
|
2024-05-28 17:11:42 -05:00
|
|
|
test('should get a package from local storage', (done) => {
|
|
|
|
const pkgName = 'foo';
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
storage.init(config).then(() => {
|
|
|
|
const ac = new AbortController();
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
storage
|
|
|
|
.updateManifest(bodyNewManifest, {
|
|
|
|
signal: ac.signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: defaultRequestOptions,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const abort = new AbortController();
|
|
|
|
storage
|
|
|
|
.getTarball(pkgName, `${pkgName}-1.0.0.tgz`, {
|
|
|
|
signal: abort.signal,
|
|
|
|
})
|
|
|
|
.then((stream) => {
|
|
|
|
stream.on('data', (dat) => {
|
|
|
|
expect(dat).toBeDefined();
|
|
|
|
expect(dat.length).toEqual(512);
|
|
|
|
});
|
|
|
|
stream.on('end', () => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
stream.on('error', () => {
|
|
|
|
done('this should not happen');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-29 13:51:45 -05:00
|
|
|
test('should not found a package anywhere', (done) => {
|
2021-12-12 12:00:19 -05:00
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
2022-07-29 13:51:45 -05:00
|
|
|
storage.init(config).then(() => {
|
|
|
|
const abort = new AbortController();
|
|
|
|
storage
|
2024-03-10 11:58:39 -05:00
|
|
|
.getTarball('some-tarball', 'some-tarball-1.0.0.tgz', {
|
2022-07-29 13:51:45 -05:00
|
|
|
signal: abort.signal,
|
|
|
|
})
|
|
|
|
.then((stream) => {
|
|
|
|
stream.on('error', (err) => {
|
|
|
|
expect(err).toEqual(errorUtils.getNotFound(API_ERROR.NO_PACKAGE));
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should create a package if tarball is requested and does not exist locally', (done) => {
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const upstreamManifest = generateRemotePackageMetadata(
|
|
|
|
pkgName,
|
|
|
|
'1.0.0',
|
|
|
|
'https://registry.something.org'
|
|
|
|
);
|
|
|
|
nock('https://registry.verdaccio.org').get(`/${pkgName}`).reply(201, upstreamManifest);
|
|
|
|
nock('https://registry.something.org')
|
|
|
|
.get(`/${pkgName}/-/${pkgName}-1.0.0.tgz`)
|
|
|
|
// types does not match here with documentation
|
|
|
|
// @ts-expect-error
|
|
|
|
.replyWithFile(201, path.join(__dirname, 'fixtures/tarball.tgz'), {
|
|
|
|
[HEADER_TYPE.CONTENT_LENGTH]: 277,
|
|
|
|
});
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
2024-03-10 11:58:39 -05:00
|
|
|
'./fixtures/config/getTarball-getupstream.yaml',
|
2022-07-29 13:51:45 -05:00
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
storage.init(config).then(() => {
|
|
|
|
const abort = new AbortController();
|
|
|
|
storage
|
2024-03-10 11:58:39 -05:00
|
|
|
.getTarball(pkgName, `${pkgName}-1.0.0.tgz`, {
|
2022-07-29 13:51:45 -05:00
|
|
|
signal: abort.signal,
|
|
|
|
})
|
|
|
|
.then((stream) => {
|
|
|
|
stream.on('data', (dat) => {
|
|
|
|
expect(dat).toBeDefined();
|
|
|
|
});
|
|
|
|
stream.on('end', () => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
stream.on('error', () => {
|
|
|
|
done('this should not happen');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should serve fetch tarball from upstream without dist info local', (done) => {
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const upstreamManifest = addNewVersion(
|
2024-05-30 11:10:13 -05:00
|
|
|
generateRemotePackageMetadata(pkgName, '1.0.0') as Manifest,
|
2022-07-29 13:51:45 -05:00
|
|
|
'1.0.1'
|
|
|
|
);
|
|
|
|
nock('https://registry.verdaccio.org').get(`/${pkgName}`).reply(201, upstreamManifest);
|
|
|
|
nock('http://localhost:5555')
|
|
|
|
.get(`/${pkgName}/-/${pkgName}-1.0.1.tgz`)
|
|
|
|
// types does not match here with documentation
|
|
|
|
// @ts-expect-error
|
|
|
|
.replyWithFile(201, path.join(__dirname, 'fixtures/tarball.tgz'), {
|
|
|
|
[HEADER_TYPE.CONTENT_LENGTH]: 277,
|
|
|
|
});
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
2024-03-10 11:58:39 -05:00
|
|
|
'./fixtures/config/getTarball-getupstream.yaml',
|
2022-07-29 13:51:45 -05:00
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
storage.init(config).then(() => {
|
|
|
|
const ac = new AbortController();
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
storage
|
|
|
|
.updateManifest(bodyNewManifest, {
|
|
|
|
signal: ac.signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const abort = new AbortController();
|
|
|
|
storage
|
2024-03-10 11:58:39 -05:00
|
|
|
.getTarball(pkgName, `${pkgName}-1.0.1.tgz`, {
|
2022-07-29 13:51:45 -05:00
|
|
|
signal: abort.signal,
|
|
|
|
})
|
|
|
|
.then((stream) => {
|
|
|
|
stream.on('data', (dat) => {
|
|
|
|
expect(dat).toBeDefined();
|
|
|
|
});
|
|
|
|
stream.on('end', () => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
stream.on('error', () => {
|
|
|
|
done('this should not happen');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should serve fetch tarball from upstream without with info local', (done) => {
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const upstreamManifest = addNewVersion(
|
2024-05-30 11:10:13 -05:00
|
|
|
addNewVersion(generateRemotePackageMetadata(pkgName, '1.0.0') as Manifest, '1.0.1'),
|
2022-07-29 13:51:45 -05:00
|
|
|
'1.0.2'
|
|
|
|
);
|
|
|
|
nock('https://registry.verdaccio.org')
|
|
|
|
.get(`/${pkgName}`)
|
|
|
|
.times(10)
|
|
|
|
.reply(201, upstreamManifest);
|
|
|
|
nock('http://localhost:5555')
|
|
|
|
.get(`/${pkgName}/-/${pkgName}-1.0.0.tgz`)
|
|
|
|
// types does not match here with documentation
|
|
|
|
// @ts-expect-error
|
|
|
|
.replyWithFile(201, path.join(__dirname, 'fixtures/tarball.tgz'), {
|
|
|
|
[HEADER_TYPE.CONTENT_LENGTH]: 277,
|
|
|
|
});
|
2022-08-27 05:52:23 -05:00
|
|
|
const storagePath = generateRandomStorage();
|
2022-07-29 13:51:45 -05:00
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
storage: storagePath,
|
|
|
|
},
|
2024-03-10 11:58:39 -05:00
|
|
|
'./fixtures/config/getTarball-getupstream.yaml',
|
2022-07-29 13:51:45 -05:00
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
storage.init(config).then(() => {
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
return storage
|
|
|
|
.getPackageByOptions({
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
|
|
|
host: req.get('host') as string,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const abort = new AbortController();
|
|
|
|
storage
|
2024-03-10 11:58:39 -05:00
|
|
|
.getTarball(pkgName, `${pkgName}-1.0.0.tgz`, {
|
2022-07-29 13:51:45 -05:00
|
|
|
signal: abort.signal,
|
|
|
|
})
|
|
|
|
.then((stream) => {
|
|
|
|
stream.on('data', (dat) => {
|
|
|
|
expect(dat).toBeDefined();
|
|
|
|
});
|
|
|
|
stream.on('end', () => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
stream.once('error', () => {
|
|
|
|
done('this should not happen');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should serve local cache', (done) => {
|
|
|
|
const pkgName = 'upstream';
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
2024-03-10 11:58:39 -05:00
|
|
|
'./fixtures/config/getTarball-getupstream.yaml',
|
2022-07-29 13:51:45 -05:00
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
storage.init(config).then(() => {
|
|
|
|
const ac = new AbortController();
|
|
|
|
const bodyNewManifest = generatePackageMetadata(pkgName, '1.0.0');
|
|
|
|
storage
|
|
|
|
.updateManifest(bodyNewManifest, {
|
|
|
|
signal: ac.signal,
|
|
|
|
name: pkgName,
|
|
|
|
uplinksLook: true,
|
|
|
|
revision: '1',
|
|
|
|
requestOptions: {
|
|
|
|
host: 'localhost',
|
|
|
|
protocol: 'http',
|
|
|
|
headers: {},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const abort = new AbortController();
|
|
|
|
storage
|
2024-03-10 11:58:39 -05:00
|
|
|
.getTarball(pkgName, `${pkgName}-1.0.0.tgz`, {
|
2022-07-29 13:51:45 -05:00
|
|
|
signal: abort.signal,
|
|
|
|
})
|
|
|
|
.then((stream) => {
|
|
|
|
stream.on('data', (dat) => {
|
|
|
|
expect(dat).toBeDefined();
|
|
|
|
});
|
|
|
|
stream.on('end', () => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
stream.on('error', () => {
|
|
|
|
done('this should not happen');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
describe('syncUplinksMetadata()', () => {
|
2022-07-29 13:51:45 -05:00
|
|
|
describe('error handling', () => {
|
|
|
|
test('should handle double failure on uplinks with timeout', async () => {
|
|
|
|
const fooManifest = generatePackageMetadata('timeout', '8.0.0');
|
2024-02-11 10:57:04 -05:00
|
|
|
nock('https://registry.timeout.com')
|
2023-08-06 10:42:20 -05:00
|
|
|
.get(`/${fooManifest.name}`)
|
2024-02-11 10:57:04 -05:00
|
|
|
.delayConnection(8000)
|
2022-07-29 13:51:45 -05:00
|
|
|
.reply(201, manifestFooRemoteNpmjs);
|
|
|
|
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncDoubleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2024-03-10 11:58:39 -05:00
|
|
|
storage.syncUplinksMetadata(fooManifest.name, null, {
|
2024-02-11 10:57:04 -05:00
|
|
|
retry: { limit: 3 },
|
2022-07-29 13:51:45 -05:00
|
|
|
timeout: {
|
2023-08-06 10:42:20 -05:00
|
|
|
request: 1000,
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
})
|
2023-08-06 10:42:20 -05:00
|
|
|
).rejects.toThrow(API_ERROR.NO_PACKAGE);
|
2024-02-11 10:57:04 -05:00
|
|
|
}, 18000);
|
2022-07-29 13:51:45 -05:00
|
|
|
|
|
|
|
test('should handle one proxy fails', async () => {
|
|
|
|
const fooManifest = generatePackageMetadata('foo', '8.0.0');
|
|
|
|
nock('https://registry.verdaccio.org').get('/foo').replyWithError('service in holidays');
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncSingleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2024-03-10 11:58:39 -05:00
|
|
|
storage.syncUplinksMetadata(fooManifest.name, null, {
|
2022-07-29 13:51:45 -05:00
|
|
|
retry: { limit: 0 },
|
|
|
|
})
|
|
|
|
).rejects.toThrow(API_ERROR.NO_PACKAGE);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle one proxy reply 304', async () => {
|
|
|
|
const fooManifest = generatePackageMetadata('foo-no-data', '8.0.0');
|
|
|
|
nock('https://registry.verdaccio.org').get('/foo-no-data').reply(304);
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncSingleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
2024-03-10 11:58:39 -05:00
|
|
|
const [manifest] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest, {
|
2024-05-30 11:10:13 -05:00
|
|
|
retry: { limit: 0 },
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
|
|
|
expect(manifest).toBe(fooManifest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success scenarios', () => {
|
|
|
|
test('should handle one proxy success', async () => {
|
2022-08-27 05:52:23 -05:00
|
|
|
const fooManifest = generateLocalPackageMetadata('foo', '8.0.0');
|
2022-07-29 13:51:45 -05:00
|
|
|
nock('https://registry.verdaccio.org').get('/foo').reply(201, manifestFooRemoteNpmjs);
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncSingleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest);
|
2022-07-29 13:51:45 -05:00
|
|
|
expect(response).not.toBeNull();
|
|
|
|
expect((response as Manifest).name).toEqual(fooManifest.name);
|
2022-08-27 05:52:23 -05:00
|
|
|
expect(Object.keys((response as Manifest).versions)).toEqual([
|
|
|
|
'8.0.0',
|
|
|
|
'1.0.0',
|
|
|
|
'0.0.3',
|
|
|
|
'0.0.4',
|
|
|
|
'0.0.5',
|
|
|
|
'0.0.6',
|
|
|
|
'0.0.7',
|
|
|
|
]);
|
|
|
|
expect(Object.keys((response as Manifest).time)).toEqual([
|
|
|
|
'modified',
|
|
|
|
'created',
|
|
|
|
'8.0.0',
|
|
|
|
'1.0.0',
|
|
|
|
'0.0.3',
|
|
|
|
'0.0.4',
|
|
|
|
'0.0.5',
|
|
|
|
'0.0.6',
|
|
|
|
'0.0.7',
|
|
|
|
]);
|
2022-07-29 13:51:45 -05:00
|
|
|
expect((response as Manifest)[DIST_TAGS].latest).toEqual('8.0.0');
|
2022-08-27 05:52:23 -05:00
|
|
|
expect((response as Manifest).time['8.0.0']).toBeDefined();
|
2022-07-29 13:51:45 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle one proxy success with no local cache manifest', async () => {
|
|
|
|
nock('https://registry.verdaccio.org').get('/foo').reply(201, manifestFooRemoteNpmjs);
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncSingleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
const [response] = await storage.syncUplinksMetadata(fooManifest.name, null);
|
2022-07-29 13:51:45 -05:00
|
|
|
// the latest from the remote manifest
|
|
|
|
expect(response).not.toBeNull();
|
|
|
|
expect((response as Manifest).name).toEqual(fooManifest.name);
|
|
|
|
expect((response as Manifest)[DIST_TAGS].latest).toEqual('0.0.7');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle no proxy found with local cache manifest', async () => {
|
|
|
|
const fooManifest = generatePackageMetadata('foo', '8.0.0');
|
|
|
|
nock('https://registry.verdaccio.org').get('/foo').reply(201, manifestFooRemoteNpmjs);
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncNoUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest);
|
2022-07-29 13:51:45 -05:00
|
|
|
expect(response).not.toBeNull();
|
|
|
|
expect((response as Manifest).name).toEqual(fooManifest.name);
|
|
|
|
expect((response as Manifest)[DIST_TAGS].latest).toEqual('8.0.0');
|
|
|
|
});
|
|
|
|
test.todo('should handle double proxy with last one success');
|
|
|
|
});
|
2022-09-02 13:40:12 -05:00
|
|
|
|
2022-07-29 13:51:45 -05:00
|
|
|
describe('options', () => {
|
2022-09-02 13:40:12 -05:00
|
|
|
test('should handle disable uplinks via options.uplinksLook=false with cache', async () => {
|
2022-07-29 13:51:45 -05:00
|
|
|
const fooManifest = generatePackageMetadata('foo', '8.0.0');
|
|
|
|
nock('https://registry.verdaccio.org').get('/foo').reply(201, manifestFooRemoteNpmjs);
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2022-07-29 13:51:45 -05:00
|
|
|
},
|
|
|
|
'./fixtures/config/syncSingleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
const [response] = await storage.syncUplinksMetadata(fooManifest.name, fooManifest, {
|
2022-07-29 13:51:45 -05:00
|
|
|
uplinksLook: false,
|
|
|
|
});
|
2021-12-12 12:00:19 -05:00
|
|
|
|
2022-07-29 13:51:45 -05:00
|
|
|
expect((response as Manifest).name).toEqual(fooManifest.name);
|
|
|
|
expect((response as Manifest)[DIST_TAGS].latest).toEqual('8.0.0');
|
2021-12-12 12:00:19 -05:00
|
|
|
});
|
2022-09-02 13:40:12 -05:00
|
|
|
|
|
|
|
test('should handle disable uplinks via options.uplinksLook=false without cache', async () => {
|
|
|
|
const fooRemoteManifest = generateRemotePackageMetadata(
|
|
|
|
'foo',
|
|
|
|
'9.0.0',
|
|
|
|
'https://registry.verdaccio.org',
|
|
|
|
['9.0.0', '9.0.1', '9.0.2', '9.0.3']
|
|
|
|
);
|
|
|
|
nock('https://registry.verdaccio.org').get('/foo').reply(201, fooRemoteManifest);
|
|
|
|
const config = new Config(
|
|
|
|
configExample(
|
|
|
|
{
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
},
|
|
|
|
'./fixtures/config/syncSingleUplinksMetadata.yaml',
|
|
|
|
__dirname
|
|
|
|
)
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
const [response] = await storage.syncUplinksMetadata('foo', null, {
|
2022-09-02 13:40:12 -05:00
|
|
|
uplinksLook: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect((response as Manifest).name).toEqual('foo');
|
|
|
|
expect((response as Manifest)[DIST_TAGS].latest).toEqual('9.0.0');
|
|
|
|
});
|
2021-12-12 12:00:19 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
describe('getLocalDatabase', () => {
|
2024-03-10 11:58:39 -05:00
|
|
|
test('should return no results', async () => {
|
2022-08-27 05:52:23 -05:00
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
2022-10-21 16:05:18 -05:00
|
|
|
await expect(storage.getLocalDatabase()).resolves.toHaveLength(0);
|
2022-08-27 05:52:23 -05:00
|
|
|
});
|
|
|
|
|
2024-03-10 11:58:39 -05:00
|
|
|
test('should return single result', async () => {
|
2022-08-27 05:52:23 -05:00
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: 'host',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const manifest = generatePackageMetadata('foo');
|
|
|
|
const ac = new AbortController();
|
|
|
|
await storage.updateManifest(manifest, {
|
|
|
|
signal: ac.signal,
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
|
|
|
host: req.get('host') as string,
|
|
|
|
},
|
|
|
|
});
|
2022-10-21 16:05:18 -05:00
|
|
|
const response = await storage.getLocalDatabase();
|
2022-08-27 05:52:23 -05:00
|
|
|
expect(response).toHaveLength(1);
|
|
|
|
expect(response[0]).toEqual(expect.objectContaining({ name: 'foo', version: '1.0.0' }));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tokens', () => {
|
|
|
|
describe('saveToken', () => {
|
|
|
|
test('should retrieve tokens created', async () => {
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await storage.saveToken({
|
|
|
|
user: 'foo',
|
|
|
|
token: 'secret',
|
|
|
|
key: 'key',
|
|
|
|
created: 'created',
|
|
|
|
readonly: true,
|
|
|
|
});
|
|
|
|
const tokens = await storage.readTokens({ user: 'foo' });
|
|
|
|
expect(tokens).toEqual([
|
|
|
|
{ user: 'foo', token: 'secret', key: 'key', readonly: true, created: 'created' },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should delete a token created', async () => {
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await storage.saveToken({
|
|
|
|
user: 'foo',
|
|
|
|
token: 'secret',
|
|
|
|
key: 'key',
|
|
|
|
created: 'created',
|
|
|
|
readonly: true,
|
|
|
|
});
|
|
|
|
const tokens = await storage.readTokens({ user: 'foo' });
|
|
|
|
expect(tokens).toHaveLength(1);
|
|
|
|
await storage.deleteToken('foo', 'key');
|
|
|
|
const tokens2 = await storage.readTokens({ user: 'foo' });
|
|
|
|
expect(tokens2).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeTarball', () => {
|
|
|
|
test('should fail on remove tarball of package does not exist', async () => {
|
2024-06-13 05:06:01 -05:00
|
|
|
const username = 'foouser';
|
2022-08-27 05:52:23 -05:00
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
2024-06-13 05:06:01 -05:00
|
|
|
await expect(storage.removeTarball('foo', 'foo-1.0.0.tgz', 'rev', username)).rejects.toThrow(
|
2022-08-27 05:52:23 -05:00
|
|
|
API_ERROR.NO_PACKAGE
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removePackage', () => {
|
|
|
|
test('should remove entirely a package', async () => {
|
2024-06-13 05:06:01 -05:00
|
|
|
const username = 'foouser';
|
2022-08-27 05:52:23 -05:00
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
|
|
|
const manifest = generatePackageMetadata('foo');
|
|
|
|
const ac = new AbortController();
|
|
|
|
// 1. publish a package
|
|
|
|
await storage.updateManifest(manifest, {
|
|
|
|
signal: ac.signal,
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
|
|
|
host: req.get('host') as string,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// 2. request package (should be available in the local cache)
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
|
|
|
host: req.get('host') as string,
|
|
|
|
},
|
|
|
|
})) as Manifest;
|
|
|
|
const _rev = manifest1._rev;
|
|
|
|
// 3. remove the tarball
|
|
|
|
await expect(
|
2024-06-13 05:06:01 -05:00
|
|
|
storage.removeTarball(manifest1.name, 'foo-1.0.0.tgz', _rev, username)
|
2022-08-27 05:52:23 -05:00
|
|
|
).resolves.toBeDefined();
|
|
|
|
// 4. remove the package
|
2024-06-13 05:06:01 -05:00
|
|
|
await storage.removePackage(manifest1.name, _rev, username);
|
2022-08-27 05:52:23 -05:00
|
|
|
// 5. fails if package does not exist anymore in storage
|
|
|
|
await expect(
|
|
|
|
storage.getPackageByOptions({
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
|
|
|
host: req.get('host') as string,
|
|
|
|
},
|
|
|
|
})
|
2023-02-18 13:52:31 -05:00
|
|
|
).rejects.toThrow('package does not exist on uplink: foo');
|
2022-08-27 05:52:23 -05:00
|
|
|
});
|
2024-06-13 05:06:01 -05:00
|
|
|
|
|
|
|
test('ok to remove package as non-owner without check', async () => {
|
|
|
|
const config = getConfig('publishWithOwnerDefault.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const owner = 'fooUser';
|
|
|
|
const options = { ...defaultRequestOptions, username: owner };
|
|
|
|
|
|
|
|
// 1. publish a package
|
|
|
|
const bodyNewManifest = generatePackageMetadata('foo', '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
// 2. request package (should be available in the local cache)
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
})) as Manifest;
|
|
|
|
const _rev = manifest1._rev;
|
|
|
|
// 3. remove the tarball as other user
|
|
|
|
const nonOwner = 'barUser';
|
|
|
|
await expect(
|
|
|
|
storage.removeTarball(manifest1.name, 'foo-1.0.0.tgz', _rev, nonOwner)
|
|
|
|
).resolves.toBeDefined();
|
|
|
|
// 4. remove the package as other user
|
|
|
|
await storage.removePackage(manifest1.name, _rev, nonOwner);
|
|
|
|
// 5. fails if package does not exist anymore in storage
|
|
|
|
await expect(
|
|
|
|
storage.getPackageByOptions({
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
})
|
|
|
|
).rejects.toThrow('package does not exist on uplink: foo');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fail as non-owner with check', async () => {
|
|
|
|
const config = getConfig('publishWithOwnerAndCheck.yaml');
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
const owner = 'fooUser';
|
|
|
|
const options = { ...defaultRequestOptions, username: owner };
|
|
|
|
|
|
|
|
// 1. publish a package
|
|
|
|
const bodyNewManifest = generatePackageMetadata('foo', '1.0.0');
|
|
|
|
await storage.updateManifest(bodyNewManifest, {
|
|
|
|
signal: new AbortController().signal,
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: options,
|
|
|
|
});
|
|
|
|
// 2. request package (should be available in the local cache)
|
|
|
|
const manifest1 = (await storage.getPackageByOptions({
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: false,
|
|
|
|
requestOptions: options,
|
|
|
|
})) as Manifest;
|
|
|
|
const _rev = manifest1._rev;
|
|
|
|
// 3. try removing the tarball
|
|
|
|
const nonOwner = 'barUser';
|
|
|
|
await expect(
|
|
|
|
storage.removeTarball(manifest1.name, 'foo-1.0.0.tgz', _rev, nonOwner)
|
|
|
|
).rejects.toThrow();
|
|
|
|
// 4. try removing the package
|
|
|
|
await expect(storage.removePackage(manifest1.name, _rev, nonOwner)).rejects.toThrow();
|
|
|
|
});
|
2022-08-27 05:52:23 -05:00
|
|
|
});
|
|
|
|
|
2022-09-18 14:47:23 -05:00
|
|
|
describe('getPackageByOptions()', () => {
|
2021-12-12 12:00:19 -05:00
|
|
|
describe('with uplinks', () => {
|
|
|
|
test('should get 201 and merge from uplink', async () => {
|
|
|
|
nock(domain).get('/foo').reply(201, fooManifest);
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2022-02-20 12:39:38 -05:00
|
|
|
storage.getPackageByOptions({
|
2021-12-12 12:00:19 -05:00
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
2022-07-29 13:51:45 -05:00
|
|
|
host: req.get('host') as string,
|
2021-12-12 12:00:19 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
).resolves.toEqual(expect.objectContaining({ name: 'foo' }));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get 201 and merge from uplink with version', async () => {
|
|
|
|
nock(domain).get('/foo').reply(201, fooManifest);
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2022-02-20 12:39:38 -05:00
|
|
|
storage.getPackageByOptions({
|
2021-12-12 12:00:19 -05:00
|
|
|
name: 'foo',
|
|
|
|
version: '1.0.0',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
2022-07-29 13:51:45 -05:00
|
|
|
host: req.get('host') as string,
|
2021-12-12 12:00:19 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
).resolves.toEqual(expect.objectContaining({ name: 'foo' }));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get 201 and merge from uplink with dist-tag', async () => {
|
|
|
|
nock(domain).get('/foo').reply(201, fooManifest);
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2022-02-20 12:39:38 -05:00
|
|
|
storage.getPackageByOptions({
|
2021-12-12 12:00:19 -05:00
|
|
|
name: 'foo',
|
|
|
|
version: 'latest',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
2022-07-29 13:51:45 -05:00
|
|
|
host: req.get('host') as string,
|
2021-12-12 12:00:19 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
).resolves.toEqual(expect.objectContaining({ name: 'foo' }));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get 404 for version does not exist', async () => {
|
|
|
|
nock(domain).get('/foo').reply(201, fooManifest);
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2022-02-20 12:39:38 -05:00
|
|
|
storage.getPackageByOptions({
|
2021-12-12 12:00:19 -05:00
|
|
|
name: 'foo',
|
|
|
|
version: '1.0.0-does-not-exist',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
2022-07-29 13:51:45 -05:00
|
|
|
host: req.get('host') as string,
|
2021-12-12 12:00:19 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
).rejects.toThrow(
|
|
|
|
errorUtils.getNotFound("this version doesn't exist: 1.0.0-does-not-exist")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get 404', async () => {
|
|
|
|
nock(domain).get('/foo2').reply(404);
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
|
|
|
uplinks: {
|
|
|
|
npmjs: {
|
|
|
|
url: domain,
|
|
|
|
},
|
|
|
|
},
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2022-02-20 12:39:38 -05:00
|
|
|
storage.getPackageByOptions({
|
2021-12-12 12:00:19 -05:00
|
|
|
name: 'foo2',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
2022-07-29 13:51:45 -05:00
|
|
|
host: req.get('host') as string,
|
2021-12-12 12:00:19 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
).rejects.toThrow(errorUtils.getNotFound());
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get ETIMEDOUT with uplink', async () => {
|
|
|
|
nock(domain).get('/foo2').replyWithError({
|
|
|
|
code: 'ETIMEDOUT',
|
|
|
|
errno: 'ETIMEDOUT',
|
|
|
|
});
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
2022-08-19 13:25:20 -05:00
|
|
|
...getDefaultConfig(),
|
|
|
|
uplinks: {
|
|
|
|
npmjs: {
|
|
|
|
url: domain,
|
|
|
|
},
|
|
|
|
},
|
2022-08-27 05:52:23 -05:00
|
|
|
storage: generateRandomStorage(),
|
2021-12-12 12:00:19 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
await expect(
|
2022-02-20 12:39:38 -05:00
|
|
|
storage.getPackageByOptions({
|
2021-12-12 12:00:19 -05:00
|
|
|
name: 'foo2',
|
|
|
|
uplinksLook: true,
|
2022-07-29 13:51:45 -05:00
|
|
|
retry: { limit: 0 },
|
2021-12-12 12:00:19 -05:00
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
2022-07-29 13:51:45 -05:00
|
|
|
host: req.get('host') as string,
|
2021-12-12 12:00:19 -05:00
|
|
|
},
|
|
|
|
})
|
2023-08-06 10:42:20 -05:00
|
|
|
).rejects.toThrow(errorUtils.getServiceUnavailable(API_ERROR.NO_PACKAGE));
|
2021-12-12 12:00:19 -05:00
|
|
|
});
|
2022-08-27 05:52:23 -05:00
|
|
|
|
|
|
|
test('should fetch abbreviated version of manifest ', async () => {
|
|
|
|
const fooManifest = generateLocalPackageMetadata('foo', '1.0.0');
|
|
|
|
nock(domain).get('/foo').reply(201, fooManifest);
|
|
|
|
const config = new Config(
|
|
|
|
configExample({
|
|
|
|
...getDefaultConfig(),
|
|
|
|
storage: generateRandomStorage(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const req = httpMocks.createRequest({
|
|
|
|
method: 'GET',
|
|
|
|
connection: { remoteAddress: fakeHost },
|
|
|
|
headers: {
|
|
|
|
host: fakeHost,
|
|
|
|
[HEADERS.FORWARDED_PROTO]: 'http',
|
|
|
|
},
|
|
|
|
url: '/',
|
|
|
|
});
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
|
|
|
|
const manifest = (await storage.getPackageByOptions({
|
|
|
|
name: 'foo',
|
|
|
|
uplinksLook: true,
|
|
|
|
requestOptions: {
|
|
|
|
headers: req.headers as any,
|
|
|
|
protocol: req.protocol,
|
|
|
|
host: req.get('host') as string,
|
|
|
|
},
|
|
|
|
abbreviated: true,
|
|
|
|
})) as AbbreviatedManifest;
|
|
|
|
const { versions, name } = manifest;
|
|
|
|
expect(name).toEqual('foo');
|
|
|
|
expect(Object.keys(versions)).toEqual(['1.0.0']);
|
|
|
|
expect(manifest[DIST_TAGS]).toEqual({ latest: '1.0.0' });
|
|
|
|
const version = versions['1.0.0'];
|
|
|
|
expect(Object.keys(version)).toEqual([
|
|
|
|
'name',
|
|
|
|
'version',
|
|
|
|
'deprecated',
|
|
|
|
'bin',
|
|
|
|
'dist',
|
|
|
|
'engines',
|
|
|
|
'funding',
|
|
|
|
'directories',
|
|
|
|
'dependencies',
|
|
|
|
'devDependencies',
|
|
|
|
'peerDependencies',
|
|
|
|
'optionalDependencies',
|
|
|
|
'bundleDependencies',
|
2024-06-13 06:11:38 -05:00
|
|
|
'cpu',
|
|
|
|
'os',
|
|
|
|
'peerDependenciesMeta',
|
|
|
|
'acceptDependencies',
|
2022-08-27 05:52:23 -05:00
|
|
|
'_hasShrinkwrap',
|
|
|
|
'hasInstallScript',
|
|
|
|
]);
|
|
|
|
expect(manifest.modified).toBeDefined();
|
|
|
|
// special case for pnpm/rfcs/pull/2
|
|
|
|
expect(manifest.time).toBeDefined();
|
|
|
|
// fields must not have
|
|
|
|
// @ts-expect-error
|
|
|
|
expect(manifest.readme).not.toBeDefined();
|
|
|
|
// @ts-expect-error
|
|
|
|
expect(manifest._attachments).not.toBeDefined();
|
|
|
|
// @ts-expect-error
|
|
|
|
expect(manifest._rev).not.toBeDefined();
|
|
|
|
});
|
2021-12-12 12:00:19 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|