mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
parent
67406082ed
commit
73d34bf9c4
24
package.json
24
package.json
@ -44,6 +44,7 @@
|
||||
"@commitlint/cli": "8.3.5",
|
||||
"@commitlint/config-conventional": "8.2.0",
|
||||
"@types/async": "3.2.5",
|
||||
"@types/autocannon": "4.1.0",
|
||||
"@types/autosuggest-highlight": "3.1.1",
|
||||
"@types/express": "4.17.6",
|
||||
"@types/http-errors": "1.8.0",
|
||||
@ -52,7 +53,6 @@
|
||||
"@types/lodash": "4.14.167",
|
||||
"@types/lowdb": "^1.0.9",
|
||||
"@types/mime": "2.0.2",
|
||||
"@types/autocannon": "4.1.0",
|
||||
"@types/minimatch": "3.0.3",
|
||||
"@types/node": "^14.14.7",
|
||||
"@types/react": "16.14.2",
|
||||
@ -69,21 +69,22 @@
|
||||
"@types/webpack-env": "1.16.0",
|
||||
"@typescript-eslint/eslint-plugin": "4.13.0",
|
||||
"@typescript-eslint/parser": "4.13.0",
|
||||
"@verdaccio/types": "workspace:*",
|
||||
"@verdaccio/ui-theme": "workspace:*",
|
||||
"@verdaccio/benchmark": "workspace:*",
|
||||
"@verdaccio/eslint-config": "workspace:*",
|
||||
"@verdaccio/types": "workspace:*",
|
||||
"@verdaccio/ui-theme": "workspace:*",
|
||||
"autocannon": "7.3.0",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"babel-eslint": "10.1.0",
|
||||
"babel-jest": "26.6.3",
|
||||
"babel-jest": "27.0.2",
|
||||
"babel-plugin-dynamic-import-node": "2.3.3",
|
||||
"babel-plugin-emotion": "11.0.0",
|
||||
"codecov": "3.8.1",
|
||||
"concurrently": "^5.3.0",
|
||||
"core-js": "^3.12.1",
|
||||
"cross-env": "7.0.3",
|
||||
"debug": "4.3.1",
|
||||
"detect-secrets": "1.0.6",
|
||||
"autocannon": "7.3.0",
|
||||
"eslint": "7.26.0",
|
||||
"eslint-config-google": "0.14.0",
|
||||
"eslint-config-prettier": "8.3.0",
|
||||
@ -91,26 +92,25 @@
|
||||
"eslint-plugin-import": "2.23.2",
|
||||
"eslint-plugin-jest": "24.3.6",
|
||||
"eslint-plugin-jsx-a11y": "6.4.1",
|
||||
"eslint-plugin-prettier": "3.4.0",
|
||||
"eslint-plugin-react": "7.23.2",
|
||||
"eslint-plugin-react-hooks": "4.2.0",
|
||||
"eslint-plugin-simple-import-sort": "7.0.0",
|
||||
"eslint-plugin-verdaccio": "10.0.0",
|
||||
"eslint-plugin-prettier": "3.4.0",
|
||||
"fs-extra": "9.1.0",
|
||||
"debug": "4.3.1",
|
||||
"husky": "2.7.0",
|
||||
"in-publish": "2.0.1",
|
||||
"jest": "26.6.3",
|
||||
"jest-environment-jsdom": "26.6.2",
|
||||
"jest": "27.0.4",
|
||||
"jest-environment-jsdom": "27.0.3",
|
||||
"jest-environment-jsdom-global": "^2.0.4",
|
||||
"jest-environment-node": "26.6.2",
|
||||
"jest-environment-node": "27.0.3",
|
||||
"jest-fetch-mock": "3.0.3",
|
||||
"jest-junit": "11.0.1",
|
||||
"kleur": "4.1.4",
|
||||
"lint-staged": "8.2.1",
|
||||
"nock": "12.0.3",
|
||||
"nodemon": "^2.0.7",
|
||||
"node-fetch": "2.6.1",
|
||||
"nodemon": "^2.0.7",
|
||||
"npm-run-all": "4.1.5",
|
||||
"prettier": "2.3.0",
|
||||
"rimraf": "3.0.2",
|
||||
@ -131,7 +131,7 @@
|
||||
"docker": "docker build -t verdaccio/verdaccio:local . --no-cache",
|
||||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
|
||||
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
|
||||
"lint": "eslint --max-warnings 48 \"**/*.{js,jsx,ts,tsx}\"",
|
||||
"lint": "eslint --max-warnings 49 \"**/*.{js,jsx,ts,tsx}\"",
|
||||
"test": "pnpm recursive test --filter ./packages",
|
||||
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
|
||||
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",
|
||||
|
@ -34,30 +34,34 @@ describe('package', () => {
|
||||
app = await initializeServer('package.yaml');
|
||||
});
|
||||
|
||||
test('should return a package', async (done) => {
|
||||
test('should return a package', async () => {
|
||||
await publishVersion(app, 'package.yaml', 'foo', '1.0.0');
|
||||
return supertest(app)
|
||||
.get('/foo')
|
||||
.set('Accept', HEADERS.JSON)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.then((response) => {
|
||||
expect(response.body.name).toEqual('foo');
|
||||
done();
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
supertest(app)
|
||||
.get('/foo')
|
||||
.set('Accept', HEADERS.JSON)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.then((response) => {
|
||||
expect(response.body.name).toEqual('foo');
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should return a package by version', async (done) => {
|
||||
test('should return a package by version', async () => {
|
||||
await publishVersion(app, 'package.yaml', 'foo2', '1.0.0');
|
||||
return supertest(app)
|
||||
.get('/foo2/1.0.0')
|
||||
.set('Accept', HEADERS.JSON)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.then((response) => {
|
||||
expect(response.body.name).toEqual('foo2');
|
||||
done();
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
supertest(app)
|
||||
.get('/foo2/1.0.0')
|
||||
.set('Accept', HEADERS.JSON)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.then((response) => {
|
||||
expect(response.body.name).toEqual('foo2');
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: investigate the 404
|
||||
|
@ -18,8 +18,6 @@ const mockApiJWTmiddleware = jest.fn(
|
||||
}
|
||||
);
|
||||
|
||||
jest.setTimeout(50000000);
|
||||
|
||||
jest.mock('@verdaccio/auth', () => ({
|
||||
Auth: class {
|
||||
apiJWTmiddleware() {
|
||||
@ -86,98 +84,108 @@ describe('publish', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('should fail on publish a bad versions package', async (done) => {
|
||||
test('should fail on publish a bad versions package', async () => {
|
||||
const app = await initializeServer('publish.yaml');
|
||||
return supertest(app)
|
||||
.put(`/${encodeURIComponent(pkgName)}`)
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify(
|
||||
Object.assign({}, pkgMetadata, {
|
||||
versions: '',
|
||||
})
|
||||
return new Promise((resolve) => {
|
||||
supertest(app)
|
||||
.put(`/${encodeURIComponent(pkgName)}`)
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify(
|
||||
Object.assign({}, pkgMetadata, {
|
||||
versions: '',
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.set('accept', HEADERS.GZIP)
|
||||
.expect(HTTP_STATUS.BAD_REQUEST)
|
||||
.then((response) => {
|
||||
console.log('response.body', response.body);
|
||||
expect(response.body.error).toEqual(API_ERROR.UNSUPORTED_REGISTRY_CALL);
|
||||
done();
|
||||
});
|
||||
.set('accept', HEADERS.GZIP)
|
||||
.expect(HTTP_STATUS.BAD_REQUEST)
|
||||
.then((response) => {
|
||||
console.log('response.body', response.body);
|
||||
expect(response.body.error).toEqual(API_ERROR.UNSUPORTED_REGISTRY_CALL);
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('publish a package', () => {
|
||||
test('should publish a package', async (done) => {
|
||||
test('should publish a package', async () => {
|
||||
const app = await initializeServer('publish.yaml');
|
||||
return publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.then((response) => {
|
||||
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
|
||||
done();
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.then((response) => {
|
||||
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should publish a new package', async (done) => {
|
||||
test('should publish a new package', async () => {
|
||||
const pkgName = 'test';
|
||||
const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
|
||||
const app = await initializeServer('publish.yaml');
|
||||
return supertest(app)
|
||||
.put(`/${encodeURIComponent(pkgName)}`)
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify(
|
||||
Object.assign({}, pkgMetadata, {
|
||||
_attachments: null,
|
||||
})
|
||||
return new Promise((resolve) => {
|
||||
supertest(app)
|
||||
.put(`/${encodeURIComponent(pkgName)}`)
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify(
|
||||
Object.assign({}, pkgMetadata, {
|
||||
_attachments: null,
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.set('accept', HEADERS.GZIP)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.then((response) => {
|
||||
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
|
||||
done();
|
||||
});
|
||||
.set('accept', HEADERS.GZIP)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.then((response) => {
|
||||
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should publish a new package with no readme', async (done) => {
|
||||
test('should publish a new package with no readme', async () => {
|
||||
const pkgName = 'test';
|
||||
const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
|
||||
const app = await initializeServer('publish.yaml');
|
||||
return supertest(app)
|
||||
.put(`/${encodeURIComponent(pkgName)}`)
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify(
|
||||
Object.assign({}, pkgMetadata, {
|
||||
versions: {
|
||||
['1.0.0']: {
|
||||
readme: null,
|
||||
return new Promise((resolve) => {
|
||||
supertest(app)
|
||||
.put(`/${encodeURIComponent(pkgName)}`)
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify(
|
||||
Object.assign({}, pkgMetadata, {
|
||||
versions: {
|
||||
['1.0.0']: {
|
||||
readme: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.set('accept', HEADERS.GZIP)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.then((response) => {
|
||||
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
|
||||
done();
|
||||
});
|
||||
.set('accept', HEADERS.GZIP)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.then((response) => {
|
||||
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on publish a duplicated package', async (done) => {
|
||||
test('should fails on publish a duplicated package', async () => {
|
||||
const app = await initializeServer('publish.yaml');
|
||||
await publishVersion(app, 'publish.yaml', 'foo', '1.0.0');
|
||||
return publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
|
||||
.expect(HTTP_STATUS.CONFLICT)
|
||||
.then((response) => {
|
||||
console.log('response.body', response.body);
|
||||
expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
|
||||
done();
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
|
||||
.expect(HTTP_STATUS.CONFLICT)
|
||||
.then((response) => {
|
||||
console.log('response.body', response.body);
|
||||
expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unpublish a package', () => {
|
||||
|
@ -52,7 +52,7 @@ jest.mock('@verdaccio/auth', () => ({
|
||||
describe('user', () => {
|
||||
const credentials = { name: 'test', password: 'test' };
|
||||
|
||||
test('should test add a new user', async (done) => {
|
||||
test('should test add a new user', async () => {
|
||||
mockApiJWTmiddleware.mockImplementationOnce(
|
||||
() =>
|
||||
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
||||
@ -64,28 +64,31 @@ describe('user', () => {
|
||||
mockAddUser.mockImplementationOnce(() => (_name, _password, callback): void => {
|
||||
return callback(null, true);
|
||||
});
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.put(`/-/user/org.couchdb.user:newUser`)
|
||||
.send({
|
||||
name: 'newUser',
|
||||
password: 'newUser',
|
||||
})
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.token).toBeDefined();
|
||||
const token = res.body.token;
|
||||
expect(typeof token).toBe('string');
|
||||
expect(res.body.ok).toMatch(`user 'newUser' created`);
|
||||
done();
|
||||
});
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.put(`/-/user/org.couchdb.user:newUser`)
|
||||
.send({
|
||||
name: 'newUser',
|
||||
password: 'newUser',
|
||||
})
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.token).toBeDefined();
|
||||
const token = res.body.token;
|
||||
expect(typeof token).toBe('string');
|
||||
expect(res.body.ok).toMatch(`user 'newUser' created`);
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should test fails on add a existing user with login', async (done) => {
|
||||
test('should test fails on add a existing user with login', async () => {
|
||||
mockApiJWTmiddleware.mockImplementationOnce(
|
||||
() =>
|
||||
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
||||
@ -93,39 +96,45 @@ describe('user', () => {
|
||||
_next();
|
||||
}
|
||||
);
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.put('/-/user/org.couchdb.user:jotaNew')
|
||||
.send(credentials)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CONFLICT)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(API_ERROR.USERNAME_ALREADY_REGISTERED);
|
||||
done();
|
||||
});
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.put('/-/user/org.couchdb.user:jotaNew')
|
||||
.send(credentials)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CONFLICT)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(API_ERROR.USERNAME_ALREADY_REGISTERED);
|
||||
resolve(res.body);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should log in as existing user', async (done) => {
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
||||
.send(credentials)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
test('should log in as existing user', async () => {
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
||||
.send(credentials)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
expect(res.body).toBeTruthy();
|
||||
expect(res.body.ok).toMatch(`you are authenticated as \'${credentials.name}\'`);
|
||||
done();
|
||||
});
|
||||
expect(res.body).toBeTruthy();
|
||||
expect(res.body.ok).toMatch(`you are authenticated as \'${credentials.name}\'`);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should test fails add a new user with missing name', async (done) => {
|
||||
test('should test fails add a new user with missing name', async () => {
|
||||
mockApiJWTmiddleware.mockImplementationOnce(
|
||||
() =>
|
||||
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
||||
@ -139,23 +148,26 @@ describe('user', () => {
|
||||
const credentialsShort = _.cloneDeep(credentials);
|
||||
delete credentialsShort.name;
|
||||
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.BAD_REQUEST)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.BAD_REQUEST)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(API_ERROR.USERNAME_PASSWORD_REQUIRED);
|
||||
done();
|
||||
});
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(API_ERROR.USERNAME_PASSWORD_REQUIRED);
|
||||
resolve(app);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should test fails add a new user with missing password', async (done) => {
|
||||
test('should test fails add a new user with missing password', async () => {
|
||||
mockApiJWTmiddleware.mockImplementationOnce(
|
||||
() =>
|
||||
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
||||
@ -166,25 +178,28 @@ describe('user', () => {
|
||||
const credentialsShort = _.cloneDeep(credentials);
|
||||
delete credentialsShort.password;
|
||||
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.BAD_REQUEST)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.BAD_REQUEST)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
expect(res.body.error).toBeDefined();
|
||||
// FIXME: message is not 100% accurate
|
||||
// eslint-disable-next-line new-cap
|
||||
expect(res.body.error).toMatch(API_ERROR.PASSWORD_SHORT());
|
||||
done();
|
||||
});
|
||||
expect(res.body.error).toBeDefined();
|
||||
// FIXME: message is not 100% accurate
|
||||
// eslint-disable-next-line new-cap
|
||||
expect(res.body.error).toMatch(API_ERROR.PASSWORD_SHORT());
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should test fails add a new user with wrong password', async (done) => {
|
||||
test('should test fails add a new user with wrong password', async () => {
|
||||
mockApiJWTmiddleware.mockImplementationOnce(
|
||||
() =>
|
||||
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
||||
@ -197,27 +212,29 @@ describe('user', () => {
|
||||
});
|
||||
const credentialsShort = _.cloneDeep(credentials);
|
||||
credentialsShort.password = 'failPassword';
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.put('/-/user/org.couchdb.user:test')
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.UNAUTHORIZED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.put('/-/user/org.couchdb.user:test')
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.UNAUTHORIZED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(API_ERROR.BAD_USERNAME_PASSWORD);
|
||||
done();
|
||||
});
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(API_ERROR.BAD_USERNAME_PASSWORD);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should be able to logout an user', async (done) => {
|
||||
test('should be able to logout an user', async () => {
|
||||
mockApiJWTmiddleware.mockImplementationOnce(
|
||||
() =>
|
||||
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
||||
(req: $RequestExtend, _res: $ResponseExtend, _next): void => {
|
||||
req.remote_user = { name: 'test' };
|
||||
_next();
|
||||
}
|
||||
@ -228,18 +245,21 @@ describe('user', () => {
|
||||
const credentialsShort = _.cloneDeep(credentials);
|
||||
credentialsShort.password = 'failPassword';
|
||||
|
||||
supertest(await initializeServer('user.yaml'))
|
||||
.delete('/-/user/token/someSecretToken')
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
const app = await initializeServer('user.yaml');
|
||||
return new Promise((resolve, reject) => {
|
||||
supertest(app)
|
||||
.delete('/-/user/token/someSecretToken')
|
||||
.send(credentialsShort)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.LOGGED_OUT);
|
||||
done();
|
||||
});
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.LOGGED_OUT);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -45,7 +45,7 @@
|
||||
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
||||
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
||||
"build": "pnpm run build:js && pnpm run build:types",
|
||||
"test": "cross-env NODE_ENV=test BABEL_ENV=test jest"
|
||||
"test": "cross-env NODE_ENV=test VERDACCIO_TEST_BUCKET=test BABEL_ENV=test jest"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
|
@ -57,9 +57,13 @@ describe('proxy', () => {
|
||||
},
|
||||
url,
|
||||
});
|
||||
let dataSearch;
|
||||
const stream = prox1.search({ req });
|
||||
stream.on('data', (data) => {
|
||||
expect(data).toBeDefined();
|
||||
dataSearch += `${data}`;
|
||||
});
|
||||
stream.on('end', () => {
|
||||
expect(dataSearch).toBeDefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -54,7 +54,7 @@ describe('endpoint unit test', () => {
|
||||
let app;
|
||||
let mockRegistry;
|
||||
|
||||
beforeAll(async function (done) {
|
||||
beforeAll(async function () {
|
||||
const store = generateRamdonStorage();
|
||||
const mockServerPort = 55549;
|
||||
const configForTest = configExample(
|
||||
@ -81,33 +81,32 @@ describe('endpoint unit test', () => {
|
||||
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Registry API Endpoints', () => {
|
||||
describe('should test user api', () => {
|
||||
describe('should test authorization headers with tokens only errors', () => {
|
||||
test('should fails on protected endpoint /-/auth-package bad format', (done) => {
|
||||
request(app)
|
||||
.get('/auth-package')
|
||||
.set(HEADERS.AUTHORIZATION, 'FakeHader')
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.expect(HTTP_STATUS.FORBIDDEN)
|
||||
.end(function (err, res) {
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(
|
||||
/authorization required to access package auth-package/
|
||||
);
|
||||
done();
|
||||
});
|
||||
test('should fails on protected endpoint /-/auth-package bad format', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/auth-package')
|
||||
.set(HEADERS.AUTHORIZATION, 'FakeHader')
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.expect(HTTP_STATUS.FORBIDDEN)
|
||||
.end(function (err, res) {
|
||||
expect(res.body.error).toBeDefined();
|
||||
expect(res.body.error).toMatch(
|
||||
/authorization required to access package auth-package/
|
||||
);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on protected endpoint /-/auth-package bad JWT Bearer format', (done) => {
|
||||
@ -477,14 +476,14 @@ describe('endpoint unit test', () => {
|
||||
* It publish 2 versions and unpublish the latest one, then verifies
|
||||
* the version do not exist anymore in the body of the metadata.
|
||||
*/
|
||||
const runPublishUnPublishFlow = async (pkgName: string, done, token?: string) => {
|
||||
const runPublishUnPublishFlow = async (pkgName: string, token?: string) => {
|
||||
const version = '2.0.0';
|
||||
const pkg = generatePackageMetadata(pkgName, version);
|
||||
|
||||
const [err] = await putPackage(request(app), `/${pkgName}`, pkg, token);
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
|
||||
const newVersion = '2.0.1';
|
||||
@ -496,7 +495,7 @@ describe('endpoint unit test', () => {
|
||||
);
|
||||
if (newErr) {
|
||||
expect(newErr).toBeNull();
|
||||
return done(newErr);
|
||||
return Promise.reject(newErr);
|
||||
}
|
||||
|
||||
const deletePayload = generatePackageUnpublish(pkgName, ['2.0.0']);
|
||||
@ -513,26 +512,26 @@ describe('endpoint unit test', () => {
|
||||
const existVersion = await verifyPackageVersionDoesExist(app, pkgName, newVersion, token);
|
||||
expect(existVersion).toBeTruthy();
|
||||
|
||||
return done();
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
describe('un/publish scenarios with credentials', () => {
|
||||
test('should flow with no credentials', async (done) => {
|
||||
test('should flow with no credentials', async () => {
|
||||
const pkgName = '@public-anyone-can-publish/pk1-test';
|
||||
runPublishUnPublishFlow(pkgName, done, undefined);
|
||||
return await runPublishUnPublishFlow(pkgName, undefined);
|
||||
});
|
||||
|
||||
test('should flow with credentials', async (done) => {
|
||||
test('should flow with credentials', async () => {
|
||||
const credentials = { name: 'jota_unpublish', password: 'secretPass' };
|
||||
const token = await getNewToken(request(app), credentials);
|
||||
const pkgName = '@only-one-can-publish/pk1-test';
|
||||
|
||||
runPublishUnPublishFlow(pkgName, done, token);
|
||||
return await runPublishUnPublishFlow(pkgName, token);
|
||||
});
|
||||
});
|
||||
|
||||
describe('test error handling', () => {
|
||||
test('should fail if user is not allowed to unpublish', async (done) => {
|
||||
test('should fail if user is not allowed to unpublish', async () => {
|
||||
/**
|
||||
* Context:
|
||||
*
|
||||
@ -563,7 +562,7 @@ describe('endpoint unit test', () => {
|
||||
);
|
||||
if (newErr) {
|
||||
expect(newErr).toBeNull();
|
||||
return done(newErr);
|
||||
return Promise.reject(newErr);
|
||||
}
|
||||
|
||||
const deletePayload = generatePackageUnpublish(pkgName, ['2.0.0']);
|
||||
@ -578,10 +577,9 @@ describe('endpoint unit test', () => {
|
||||
expect(res2.body.error).toMatch(
|
||||
/user jota_unpublish_fail is not allowed to unpublish package non-unpublish/
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
test('should fail if publish prop is not defined', async (done) => {
|
||||
test('should fail if publish prop is not defined', async () => {
|
||||
/**
|
||||
* Context:
|
||||
*
|
||||
@ -615,84 +613,87 @@ describe('endpoint unit test', () => {
|
||||
expect(resp.body.error).toMatch(
|
||||
/user jota_only_unpublish_fail is not allowed to publish package only-unpublish/
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should be able to publish/unpublish by only super_admin user', async (done) => {
|
||||
test('should be able to publish/unpublish by only super_admin user', async () => {
|
||||
const credentials = { name: 'super_admin', password: 'secretPass' };
|
||||
const token = await getNewToken(request(app), credentials);
|
||||
request(app)
|
||||
.put('/super-admin-can-unpublish')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.send(
|
||||
JSON.stringify(
|
||||
_.assign({}, publishMetadata, {
|
||||
name: 'super-admin-can-unpublish',
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
.put('/super-admin-can-unpublish')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.send(
|
||||
JSON.stringify(
|
||||
_.assign({}, publishMetadata, {
|
||||
name: 'super-admin-can-unpublish',
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
}
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.success).toBeDefined();
|
||||
expect(res.body.success).toBeTruthy();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
||||
request(app)
|
||||
.del('/super-admin-can-unpublish/-rev/4-6abcdb4efd41a576')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_REMOVED);
|
||||
done();
|
||||
});
|
||||
});
|
||||
return reject(err);
|
||||
}
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.success).toBeDefined();
|
||||
expect(res.body.success).toBeTruthy();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
||||
request(app)
|
||||
.del('/super-admin-can-unpublish/-rev/4-6abcdb4efd41a576')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_REMOVED);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should be able to publish/unpublish by any user', async (done) => {
|
||||
test('should be able to publish/unpublish by any user', async () => {
|
||||
const credentials = { name: 'any_user', password: 'secretPass' };
|
||||
const token = await getNewToken(request(app), credentials);
|
||||
request(app)
|
||||
.put('/all-can-unpublish')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.send(
|
||||
JSON.stringify(
|
||||
_.assign({}, publishMetadata, {
|
||||
name: 'all-can-unpublish',
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
.put('/all-can-unpublish')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.send(
|
||||
JSON.stringify(
|
||||
_.assign({}, publishMetadata, {
|
||||
name: 'all-can-unpublish',
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
}
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.success).toBeDefined();
|
||||
expect(res.body.success).toBeTruthy();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
||||
request(app)
|
||||
.del('/all-can-unpublish/-rev/4-6abcdb4efd41a576')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_REMOVED);
|
||||
done();
|
||||
});
|
||||
});
|
||||
return reject(err);
|
||||
}
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.success).toBeDefined();
|
||||
expect(res.body.success).toBeTruthy();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
||||
request(app)
|
||||
.del('/all-can-unpublish/-rev/4-6abcdb4efd41a576')
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(API_MESSAGE.PKG_REMOVED);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -700,10 +701,9 @@ describe('endpoint unit test', () => {
|
||||
const pkgName = '@scope/starPackage';
|
||||
const credentials = { name: 'jota_star', password: 'secretPass' };
|
||||
let token = '';
|
||||
beforeAll(async (done) => {
|
||||
beforeAll(async () => {
|
||||
token = await getNewToken(request(app), credentials);
|
||||
await putPackage(request(app), `/${pkgName}`, generatePackageMetadata(pkgName), token);
|
||||
done();
|
||||
});
|
||||
|
||||
test('should star a package', (done) => {
|
||||
@ -748,38 +748,40 @@ describe('endpoint unit test', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('should retrieve stars list with credentials', async (done) => {
|
||||
request(app)
|
||||
.put(`/${pkgName}`)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(generateStarMedatada(pkgName, { [credentials.name]: true }))
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
}
|
||||
request(app)
|
||||
.get('/-/_view/starredByUser')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify({
|
||||
key: [credentials.name],
|
||||
})
|
||||
)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
}
|
||||
expect(res.body.rows).toBeDefined();
|
||||
expect(res.body.rows).toHaveLength(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('should retrieve stars list with credentials', async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
.put(`/${pkgName}`)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(generateStarMedatada(pkgName, { [credentials.name]: true }))
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return reject(err);
|
||||
}
|
||||
request(app)
|
||||
.get('/-/_view/starredByUser')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
||||
.send(
|
||||
JSON.stringify({
|
||||
key: [credentials.name],
|
||||
})
|
||||
)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return reject(err);
|
||||
}
|
||||
expect(res.body.rows).toBeDefined();
|
||||
expect(res.body.rows).toHaveLength(1);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -788,7 +790,7 @@ describe('endpoint unit test', () => {
|
||||
const credentials = { name: 'jota_deprecate', password: 'secretPass' };
|
||||
const version = '1.0.0';
|
||||
let token = '';
|
||||
beforeAll(async (done) => {
|
||||
beforeAll(async () => {
|
||||
token = await getNewToken(request(app), credentials);
|
||||
await putPackage(
|
||||
request(app),
|
||||
@ -796,33 +798,30 @@ describe('endpoint unit test', () => {
|
||||
generatePackageMetadata(pkgName, version),
|
||||
token
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
test('should deprecate a package', async (done) => {
|
||||
test('should deprecate a package', async () => {
|
||||
const pkg = generateDeprecateMetadata(pkgName, version, 'get deprecated');
|
||||
const [err] = await putPackage(request(app), `/${pkgName}`, pkg, token);
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
const [, res] = await getPackage(request(app), '', pkgName);
|
||||
expect(res.body.versions[version].deprecated).toEqual('get deprecated');
|
||||
done();
|
||||
});
|
||||
|
||||
test('should undeprecate a package', async (done) => {
|
||||
test('should undeprecate a package', async () => {
|
||||
let pkg = generateDeprecateMetadata(pkgName, version, 'get deprecated');
|
||||
await putPackage(request(app), `/${pkgName}`, pkg, token);
|
||||
pkg = generateDeprecateMetadata(pkgName, version, '');
|
||||
const [err] = await putPackage(request(app), `/${pkgName}`, pkg, token);
|
||||
if (err) {
|
||||
expect(err).toBeNull();
|
||||
return done(err);
|
||||
return;
|
||||
}
|
||||
const [, res] = await getPackage(request(app), '', pkgName);
|
||||
expect(res.body.versions[version].deprecated).not.toBeDefined();
|
||||
done();
|
||||
});
|
||||
|
||||
test(
|
||||
@ -848,7 +847,7 @@ describe('endpoint unit test', () => {
|
||||
}
|
||||
);
|
||||
|
||||
test('should deprecate multiple packages', async (done) => {
|
||||
test('should deprecate multiple packages', async () => {
|
||||
await putPackage(
|
||||
request(app),
|
||||
`/${pkgName}`,
|
||||
@ -862,9 +861,11 @@ describe('endpoint unit test', () => {
|
||||
};
|
||||
await putPackage(request(app), `/${pkgName}`, pkg, token);
|
||||
const [, res] = await getPackage(request(app), '', pkgName);
|
||||
expect(res.body.versions[version].deprecated).toEqual('get deprecated');
|
||||
expect(res.body.versions['1.0.1'].deprecated).toEqual('get deprecated');
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
expect(res.body.versions[version].deprecated).toEqual('get deprecated');
|
||||
expect(res.body.versions['1.0.1'].deprecated).toEqual('get deprecated');
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ describe('endpoint user auth JWT unit test', () => {
|
||||
let mockRegistry;
|
||||
const FAKE_TOKEN: string = buildToken(TOKEN_BEARER, 'fake');
|
||||
|
||||
beforeAll(async function (done) {
|
||||
beforeAll(async function () {
|
||||
const mockServerPort = 55546;
|
||||
const store = generateRamdonStorage();
|
||||
const configForTest = configExample(
|
||||
@ -56,18 +56,15 @@ describe('endpoint user auth JWT unit test', () => {
|
||||
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('should test add a new user with JWT enabled', async (done) => {
|
||||
test('should test add a new user with JWT enabled', async () => {
|
||||
const [err, res] = await addUser(request(app), credentials.name, credentials);
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
@ -94,10 +91,9 @@ describe('endpoint user auth JWT unit test', () => {
|
||||
expect(err2).toBeNull();
|
||||
expect(resp2.statusCode).toBe(HTTP_STATUS.UNAUTHORIZED);
|
||||
expect(resp2.body.error).toMatch(FORBIDDEN_VUE);
|
||||
done();
|
||||
});
|
||||
|
||||
test('should emulate npm login when user already exist', async (done) => {
|
||||
test('should emulate npm login when user already exist', async () => {
|
||||
const credentials = { name: 'jwtUser2', password: 'secretPass' };
|
||||
// creates an user
|
||||
await addUser(request(app), credentials.name, credentials);
|
||||
@ -107,23 +103,25 @@ describe('endpoint user auth JWT unit test', () => {
|
||||
// npm will try to sign in sending credentials via basic auth header
|
||||
const token = buildUserBuffer(credentials.name, credentials.password).toString('base64');
|
||||
// put should exist in request
|
||||
// @ts-ignore
|
||||
request(app)
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}/-rev/undefined`)
|
||||
.send(credentials)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BASIC, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.token).toBeDefined();
|
||||
return new Promise((resolve) => {
|
||||
// @ts-ignore
|
||||
request(app)
|
||||
.put(`/-/user/org.couchdb.user:${credentials.name}/-rev/undefined`)
|
||||
.send(credentials)
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BASIC, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.CREATED)
|
||||
.end(function (err, res) {
|
||||
expect(err).toBeNull();
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.token).toBeDefined();
|
||||
|
||||
done();
|
||||
});
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on try to access with corrupted token', async (done) => {
|
||||
test('should fails on try to access with corrupted token', async () => {
|
||||
const [err2, resp2] = await getPackage(
|
||||
request(app),
|
||||
FAKE_TOKEN,
|
||||
@ -133,13 +131,12 @@ describe('endpoint user auth JWT unit test', () => {
|
||||
expect(err2).toBeNull();
|
||||
expect(resp2.statusCode).toBe(HTTP_STATUS.UNAUTHORIZED);
|
||||
expect(resp2.body.error).toMatch(FORBIDDEN_VUE);
|
||||
done();
|
||||
});
|
||||
|
||||
test(
|
||||
'should fails on login if user credentials are invalid even if jwt' +
|
||||
' valid token is provided',
|
||||
async (done) => {
|
||||
async () => {
|
||||
const credentials = { name: 'newFailsUser', password: 'secretPass' };
|
||||
const [err, res] = await addUser(request(app), credentials.name, credentials);
|
||||
expect(err).toBeNull();
|
||||
@ -162,8 +159,6 @@ describe('endpoint user auth JWT unit test', () => {
|
||||
expect(err2).toBeNull();
|
||||
expect(resp2.statusCode).toBe(HTTP_STATUS.UNAUTHORIZED);
|
||||
expect(resp2.body.error).toMatch(API_ERROR.BAD_USERNAME_PASSWORD);
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ describe('api with no limited access configuration', () => {
|
||||
const store = generateRamdonStorage();
|
||||
jest.setTimeout(10000);
|
||||
|
||||
beforeAll(async (done) => {
|
||||
beforeAll(async () => {
|
||||
const mockServerPort = 55530;
|
||||
const configForTest = configExample(
|
||||
{
|
||||
@ -34,64 +34,67 @@ describe('api with no limited access configuration', () => {
|
||||
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
describe('test proxy packages partially restricted', () => {
|
||||
test('should test fails on fetch endpoint /-/not-found', (done) => {
|
||||
request(app)
|
||||
// @ts-ignore
|
||||
.get('/not-found-for-sure')
|
||||
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HEADERS.CONTENT_TYPE, /json/)
|
||||
.expect(HTTP_STATUS.NOT_FOUND)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
test('should test fails on fetch endpoint /-/not-found', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
// @ts-ignore
|
||||
.get('/not-found-for-sure')
|
||||
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HEADERS.CONTENT_TYPE, /json/)
|
||||
.expect(HTTP_STATUS.NOT_FOUND)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should test fetch endpoint /-/jquery', (done) => {
|
||||
request(app)
|
||||
// @ts-ignore
|
||||
.get('/jquery')
|
||||
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HEADERS.CONTENT_TYPE, /json/)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
test('should test fetch endpoint /-/jquery', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
// @ts-ignore
|
||||
.get('/jquery')
|
||||
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HEADERS.CONTENT_TYPE, /json/)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should success on fetch endpoint /-/vue', (done) => {
|
||||
request(app)
|
||||
// @ts-ignore
|
||||
.get('/vue')
|
||||
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HEADERS.CONTENT_TYPE, /json/)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
test('should success on fetch endpoint /-/vue', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
// @ts-ignore
|
||||
.get('/vue')
|
||||
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HEADERS.CONTENT_TYPE, /json/)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ describe('endpoint user profile', () => {
|
||||
let mockRegistry;
|
||||
jest.setTimeout(20000);
|
||||
|
||||
beforeAll(async (done) => {
|
||||
beforeAll(async () => {
|
||||
const store = generateRamdonStorage();
|
||||
const mockServerPort = 55544;
|
||||
const configForTest = configExample(
|
||||
@ -44,28 +44,24 @@ describe('endpoint user profile', () => {
|
||||
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('should fetch a profile of logged user', async (done) => {
|
||||
test('should fetch a profile of logged user', async () => {
|
||||
const credentials = { name: 'JotaJWT', password: 'secretPass' };
|
||||
const token = await getNewToken(request(app), credentials);
|
||||
const [err1, res1] = await getProfile(request(app), token);
|
||||
expect(err1).toBeNull();
|
||||
expect(res1.body.name).toBe(credentials.name);
|
||||
done();
|
||||
});
|
||||
|
||||
describe('change password', () => {
|
||||
test('should change password successfully', async (done) => {
|
||||
test('should change password successfully', async () => {
|
||||
const credentials = { name: 'userTest2000', password: 'secretPass000' };
|
||||
const body = {
|
||||
password: {
|
||||
@ -78,10 +74,9 @@ describe('endpoint user profile', () => {
|
||||
|
||||
expect(err1).toBeNull();
|
||||
expect(res1.body.name).toBe(credentials.name);
|
||||
done();
|
||||
});
|
||||
|
||||
test('should change password is too short', async (done) => {
|
||||
test('should change password is too short', async () => {
|
||||
const credentials = { name: 'userTest2001', password: 'secretPass001' };
|
||||
const body = {
|
||||
password: {
|
||||
@ -95,12 +90,11 @@ describe('endpoint user profile', () => {
|
||||
expect(resp.error).not.toBeNull();
|
||||
/* eslint new-cap: 0 */
|
||||
expect(resp.error.text).toMatch(API_ERROR.PASSWORD_SHORT());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('change tfa', () => {
|
||||
test('should report TFA is disabled', async (done) => {
|
||||
test('should report TFA is disabled', async () => {
|
||||
const credentials = { name: 'userTest2002', password: 'secretPass002' };
|
||||
const body = {
|
||||
tfa: {},
|
||||
@ -115,25 +109,22 @@ describe('endpoint user profile', () => {
|
||||
|
||||
expect(resp.error).not.toBeNull();
|
||||
expect(resp.error.text).toMatch(SUPPORT_ERRORS.TFA_DISABLED);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
test('should forbid to fetch a profile with invalid token', async (done) => {
|
||||
test('should forbid to fetch a profile with invalid token', async () => {
|
||||
const [, resp] = await getProfile(request(app), `fakeToken`, HTTP_STATUS.UNAUTHORIZED);
|
||||
|
||||
expect(resp.error).not.toBeNull();
|
||||
expect(resp.error.text).toMatch(API_ERROR.MUST_BE_LOGGED);
|
||||
done();
|
||||
});
|
||||
|
||||
test('should forbid to update a profile with invalid token', async (done) => {
|
||||
test('should forbid to update a profile with invalid token', async () => {
|
||||
const [, resp] = await postProfile(request(app), {}, `fakeToken`, HTTP_STATUS.UNAUTHORIZED);
|
||||
|
||||
expect(resp.error).not.toBeNull();
|
||||
expect(resp.error.text).toMatch(API_ERROR.MUST_BE_LOGGED);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -88,19 +88,17 @@ const createNullStream = () =>
|
||||
describe('StorageTest', () => {
|
||||
let mockRegistry;
|
||||
|
||||
beforeAll(async (done) => {
|
||||
beforeAll(async () => {
|
||||
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
done();
|
||||
return;
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('should be defined', async () => {
|
||||
@ -159,41 +157,44 @@ describe('StorageTest', () => {
|
||||
});
|
||||
|
||||
describe('test _syncUplinksMetadata', () => {
|
||||
test('should fetch from uplink jquery metadata from registry', async (done) => {
|
||||
test('should fetch from uplink jquery metadata from registry', async () => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('jquery', null, {}, (err, metadata) => {
|
||||
expect(err).toBeNull();
|
||||
expect(metadata).toBeDefined();
|
||||
expect(metadata).toBeInstanceOf(Object);
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('jquery', null, {}, (err, metadata) => {
|
||||
expect(err).toBeNull();
|
||||
expect(metadata).toBeDefined();
|
||||
expect(metadata).toBeInstanceOf(Object);
|
||||
resolve(metadata);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on fetch from uplink non existing from registry', async (done) => {
|
||||
test('should fails on fetch from uplink non existing from registry', async () => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
expect(errors[0][0].statusCode).toBe(HTTP_STATUS.NOT_FOUND);
|
||||
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, _metadata, errors) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
expect(errors[0][0].statusCode).toBe(HTTP_STATUS.NOT_FOUND);
|
||||
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
||||
resolve(errors);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on fetch from uplink corrupted pkg from registry', async (done) => {
|
||||
test('should fails on fetch from uplink corrupted pkg from registry', async () => {
|
||||
const storage: IStorageHandler = await generateStorage();
|
||||
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('corrupted-package', null, {}, (err, metadata, errors) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
expect(errors[0][0].statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
|
||||
expect(errors[0][0].message).toMatch(API_ERROR.BAD_STATUS_CODE);
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
// @ts-ignore
|
||||
storage._syncUplinksMetadata('corrupted-package', null, {}, (err, metadata, errors) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
expect(errors[0][0].statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
|
||||
expect(errors[0][0].message).toMatch(API_ERROR.BAD_STATUS_CODE);
|
||||
resolve(errors);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe('endpoint unit test', () => {
|
||||
let mockRegistry;
|
||||
let token;
|
||||
|
||||
beforeAll(async function (done) {
|
||||
beforeAll(async function () {
|
||||
const store = generateRamdonStorage();
|
||||
const mockServerPort = 55543;
|
||||
const configForTest = configExample(
|
||||
@ -90,69 +90,69 @@ describe('endpoint unit test', () => {
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
token = await getNewToken(request(app), credentials);
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Registry Token Endpoints', () => {
|
||||
test('should list empty tokens', async (done) => {
|
||||
request(app)
|
||||
.get('/-/npm/v1/tokens')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, resp) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
test('should list empty tokens', async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
.get('/-/npm/v1/tokens')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, resp) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
const { objects, urls } = resp.body;
|
||||
expect(objects).toHaveLength(0);
|
||||
expect(urls.next).toEqual('');
|
||||
done();
|
||||
});
|
||||
const { objects, urls } = resp.body;
|
||||
expect(objects).toHaveLength(0);
|
||||
expect(urls.next).toEqual('');
|
||||
resolve(urls);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should generate one token', async (done) => {
|
||||
test('should generate one token', async () => {
|
||||
await generateTokenCLI(app, token, {
|
||||
password: credentials.password,
|
||||
readonly: false,
|
||||
cidr_whitelist: [],
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
.get('/-/npm/v1/tokens')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, resp) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
request(app)
|
||||
.get('/-/npm/v1/tokens')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, resp) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
const { objects, urls } = resp.body;
|
||||
|
||||
const { objects, urls } = resp.body;
|
||||
expect(objects).toHaveLength(1);
|
||||
const [tokenGenerated] = objects;
|
||||
expect(tokenGenerated.user).toEqual(credentials.name);
|
||||
expect(tokenGenerated.readonly).toBeFalsy();
|
||||
expect(tokenGenerated.token).toMatch(/.../);
|
||||
expect(_.isString(tokenGenerated.created)).toBeTruthy();
|
||||
|
||||
expect(objects).toHaveLength(1);
|
||||
const [tokenGenerated] = objects;
|
||||
expect(tokenGenerated.user).toEqual(credentials.name);
|
||||
expect(tokenGenerated.readonly).toBeFalsy();
|
||||
expect(tokenGenerated.token).toMatch(/.../);
|
||||
expect(_.isString(tokenGenerated.created)).toBeTruthy();
|
||||
|
||||
// we don't support pagination yet
|
||||
expect(urls.next).toEqual('');
|
||||
done();
|
||||
});
|
||||
// we don't support pagination yet
|
||||
expect(urls.next).toEqual('');
|
||||
resolve(urls);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should delete a token', async (done) => {
|
||||
test('should delete a token', async () => {
|
||||
const res = await generateTokenCLI(app, token, {
|
||||
password: credentials.password,
|
||||
readonly: false,
|
||||
@ -162,43 +162,42 @@ describe('endpoint unit test', () => {
|
||||
const t = res[1].body.token;
|
||||
|
||||
await deleteTokenCLI(app, token, t);
|
||||
return new Promise((resolve, reject) => {
|
||||
request(app)
|
||||
.get('/-/npm/v1/tokens')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
request(app)
|
||||
.get('/-/npm/v1/tokens')
|
||||
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// FIXME: enable these checks
|
||||
// const { objects } = resp.body;
|
||||
// expect(objects).toHaveLength(0);
|
||||
done();
|
||||
});
|
||||
// FIXME: enable these checks
|
||||
// const { objects } = resp.body;
|
||||
// expect(objects).toHaveLength(0);
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('handle errors', () => {
|
||||
test('should fail with wrong credentials', async (done) => {
|
||||
test('should fail with wrong credentials', async () => {
|
||||
try {
|
||||
await generateTokenCLI(app, token, {
|
||||
password: 'wrongPassword',
|
||||
readonly: false,
|
||||
cidr_whitelist: [],
|
||||
});
|
||||
done();
|
||||
} catch (e) {
|
||||
const [err, body] = e;
|
||||
expect(err).not.toBeNull();
|
||||
expect(body.error).toEqual(API_ERROR.BAD_USERNAME_PASSWORD);
|
||||
expect(body.status).toEqual(HTTP_STATUS.UNAUTHORIZED);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
test('should fail if readonly is missing', async (done) => {
|
||||
test('should fail if readonly is missing', async () => {
|
||||
try {
|
||||
const res = await generateTokenCLI(app, token, {
|
||||
password: credentials.password,
|
||||
@ -207,13 +206,12 @@ describe('endpoint unit test', () => {
|
||||
|
||||
expect(res[0]).toBeNull();
|
||||
expect(res[1].body.error).toEqual(SUPPORT_ERRORS.PARAMETERS_NOT_VALID);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
return Promise.reject(e);
|
||||
}
|
||||
});
|
||||
|
||||
test('should fail if cidr_whitelist is missing', async (done) => {
|
||||
test('should fail if cidr_whitelist is missing', async () => {
|
||||
try {
|
||||
const res = await generateTokenCLI(app, token, {
|
||||
password: credentials.password,
|
||||
@ -222,9 +220,8 @@ describe('endpoint unit test', () => {
|
||||
|
||||
expect(res[0]).toBeNull();
|
||||
expect(res[1].body.error).toEqual(SUPPORT_ERRORS.PARAMETERS_NOT_VALID);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
return Promise.reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ describe('endpoint web unit test', () => {
|
||||
let app;
|
||||
let mockRegistry;
|
||||
|
||||
beforeAll(async (done) => {
|
||||
beforeAll(async () => {
|
||||
const store = generateRamdonStorage();
|
||||
const mockServerPort = 55523;
|
||||
const configForTest = configExample(
|
||||
@ -37,15 +37,12 @@ describe('endpoint web unit test', () => {
|
||||
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
||||
const storePath = path.join(__dirname, '/mock/store');
|
||||
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
afterAll(function () {
|
||||
const [registry, pid] = mockRegistry;
|
||||
registry.stop();
|
||||
logger.info(`registry ${pid} has been stopped`);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Registry WebUI endpoints', () => {
|
||||
@ -64,85 +61,97 @@ describe('endpoint web unit test', () => {
|
||||
});
|
||||
|
||||
describe('Packages', () => {
|
||||
test('should display sidebar info', (done) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/pk1-test')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function (err, res) {
|
||||
// console.log("-->", res);
|
||||
// expect(err).toBeNull();
|
||||
test('should display sidebar info', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/pk1-test')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function (err, res) {
|
||||
// console.log("-->", res);
|
||||
// expect(err).toBeNull();
|
||||
|
||||
const sideBarInfo = res.body;
|
||||
const latestVersion = publishMetadata.versions[publishMetadata[DIST_TAGS].latest];
|
||||
const sideBarInfo = res.body;
|
||||
const latestVersion = publishMetadata.versions[publishMetadata[DIST_TAGS].latest];
|
||||
|
||||
expect(sideBarInfo.latest.author).toBeDefined();
|
||||
expect(sideBarInfo.latest.author.avatar).toMatch(/www.gravatar.com/);
|
||||
expect(sideBarInfo.latest.author.name).toBe(latestVersion.author.name);
|
||||
expect(sideBarInfo.latest.author.email).toBe(latestVersion.author.email);
|
||||
done();
|
||||
});
|
||||
expect(sideBarInfo.latest.author).toBeDefined();
|
||||
expect(sideBarInfo.latest.author.avatar).toMatch(/www.gravatar.com/);
|
||||
expect(sideBarInfo.latest.author.name).toBe(latestVersion.author.name);
|
||||
expect(sideBarInfo.latest.author.email).toBe(latestVersion.author.email);
|
||||
resolve(sideBarInfo);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should display sidebar info by version', (done) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/pk1-test?v=1.0.6')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function (err, res) {
|
||||
const sideBarInfo = res.body;
|
||||
const latestVersion = publishMetadata.versions[publishMetadata[DIST_TAGS].latest];
|
||||
test('should display sidebar info by version', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/pk1-test?v=1.0.6')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function (err, res) {
|
||||
const sideBarInfo = res.body;
|
||||
const latestVersion = publishMetadata.versions[publishMetadata[DIST_TAGS].latest];
|
||||
|
||||
expect(sideBarInfo.latest.author).toBeDefined();
|
||||
expect(sideBarInfo.latest.author.avatar).toMatch(/www.gravatar.com/);
|
||||
expect(sideBarInfo.latest.author.name).toBe(latestVersion.author.name);
|
||||
expect(sideBarInfo.latest.author.email).toBe(latestVersion.author.email);
|
||||
done();
|
||||
});
|
||||
expect(sideBarInfo.latest.author).toBeDefined();
|
||||
expect(sideBarInfo.latest.author.avatar).toMatch(/www.gravatar.com/);
|
||||
expect(sideBarInfo.latest.author.name).toBe(latestVersion.author.name);
|
||||
expect(sideBarInfo.latest.author.email).toBe(latestVersion.author.email);
|
||||
resolve(sideBarInfo);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should display sidebar info 404', (done) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/404')
|
||||
.expect(HTTP_STATUS.NOT_FOUND)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function () {
|
||||
done();
|
||||
});
|
||||
test('should display sidebar info 404', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/404')
|
||||
.expect(HTTP_STATUS.NOT_FOUND)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function () {
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should display sidebar info 404 with version', (done) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/pk1-test?v=0.0.0-not-found')
|
||||
.expect(HTTP_STATUS.NOT_FOUND)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function () {
|
||||
done();
|
||||
});
|
||||
test('should display sidebar info 404 with version', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/sidebar/@scope/pk1-test?v=0.0.0-not-found')
|
||||
.expect(HTTP_STATUS.NOT_FOUND)
|
||||
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||
.end(function () {
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Search', () => {
|
||||
test('should find @scope/pk1-test', (done) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/search/@scope%2fpk1-test')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
expect(res.body).toHaveLength(1);
|
||||
done();
|
||||
});
|
||||
test('should find @scope/pk1-test', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/search/@scope%2fpk1-test')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (_err, res) {
|
||||
expect(res.body).toHaveLength(1);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should not find forbidden-place', (done) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/search/forbidden-place')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
// this is expected since we are not logged
|
||||
// and forbidden-place is allow_access: 'nobody'
|
||||
expect(res.body).toHaveLength(0);
|
||||
done();
|
||||
});
|
||||
test('should not find forbidden-place', () => {
|
||||
return new Promise((resolve) => {
|
||||
request(app)
|
||||
.get('/-/verdaccio/search/forbidden-place')
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.end(function (err, res) {
|
||||
// this is expected since we are not logged
|
||||
// and forbidden-place is allow_access: 'nobody'
|
||||
expect(res.body).toHaveLength(0);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -143,7 +143,7 @@ describe('LocalStorage', () => {
|
||||
});
|
||||
|
||||
describe('LocalStorage::mergeTags', () => {
|
||||
test('should mergeTags', async (done) => {
|
||||
test('should mergeTags', async () => {
|
||||
const pkgName = 'merge-tags-test-1';
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
await addNewVersion(pkgName, '1.0.0');
|
||||
@ -154,19 +154,21 @@ describe('LocalStorage', () => {
|
||||
latest: '2.0.0',
|
||||
};
|
||||
|
||||
storage.mergeTags(pkgName, tags, async (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
const metadata: Package = await getPackageMetadataFromStore(pkgName);
|
||||
expect(metadata[DIST_TAGS]).toBeDefined();
|
||||
expect(metadata[DIST_TAGS]['beta']).toBeDefined();
|
||||
expect(metadata[DIST_TAGS]['beta']).toBe('3.0.0');
|
||||
expect(metadata[DIST_TAGS]['latest']).toBe('2.0.0');
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
storage.mergeTags(pkgName, tags, async (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
const metadata: Package = await getPackageMetadataFromStore(pkgName);
|
||||
expect(metadata[DIST_TAGS]).toBeDefined();
|
||||
expect(metadata[DIST_TAGS]['beta']).toBeDefined();
|
||||
expect(metadata[DIST_TAGS]['beta']).toBe('3.0.0');
|
||||
expect(metadata[DIST_TAGS]['latest']).toBe('2.0.0');
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails mergeTags version not found', async (done) => {
|
||||
test('should fails mergeTags version not found', async () => {
|
||||
const pkgName = 'merge-tags-test-1';
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
// const tarballName: string = `${pkgName}-${version}.tgz`;
|
||||
@ -177,21 +179,23 @@ describe('LocalStorage', () => {
|
||||
beta: '9999.0.0',
|
||||
};
|
||||
|
||||
storage.mergeTags(pkgName, tags, async (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND);
|
||||
expect(err.message).toMatch(API_ERROR.VERSION_NOT_EXIST);
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
storage.mergeTags(pkgName, tags, async (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND);
|
||||
expect(err.message).toMatch(API_ERROR.VERSION_NOT_EXIST);
|
||||
resolve(tags);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on mergeTags', async (done) => {
|
||||
test('should fails on mergeTags', (done) => {
|
||||
const tags: MergeTags = {
|
||||
beta: '3.0.0',
|
||||
latest: '2.0.0',
|
||||
};
|
||||
|
||||
storage.mergeTags('not-found', tags, async (err) => {
|
||||
storage.mergeTags('not-found', tags, (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.NOT_FOUND);
|
||||
expect(err.message).toMatch(API_ERROR.NO_PACKAGE);
|
||||
@ -201,7 +205,7 @@ describe('LocalStorage', () => {
|
||||
});
|
||||
|
||||
describe('LocalStorage::addVersion', () => {
|
||||
test('should add new version without tag', async (done) => {
|
||||
test('should add new version without tag', async () => {
|
||||
const pkgName = 'add-version-test-1';
|
||||
const version = '1.0.1';
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
@ -210,72 +214,79 @@ describe('LocalStorage', () => {
|
||||
await addTarballToStore(pkgName, `${pkgName}-9.0.0.tgz`);
|
||||
await addTarballToStore(pkgName, tarballName);
|
||||
|
||||
storage.addVersion(
|
||||
pkgName,
|
||||
version,
|
||||
generateNewVersion(pkgName, version),
|
||||
'',
|
||||
(err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
return new Promise((resolve) => {
|
||||
storage.addVersion(
|
||||
pkgName,
|
||||
version,
|
||||
generateNewVersion(pkgName, version),
|
||||
'',
|
||||
(err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
resolve(data);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails on add a duplicated version without tag', async (done) => {
|
||||
test('should fails on add a duplicated version without tag', async () => {
|
||||
const pkgName = 'add-version-test-2';
|
||||
const version = '1.0.1';
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
await addNewVersion(pkgName, version);
|
||||
|
||||
storage.addVersion(pkgName, version, generateNewVersion(pkgName, version), '', (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.CONFLICT);
|
||||
expect(err.message).toMatch(API_ERROR.PACKAGE_EXIST);
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
storage.addVersion(pkgName, version, generateNewVersion(pkgName, version), '', (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.CONFLICT);
|
||||
expect(err.message).toMatch(API_ERROR.PACKAGE_EXIST);
|
||||
resolve(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fails add new version wrong shasum', async (done) => {
|
||||
test('should fails add new version wrong shasum', async () => {
|
||||
const pkgName = 'add-version-test-4';
|
||||
const version = '4.0.0';
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
const tarballName = `${pkgName}-${version}.tgz`;
|
||||
await addTarballToStore(pkgName, tarballName);
|
||||
|
||||
storage.addVersion(
|
||||
pkgName,
|
||||
version,
|
||||
generateNewVersion(pkgName, version, 'fake'),
|
||||
'',
|
||||
(err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.BAD_REQUEST);
|
||||
expect(err.message).toMatch(/shasum error/);
|
||||
done();
|
||||
}
|
||||
);
|
||||
return new Promise((resolve) => {
|
||||
storage.addVersion(
|
||||
pkgName,
|
||||
version,
|
||||
generateNewVersion(pkgName, version, 'fake'),
|
||||
'',
|
||||
(err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toEqual(HTTP_STATUS.BAD_REQUEST);
|
||||
expect(err.message).toMatch(/shasum error/);
|
||||
resolve(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('should add new second version without tag', async (done) => {
|
||||
test('should add new second version without tag', async () => {
|
||||
const pkgName = 'add-version-test-3';
|
||||
const version = '1.0.2';
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
await addNewVersion(pkgName, '1.0.1');
|
||||
await addNewVersion(pkgName, '1.0.3');
|
||||
|
||||
storage.addVersion(
|
||||
pkgName,
|
||||
version,
|
||||
generateNewVersion(pkgName, version),
|
||||
'beta',
|
||||
(err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
done();
|
||||
}
|
||||
);
|
||||
return new Promise((resolve) => {
|
||||
storage.addVersion(
|
||||
pkgName,
|
||||
version,
|
||||
generateNewVersion(pkgName, version),
|
||||
'beta',
|
||||
(err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data).toBeUndefined();
|
||||
resolve(data);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -284,21 +295,24 @@ describe('LocalStorage', () => {
|
||||
const pkgName = 'add-update-versions-test-1';
|
||||
const version = '1.0.2';
|
||||
let _storage;
|
||||
beforeEach(async (done) => {
|
||||
beforeEach(async () => {
|
||||
class MockLocalStorage extends LocalStorage {}
|
||||
// @ts-ignore
|
||||
MockLocalStorage.prototype._writePackage = jest.fn(LocalStorage.prototype._writePackage);
|
||||
_storage = getStorage(MockLocalStorage);
|
||||
await _storage.init();
|
||||
rimRaf(path.join(configExample().storage, pkgName), async () => {
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
await addNewVersion(pkgName, '1.0.1');
|
||||
await addNewVersion(pkgName, version);
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
// @ts-expect-error
|
||||
rimRaf(path.join(configExample().storage, pkgName), async () => {
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
await addNewVersion(pkgName, '1.0.1');
|
||||
await addNewVersion(pkgName, version);
|
||||
resolve(pkgName);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should update versions from external source', async (done) => {
|
||||
test('should update versions from external source', (done) => {
|
||||
_storage.updateVersions(pkgName, metadata, (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(_storage._writePackage).toHaveBeenCalledTimes(1);
|
||||
@ -332,7 +346,7 @@ describe('LocalStorage', () => {
|
||||
describe('LocalStorage::changePackage', () => {
|
||||
const pkgName = 'change-package';
|
||||
|
||||
test('should unpublish a version', async (done) => {
|
||||
test('should unpublish a version', async () => {
|
||||
await addPackageToStore(pkgName, generatePackageTemplate(pkgName));
|
||||
await addNewVersion(pkgName, '1.0.1');
|
||||
await addNewVersion(pkgName, '1.0.2');
|
||||
@ -340,14 +354,16 @@ describe('LocalStorage', () => {
|
||||
const metadata = JSON.parse(readMetadata('changePackage/metadata-change'));
|
||||
const rev: string = metadata['_rev'];
|
||||
|
||||
storage.changePackage(pkgName, metadata, rev, (err) => {
|
||||
expect(err).toBeUndefined();
|
||||
storage.getPackageMetadata(pkgName, (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data.versions['1.0.1']).toBeDefined();
|
||||
expect(data.versions['1.0.2']).toBeUndefined();
|
||||
expect(data.versions['1.0.3']).toBeUndefined();
|
||||
done();
|
||||
return new Promise((resolve) => {
|
||||
storage.changePackage(pkgName, metadata, rev, (err) => {
|
||||
expect(err).toBeUndefined();
|
||||
storage.getPackageMetadata(pkgName, (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
expect(data.versions['1.0.1']).toBeDefined();
|
||||
expect(data.versions['1.0.2']).toBeUndefined();
|
||||
expect(data.versions['1.0.3']).toBeUndefined();
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -468,7 +484,7 @@ describe('LocalStorage', () => {
|
||||
expect(contentLength).toBe(279);
|
||||
done();
|
||||
});
|
||||
stream.on('open', function () {
|
||||
stream.on('end', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -485,14 +501,11 @@ describe('LocalStorage', () => {
|
||||
});
|
||||
|
||||
describe('LocalStorage::search', () => {
|
||||
test('should find a tarball', (done) => {
|
||||
// FIXME: flacky test, review
|
||||
test.skip('should find a tarball', (done) => {
|
||||
// @ts-ignore
|
||||
const stream = storage.search('99999');
|
||||
|
||||
stream.on('data', function each(pkg) {
|
||||
expect(pkg.name).toEqual(pkgName);
|
||||
});
|
||||
|
||||
stream.on('error', function (err) {
|
||||
expect(err).not.toBeNull();
|
||||
done();
|
||||
|
@ -1,4 +1,3 @@
|
||||
import assert from 'assert';
|
||||
import { semverSort } from '@verdaccio/utils';
|
||||
import { setup } from '@verdaccio/logger';
|
||||
|
||||
@ -16,7 +15,7 @@ describe('Storage._merge_versions versions', () => {
|
||||
// @ts-ignore
|
||||
mergeVersions(pkg, { versions: { a: 2, q: 2 } });
|
||||
|
||||
assert.deepEqual(pkg, {
|
||||
expect(pkg).toStrictEqual({
|
||||
versions: { a: 1, b: 1, c: 1, q: 2 },
|
||||
'dist-tags': {},
|
||||
});
|
||||
@ -31,7 +30,7 @@ describe('Storage._merge_versions versions', () => {
|
||||
// @ts-ignore
|
||||
mergeVersions(pkg, { 'dist-tags': { q: '2.2.2', w: '3.3.3', t: '4.4.4' } });
|
||||
|
||||
assert.deepEqual(pkg, {
|
||||
expect(pkg).toStrictEqual({
|
||||
versions: {},
|
||||
'dist-tags': { q: '2.2.2', w: '3.3.3', t: '4.4.4' },
|
||||
});
|
||||
@ -51,14 +50,14 @@ describe('Storage._merge_versions versions', () => {
|
||||
// @ts-ignore
|
||||
mergeVersions(pkg, { 'dist-tags': { q: '1.1.2', w: '3.3.3', t: '4.4.4' } });
|
||||
|
||||
assert.deepEqual(pkg, {
|
||||
expect(pkg).toStrictEqual({
|
||||
versions: {},
|
||||
'dist-tags': { q: '1.1.10', w: '3.3.3', t: '4.4.4' },
|
||||
});
|
||||
});
|
||||
|
||||
test('semverSort', () => {
|
||||
assert.deepEqual(semverSort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b']), [
|
||||
expect(semverSort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b'])).toStrictEqual([
|
||||
'1.2.3a',
|
||||
'1.2.3-b',
|
||||
'1.2.3c',
|
||||
|
1708
pnpm-lock.yaml
generated
1708
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -13,7 +13,7 @@ class E2ECliTestEnvironment extends NodeEnvironment {
|
||||
super(config);
|
||||
}
|
||||
|
||||
async setup() {
|
||||
public async setup() {
|
||||
// create an unique suite location peer test to avoid conflicts
|
||||
const tempRoot = fs.mkdtempSync(
|
||||
path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-suite-test-')
|
||||
@ -29,7 +29,7 @@ class E2ECliTestEnvironment extends NodeEnvironment {
|
||||
// TODO: clean folder
|
||||
}
|
||||
|
||||
runScript(script): any {
|
||||
public runScript(script): any {
|
||||
return super.runScript(script);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user