fix: new publish with token should add user to maintainers (#1662)
* fix: new publish with token should add user to maintainers ci: use github fix: fix _saveNpmUser * ci: github add mysql service
This commit is contained in:
52
.github/workflows/nodejs.yml
vendored
Normal file
52
.github/workflows/nodejs.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '0 2 * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: true
|
||||
MYSQL_DATABASE: cnpmjs_test
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [10, 12]
|
||||
os: [ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout Git Source
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm i -g npminstall && npminstall
|
||||
|
||||
- name: Continuous Integration
|
||||
run: npm run ci
|
||||
|
||||
- name: Code Coverage
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
10
.travis.yml
10
.travis.yml
@@ -1,10 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '10'
|
||||
- '12'
|
||||
services:
|
||||
- mysql
|
||||
- postgresql
|
||||
script: 'make test-travis-all'
|
||||
after_script:
|
||||
- 'npm i codecov && codecov'
|
||||
4
Makefile
4
Makefile
@@ -11,8 +11,8 @@ init-database:
|
||||
@NODE_ENV=test node test/init_db.js
|
||||
|
||||
init-mysql:
|
||||
@mysql -uroot -e 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
||||
@mysql -uroot -e 'CREATE DATABASE cnpmjs_test;'
|
||||
@mysql -uroot -h 127.0.0.1 --port 3306 -e 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
||||
@mysql -uroot -h 127.0.0.1 --port 3306 -e 'CREATE DATABASE cnpmjs_test;'
|
||||
|
||||
init-pg:
|
||||
@psql -c 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
||||
|
||||
@@ -102,21 +102,30 @@ module.exports = function* save(next) {
|
||||
// notice that admins can not publish to all modules
|
||||
// (but admins can add self to maintainers first)
|
||||
|
||||
var m = maintainers.filter(function (maintainer) {
|
||||
return maintainer.name === username;
|
||||
});
|
||||
|
||||
// package.json has maintainers and publisher in not in the list
|
||||
if (authorizeType === common.AuthorizeType.BEARER && m.length === 0) {
|
||||
var publisher = {
|
||||
name: this.user.name,
|
||||
email: this.user.email,
|
||||
};
|
||||
m = [ publisher ];
|
||||
maintainers.push(publisher);
|
||||
}
|
||||
|
||||
// make sure user in auth is in maintainers
|
||||
// should never happened in normal request
|
||||
if (authorizeType !== common.AuthorizeType.BEARER) {
|
||||
var m = maintainers.filter(function (maintainer) {
|
||||
return maintainer.name === username;
|
||||
});
|
||||
if (m.length === 0) {
|
||||
this.status = 403;
|
||||
const error = '[maintainers_error] ' + username + ' does not in maintainer list';
|
||||
this.body = {
|
||||
error,
|
||||
reason: error,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (m.length === 0) {
|
||||
this.status = 403;
|
||||
const error = '[maintainers_error] ' + username + ' does not in maintainer list';
|
||||
this.body = {
|
||||
error,
|
||||
reason: error,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: add this info into some table
|
||||
|
||||
@@ -697,6 +697,7 @@ function* _listStarUsers(modName) {
|
||||
}
|
||||
|
||||
function* _saveNpmUser(username) {
|
||||
var user = yield npmSerivce.getUser(username);
|
||||
if (!user) {
|
||||
var existsUser = yield User.findByName(username);
|
||||
if (existsUser && existsUser.isNpmUser) {
|
||||
|
||||
16
package.json
16
package.json
@@ -9,7 +9,8 @@
|
||||
"test-local": "make test",
|
||||
"start": "./bin/nodejsctl start && cp History.md docs/web/history.md",
|
||||
"status": "./bin/nodejsctl status",
|
||||
"stop": "./bin/nodejsctl stop"
|
||||
"stop": "./bin/nodejsctl stop",
|
||||
"ci": "make test-travis-mysql"
|
||||
},
|
||||
"bin": {
|
||||
"cnpmjs.org": "bin/cli.js"
|
||||
@@ -76,6 +77,7 @@
|
||||
"autod": "*",
|
||||
"chunkstream": "*",
|
||||
"contributors": "*",
|
||||
"egg-ci": "^1.18.0",
|
||||
"intelli-espower-loader": "^1.0.1",
|
||||
"istanbul": "*",
|
||||
"jshint": "*",
|
||||
@@ -117,5 +119,17 @@
|
||||
"fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)",
|
||||
"dead_horse <dead_horse@qq.com> (http://deadhorse.me)"
|
||||
],
|
||||
"ci": {
|
||||
"type": "github",
|
||||
"os": {
|
||||
"github": "linux, macos"
|
||||
},
|
||||
"npminstall": true,
|
||||
"version": "10, 12",
|
||||
"command": {
|
||||
"github": "ci"
|
||||
},
|
||||
"services": "mysql"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('test/controllers/registry/package/save.test.js', function () {
|
||||
describe('no @scoped package', function () {
|
||||
beforeEach(function () {
|
||||
mm(config, 'syncModel', 'all');
|
||||
mm(config, 'privatePackages', ['testmodule-new-1', 'testmodule-new-2', 'testmodule-no-latest']);
|
||||
mm(config, 'privatePackages', ['testmodule-new-1', 'testmodule-new-2', 'testmodule-no-latest', 'testmodule-new-4']);
|
||||
});
|
||||
|
||||
before(function (done) {
|
||||
@@ -228,6 +228,12 @@ describe('test/controllers/registry/package/save.test.js', function () {
|
||||
.expect(201);
|
||||
|
||||
yield tokenService.deleteToken(utils.admin, token.token);
|
||||
|
||||
var maintainers = yield packageService.listMaintainers(pkg.name);
|
||||
maintainers.should.eql([{
|
||||
name: 'cnpmjstest10',
|
||||
email: 'fengmk2@gmail.com',
|
||||
}]);
|
||||
});
|
||||
|
||||
it('should 400 when attachments missing', function (done) {
|
||||
|
||||
Reference in New Issue
Block a user