Skip to content

Commit

Permalink
test(up-storage): add unit test about uplink is npmmirror
Browse files Browse the repository at this point in the history
Cause thers is a bug in `isObject` function from `@verdaccio/core`, when `options.json` is `true`
GET request body will be string 'true', some uplinks might return 413 status code such as
https://registry.npmmirror.com

fix verdaccio#3601
  • Loading branch information
botao-tal committed Feb 23, 2023
1 parent d3ce8a5 commit 2395bd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/lib/up-storage.ts
Expand Up @@ -215,10 +215,11 @@ class ProxyStorage implements IProxy {
}
}
: undefined;
let requestOptions = {
let requestOptions: request.OptionsWithUrl = {
url: uri,
method: method,
headers: headers,
body: json,
proxy: this.proxy,
encoding: null,
gzip: true,
Expand All @@ -227,11 +228,6 @@ class ProxyStorage implements IProxy {
agentOptions: this.agent_options,
};

// GET requests should not have a body, otherwise the request might fail(return 413 status code)
if (method.toUpperCase() !== 'GET') {
requestOptions.body = json
}

if (this.ca) {
requestOptions = Object.assign({}, requestOptions, {
ca: this.ca,
Expand Down
18 changes: 14 additions & 4 deletions test/unit/modules/uplinks/up-storage.spec.ts
Expand Up @@ -12,7 +12,7 @@ import configExample from '../../partials/config';

setup({});

describe('UpStorge', () => {
describe('UpStorage', () => {
const mockServerPort = 55547;
let mockRegistry;
const uplinkDefault = {
Expand All @@ -39,7 +39,7 @@ describe('UpStorge', () => {
expect(proxy).toBeDefined();
});

describe('UpStorge::getRemoteMetadata', () => {
describe('UpStorage::getRemoteMetadata', () => {
test('should be get remote metadata', (done) => {
const proxy = generateProxy();

Expand Down Expand Up @@ -72,9 +72,19 @@ describe('UpStorge', () => {
done();
});
});

test('should be get remote metadata with json when uplink is npmmirror', (done) => {
const proxy = generateProxy({ url: 'https://registry.npmmirror.com' });

proxy.getRemoteMetadata('jquery', { json: true }, (err, data) => {
expect(err).toBeNull();
expect(data.name).toBe('jquery');
done();
});
});
});

describe('UpStorge::fetchTarball', () => {
describe('UpStorage::fetchTarball', () => {
test('should fetch a tarball from uplink', (done) => {
const proxy = generateProxy();
const tarball = `http://${DOMAIN_SERVERS}:${mockServerPort}/jquery/-/jquery-1.5.1.tgz`;
Expand Down Expand Up @@ -147,7 +157,7 @@ describe('UpStorge', () => {
}, 10000);
});

describe('UpStorge::isUplinkValid', () => {
describe('UpStorage::isUplinkValid', () => {
describe('valid use cases', () => {
const validateUpLink = (
url: string,
Expand Down

0 comments on commit 2395bd6

Please sign in to comment.