This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support package version block list (#1683)
- Loading branch information
Showing
13 changed files
with
242 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
module.exports = function (sequelize, DataTypes) { | ||
return sequelize.define('BlockPackageVersion', { | ||
name: { | ||
type: DataTypes.STRING(214), | ||
allowNull: false, | ||
comment: 'package name' | ||
}, | ||
version: { | ||
type: DataTypes.STRING(30), | ||
allowNull: false, | ||
comment: 'package version' | ||
}, | ||
reason: { | ||
type: DataTypes.LONGTEXT, | ||
comment: 'block reason', | ||
}, | ||
}, { | ||
tableName: 'package_version_blocklist', | ||
comment: 'package version block list', | ||
indexes: [ | ||
{ | ||
unique: true, | ||
fields: ['name', 'version'], | ||
}, | ||
], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,5 @@ | ||
/**! | ||
* cnpmjs.org - models/download_total.js | ||
* | ||
* Copyright(c) fengmk2 and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* fengmk2 <[email protected]> (http://fengmk2.github.com) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
// CREATE TABLE IF NOT EXISTS `downloads` ( | ||
// `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key', | ||
// `gmt_create` datetime NOT NULL COMMENT 'create time', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,5 @@ | ||
/**! | ||
* cnpmjs.org - models/total.js | ||
* | ||
* Copyright(c) fengmk2 and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* fengmk2 <[email protected]> (http://fengmk2.github.com) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
// CREATE TABLE IF NOT EXISTS `total` ( | ||
// `name` varchar(214) NOT NULL COMMENT 'total name', | ||
// `gmt_modified` datetime NOT NULL COMMENT 'modified time', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const BlockPackageVersion = require('../models').BlockPackageVersion; | ||
|
||
exports.blockPackageVersion = function* (name, version, reason) { | ||
const row = yield BlockPackageVersion.findOne({ where: { name, version } }); | ||
if (row) { | ||
row.reason = reason; | ||
yield row.save(); | ||
} else { | ||
yield BlockPackageVersion.create({ name, version, reason }); | ||
} | ||
}; | ||
|
||
exports.findBlockPackageVersions = function* (name) { | ||
if (!BlockPackageVersion) { | ||
return null; | ||
} | ||
const rows = yield BlockPackageVersion.findAll({ where: { name } }); | ||
if (rows.length === 0) { | ||
return null; | ||
} | ||
const blocks = {}; | ||
for (const row of rows) { | ||
blocks[row.version] = row; | ||
} | ||
return blocks; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
'use strict'; | ||
|
||
var should = require('should'); | ||
var assert = require('assert'); | ||
var request = require('supertest'); | ||
var mm = require('mm'); | ||
var config = require('../../../../config'); | ||
var app = require('../../../../servers/web'); | ||
var registry = require('../../../../servers/registry'); | ||
var blocklistService = require('../../../../services/blocklist'); | ||
var utils = require('../../../utils'); | ||
|
||
describe('test/controllers/web/package/show.test.js', () => { | ||
|
@@ -55,6 +57,41 @@ describe('test/controllers/web/package/show.test.js', () => { | |
}); | ||
}); | ||
|
||
it('should get block package', function* () { | ||
var pkg = utils.getPackage('@cnpmtest/testmodule-web-show-block', '0.0.1', utils.admin); | ||
pkg.versions['0.0.1'].dependencies = { | ||
bytetest: '~0.0.1', | ||
mocha: '~1.0.0', | ||
'testmodule-web-show': '0.0.1' | ||
}; | ||
yield request(registry) | ||
.put('/' + pkg.name) | ||
.set('authorization', utils.adminAuth) | ||
.send(pkg) | ||
.expect(201); | ||
|
||
yield blocklistService.blockPackageVersion('@cnpmtest/testmodule-web-show-block', '0.0.1', 'unittest'); | ||
let res = yield request(app) | ||
.get('/package/@cnpmtest/testmodule-web-show-block') | ||
.expect(451) | ||
.expect('content-type', 'text/plain; charset=utf-8'); | ||
assert(res.text === '[block] [email protected] was blocked, reason: unittest'); | ||
|
||
yield blocklistService.blockPackageVersion('@cnpmtest/testmodule-web-show-block', '0.0.1', 'unittest'); | ||
res = yield request(app) | ||
.get('/package/@cnpmtest/testmodule-web-show-block/0.0.1') | ||
.expect(451) | ||
.expect('content-type', 'text/plain; charset=utf-8'); | ||
assert(res.text === '[block] [email protected] was blocked, reason: unittest'); | ||
|
||
yield blocklistService.blockPackageVersion('@cnpmtest/testmodule-web-show-block', '*', 'block all'); | ||
res = yield request(app) | ||
.get('/package/@cnpmtest/testmodule-web-show-block') | ||
.expect(451) | ||
.expect('content-type', 'text/plain; charset=utf-8'); | ||
assert(res.text === '[block] [email protected] was blocked, reason: block all'); | ||
}); | ||
|
||
it('should get scoped package', function (done) { | ||
request(app) | ||
.get('/package/@cnpmtest/testmodule-web-show') | ||
|
Oops, something went wrong.