mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
test: use promisified supertest-like asserts
This commit is contained in:
parent
6cb257e51f
commit
17bdfd904a
19 changed files with 694 additions and 701 deletions
|
@ -55,6 +55,7 @@ devDependencies:
|
|||
# Tools required for testing
|
||||
#
|
||||
rimraf: '>=2.2.5 <3.0.0-0'
|
||||
bluebird: '2 >=2.9'
|
||||
|
||||
mocha: '2 >=2.2.3'
|
||||
|
||||
|
|
|
@ -1,58 +1,46 @@
|
|||
var assert = require('assert')
|
||||
|
||||
function readfile(x) {
|
||||
return require('fs').readFileSync(__dirname + '/' + x)
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = function () {
|
||||
var server = process.server
|
||||
|
||||
it('add tag - 404', function(cb) {
|
||||
server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('add tag - 404', function () {
|
||||
return server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1')
|
||||
.status(404)
|
||||
.body_error(/no such package/)
|
||||
})
|
||||
|
||||
describe('addtag', function() {
|
||||
before(function(cb) {
|
||||
server.put_package('testpkg-tag', eval(
|
||||
'(' + readfile('fixtures/publish.json5')
|
||||
.toString('utf8')
|
||||
.replace(/__NAME__/g, 'testpkg-tag')
|
||||
.replace(/__VERSION__/g, '0.0.1')
|
||||
+ ')'
|
||||
), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_package('testpkg-tag', eval(
|
||||
'(' + readfile('fixtures/publish.json5')
|
||||
.toString('utf8')
|
||||
.replace(/__NAME__/g, 'testpkg-tag')
|
||||
.replace(/__VERSION__/g, '0.0.1')
|
||||
+ ')'
|
||||
)).status(201)
|
||||
})
|
||||
|
||||
it('add testpkg-tag', function(){})
|
||||
|
||||
it('add tag - bad ver', function(cb) {
|
||||
server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1-x', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('version doesn\'t exist'))
|
||||
cb()
|
||||
})
|
||||
it('add tag - bad ver', function () {
|
||||
return server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1-x')
|
||||
.status(404)
|
||||
.body_error(/version doesn't exist/)
|
||||
})
|
||||
|
||||
it('add tag - bad tag', function(cb) {
|
||||
server.add_tag('testpkg-tag', 'tag/tag/tag', '0.0.1-x', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(~body.error.indexOf('invalid tag'))
|
||||
cb()
|
||||
})
|
||||
it('add tag - bad tag', function () {
|
||||
return server.add_tag('testpkg-tag', 'tag/tag/tag', '0.0.1-x')
|
||||
.status(403)
|
||||
.body_error(/invalid tag/)
|
||||
})
|
||||
|
||||
it('add tag - good', function(cb) {
|
||||
server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1', function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('tagged'))
|
||||
cb()
|
||||
})
|
||||
it('add tag - good', function () {
|
||||
return server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1')
|
||||
.status(201)
|
||||
.body_ok(/tagged/)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var assert = require('assert')
|
||||
var Server = require('./lib/server')
|
||||
|
||||
module.exports = function() {
|
||||
|
@ -7,30 +6,24 @@ module.exports = function() {
|
|||
describe('adduser', function() {
|
||||
var user = String(Math.random())
|
||||
var pass = String(Math.random())
|
||||
before(function(cb) {
|
||||
server.auth(user, pass, function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(body.ok.match(/user .* created/))
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.auth(user, pass)
|
||||
.status(201)
|
||||
.body_ok(/user .* created/)
|
||||
})
|
||||
|
||||
it('creating new user', function(){})
|
||||
|
||||
it('should log in', function(cb) {
|
||||
server.auth(user, pass, function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(body.ok.match(/you are authenticated as/))
|
||||
cb()
|
||||
})
|
||||
it('should log in', function () {
|
||||
return server.auth(user, pass)
|
||||
.status(201)
|
||||
.body_ok(/you are authenticated as/)
|
||||
})
|
||||
|
||||
it('should not register more users', function(cb) {
|
||||
server.auth(String(Math.random()), String(Math.random()), function(res, body) {
|
||||
assert.equal(res.statusCode, 409)
|
||||
assert(body.error.match(/maximum amount of users reached/))
|
||||
cb()
|
||||
})
|
||||
it('should not register more users', function () {
|
||||
return server.auth(String(Math.random()), String(Math.random()))
|
||||
.status(409)
|
||||
.body_error(/maximum amount of users reached/)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,132 +7,112 @@ function readfile(x) {
|
|||
return require('fs').readFileSync(__dirname + '/' + x)
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = function () {
|
||||
var server = process.server
|
||||
var server2 = process.server2
|
||||
|
||||
it('trying to fetch non-existent package', function(cb) {
|
||||
server.get_package('testpkg', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('trying to fetch non-existent package', function () {
|
||||
return server.get_package('testpkg').status(404).body_error(/no such package/)
|
||||
})
|
||||
|
||||
describe('testpkg', function() {
|
||||
before(server.add_package.bind(server, 'testpkg'))
|
||||
|
||||
it('creating new package', function(){/* test for before() */})
|
||||
|
||||
it('downloading non-existent tarball', function(cb) {
|
||||
server.get_tarball('testpkg', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such file'))
|
||||
cb()
|
||||
})
|
||||
describe('testpkg', function () {
|
||||
before(function () {
|
||||
return server.add_package('testpkg')
|
||||
})
|
||||
|
||||
it('uploading incomplete tarball', function(cb) {
|
||||
server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000, function(res, body) {
|
||||
cb()
|
||||
})
|
||||
it('creating new package', function (){/* test for before() */})
|
||||
|
||||
it('downloading non-existent tarball', function () {
|
||||
return server.get_tarball('testpkg', 'blahblah').status(404).body_error(/no such file/)
|
||||
})
|
||||
|
||||
describe('tarball', function() {
|
||||
before(function(cb) {
|
||||
server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(body.ok)
|
||||
cb()
|
||||
})
|
||||
it('uploading incomplete tarball', function () {
|
||||
return server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000)
|
||||
})
|
||||
|
||||
describe('tarball', function () {
|
||||
before(function () {
|
||||
return server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'))
|
||||
.status(201)
|
||||
.body_ok(/.*/)
|
||||
})
|
||||
|
||||
it('uploading new tarball', function(){/* test for before() */})
|
||||
it('uploading new tarball', function (){/* test for before() */})
|
||||
|
||||
it('downloading newly created tarball', function(cb) {
|
||||
server.get_tarball('testpkg', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
cb()
|
||||
})
|
||||
it('downloading newly created tarball', function () {
|
||||
return server.get_tarball('testpkg', 'blahblah')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
})
|
||||
})
|
||||
|
||||
it('uploading new package version (bad sha)', function(cb) {
|
||||
it('uploading new package version (bad sha)', function () {
|
||||
var pkg = require('./lib/package')('testpkg')
|
||||
pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex')
|
||||
server.put_version('testpkg', '0.0.1', pkg, function(res, body) {
|
||||
assert.equal(res.statusCode, 400)
|
||||
assert(~body.error.indexOf('shasum error'))
|
||||
cb()
|
||||
})
|
||||
|
||||
return server.put_version('testpkg', '0.0.1', pkg)
|
||||
.status(400)
|
||||
.body_error(/shasum error/)
|
||||
})
|
||||
|
||||
describe('version', function() {
|
||||
before(function(cb) {
|
||||
describe('version', function () {
|
||||
before(function () {
|
||||
var pkg = require('./lib/package')('testpkg')
|
||||
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
|
||||
server.put_version('testpkg', '0.0.1', pkg, function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('published'))
|
||||
cb()
|
||||
})
|
||||
return server.put_version('testpkg', '0.0.1', pkg)
|
||||
.status(201)
|
||||
.body_ok(/published/)
|
||||
})
|
||||
|
||||
it('uploading new package version', function(){/* test for before() */})
|
||||
it('uploading new package version', function (){/* test for before() */})
|
||||
|
||||
it('downloading newly created package', function(cb) {
|
||||
server.get_package('testpkg', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
||||
cb()
|
||||
})
|
||||
it('downloading newly created package', function () {
|
||||
return server.get_package('testpkg')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
||||
})
|
||||
})
|
||||
|
||||
it('downloading package via server2', function(cb) {
|
||||
server2.get_package('testpkg', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
||||
cb()
|
||||
})
|
||||
it('downloading package via server2', function () {
|
||||
return server2.get_package('testpkg')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].name, 'testpkg')
|
||||
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('uploading new package version for bad pkg', function(cb) {
|
||||
server.put_version('testpxg', '0.0.1', require('./lib/package')('testpxg'), function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('uploading new package version for bad pkg', function () {
|
||||
return server.put_version('testpxg', '0.0.1', require('./lib/package')('testpxg'))
|
||||
.status(404)
|
||||
.body_error(/no such package/)
|
||||
})
|
||||
|
||||
it('doubleerr test', function(cb) {
|
||||
server.put_tarball('testfwd2', 'blahblah', readfile('fixtures/binary'), function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(body.error)
|
||||
cb()
|
||||
})
|
||||
it('doubleerr test', function () {
|
||||
return server.put_tarball('testfwd2', 'blahblah', readfile('fixtures/binary'))
|
||||
.status(404)
|
||||
.body_error(/no such/)
|
||||
})
|
||||
|
||||
it('publishing package / bad ro uplink', function(cb) {
|
||||
server.put_package('baduplink', require('./lib/package')('baduplink'), function(res, body) {
|
||||
assert.equal(res.statusCode, 503)
|
||||
assert(~body.error.indexOf('one of the uplinks is down, refuse to publish'))
|
||||
cb()
|
||||
})
|
||||
it('publishing package / bad ro uplink', function () {
|
||||
return server.put_package('baduplink', require('./lib/package')('baduplink'))
|
||||
.status(503)
|
||||
.body_error(/one of the uplinks is down, refuse to publish/)
|
||||
})
|
||||
|
||||
it('who am I?', function(cb) {
|
||||
server.whoami(function(username) {
|
||||
it('who am I?', function () {
|
||||
return server.whoami().then(function (username) {
|
||||
assert.equal(username, 'test')
|
||||
cb()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,63 +9,53 @@ module.exports = function() {
|
|||
var server = process.server
|
||||
var server2 = process.server2
|
||||
|
||||
it('downloading non-existent tarball #1 / srv2', function(cb) {
|
||||
server2.get_tarball('testpkg-gh29', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('downloading non-existent tarball #1 / srv2', function () {
|
||||
return server2.get_tarball('testpkg-gh29', 'blahblah')
|
||||
.status(404)
|
||||
.body_error(/no such package/)
|
||||
})
|
||||
|
||||
describe('pkg-gh29', function() {
|
||||
before(function(cb) {
|
||||
server.put_package('testpkg-gh29', require('./lib/package')('testpkg-gh29'), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('created new package'))
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_package('testpkg-gh29', require('./lib/package')('testpkg-gh29'))
|
||||
.status(201)
|
||||
.body_ok(/created new package/)
|
||||
})
|
||||
|
||||
it('creating new package / srv1', function(){})
|
||||
|
||||
it('downloading non-existent tarball #2 / srv2', function(cb) {
|
||||
server2.get_tarball('testpkg-gh29', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such file'))
|
||||
cb()
|
||||
})
|
||||
it('downloading non-existent tarball #2 / srv2', function () {
|
||||
return server2.get_tarball('testpkg-gh29', 'blahblah')
|
||||
.status(404)
|
||||
.body_error(/no such file/)
|
||||
})
|
||||
|
||||
describe('tarball', function() {
|
||||
before(function(cb) {
|
||||
server.put_tarball('testpkg-gh29', 'blahblah', readfile('fixtures/binary'), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(body.ok)
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_tarball('testpkg-gh29', 'blahblah', readfile('fixtures/binary'))
|
||||
.status(201)
|
||||
.body_ok(/.*/)
|
||||
})
|
||||
|
||||
it('uploading new tarball / srv1', function(){})
|
||||
|
||||
describe('pkg version', function() {
|
||||
before(function(cb) {
|
||||
before(function () {
|
||||
var pkg = require('./lib/package')('testpkg-gh29')
|
||||
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
|
||||
server.put_version('testpkg-gh29', '0.0.1', pkg, function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('published'))
|
||||
cb()
|
||||
})
|
||||
return server.put_version('testpkg-gh29', '0.0.1', pkg)
|
||||
.status(201)
|
||||
.body_ok(/published/)
|
||||
})
|
||||
|
||||
it('uploading new package version / srv1', function(){})
|
||||
|
||||
it('downloading newly created tarball / srv2', function(cb) {
|
||||
server2.get_tarball('testpkg-gh29', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
cb()
|
||||
})
|
||||
it('downloading newly created tarball / srv2', function () {
|
||||
return server2.get_tarball('testpkg-gh29', 'blahblah')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require('./lib/startup')
|
||||
|
||||
var assert = require('assert')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
function readfile(x) {
|
||||
return require('fs').readFileSync(__dirname + '/' + x)
|
||||
|
@ -46,46 +47,50 @@ module.exports = function() {
|
|||
})
|
||||
})
|
||||
|
||||
it('should not fail on bad gzip', function(cb) {
|
||||
server.get_package('testexp_baddata', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
cb()
|
||||
})
|
||||
it('should not fail on bad gzip', function () {
|
||||
return server.get_package('testexp_baddata')
|
||||
.status(404)
|
||||
})
|
||||
|
||||
it('should understand gzipped data from uplink', function(cb) {
|
||||
server.get_package('testexp_gzip', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(res.headers['content-encoding'], undefined)
|
||||
assert.equal(body.name, 'testexp_gzip')
|
||||
assert.equal(Object.keys(body.versions).length, 9)
|
||||
cb()
|
||||
})
|
||||
it('should understand gzipped data from uplink', function () {
|
||||
return server.get_package('testexp_gzip')
|
||||
.status(200)
|
||||
.response(function (res) {
|
||||
assert.equal(res.headers['content-encoding'], undefined)
|
||||
})
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, 'testexp_gzip')
|
||||
assert.equal(Object.keys(body.versions).length, 9)
|
||||
})
|
||||
})
|
||||
|
||||
it('should serve gzipped data', function(cb) {
|
||||
server.request({
|
||||
it('should serve gzipped data', function () {
|
||||
return server.request({
|
||||
uri: '/testexp_gzip',
|
||||
encoding: null,
|
||||
headers: {
|
||||
'Accept-encoding': 'gzip',
|
||||
},
|
||||
json: false,
|
||||
}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(res.headers['content-encoding'], 'gzip')
|
||||
assert.throws(function() {
|
||||
JSON.parse(body.toString('utf8'))
|
||||
}).status(200)
|
||||
.response(function (res) {
|
||||
assert.equal(res.headers['content-encoding'], 'gzip')
|
||||
})
|
||||
require('zlib').gunzip(body, function(err, buf) {
|
||||
assert.equal(err, null)
|
||||
body = JSON.parse(buf)
|
||||
assert.equal(body.name, 'testexp_gzip')
|
||||
assert.equal(Object.keys(body.versions).length, 9)
|
||||
cb()
|
||||
.then(function (body) {
|
||||
assert.throws(function() {
|
||||
JSON.parse(body.toString('utf8'))
|
||||
})
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
require('zlib').gunzip(body, function(err, buf) {
|
||||
assert.equal(err, null)
|
||||
body = JSON.parse(buf)
|
||||
assert.equal(body.name, 'testexp_gzip')
|
||||
assert.equal(Object.keys(body.versions).length, 9)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ module.exports = function() {
|
|||
})
|
||||
})
|
||||
|
||||
;['content-length', 'chunked'].forEach(function(type) {
|
||||
;[ 'content-length', 'chunked' ].forEach(function(type) {
|
||||
it('should not store tarballs / ' + type, function(_cb) {
|
||||
var called
|
||||
express.get('/testexp-incomplete/-/'+type+'.tar.gz', function(_, res) {
|
||||
|
@ -46,18 +46,19 @@ module.exports = function() {
|
|||
}, 10)
|
||||
})
|
||||
|
||||
server.request({uri:'/testexp-incomplete/-/'+type+'.tar.gz'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
if (type !== 'chunked') assert.equal(res.headers['content-length'], 1e6)
|
||||
assert(body.match(/test test test/))
|
||||
})
|
||||
server.request({ uri: '/testexp-incomplete/-/'+type+'.tar.gz' })
|
||||
.status(200)
|
||||
.response(function (res) {
|
||||
if (type !== 'chunked') assert.equal(res.headers['content-length'], 1e6)
|
||||
})
|
||||
.then(function (body) {
|
||||
assert(body.match(/test test test/))
|
||||
})
|
||||
|
||||
function cb() {
|
||||
server.request({uri:'/testexp-incomplete/-/'+type+'.tar.gz'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(body.error, 'internal server error')
|
||||
_cb()
|
||||
})
|
||||
server.request({ uri: '/testexp-incomplete/-/'+type+'.tar.gz' })
|
||||
.body_error('internal server error')
|
||||
.then(function () { _cb() })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require('es6-shim')
|
||||
//require('es6-shim')
|
||||
require('./lib/startup')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
var assert = require('assert')
|
||||
var async = require('async')
|
||||
|
@ -9,38 +10,37 @@ describe('Func', function() {
|
|||
var server = process.server
|
||||
var server2 = process.server2
|
||||
|
||||
before(function(cb) {
|
||||
before(function (cb) {
|
||||
async.parallel([
|
||||
function(cb) {
|
||||
function (cb) {
|
||||
require('./lib/startup').start('./test-storage', './config-1.yaml', cb)
|
||||
},
|
||||
function(cb) {
|
||||
function (cb) {
|
||||
require('./lib/startup').start('./test-storage2', './config-2.yaml', cb)
|
||||
},
|
||||
], cb)
|
||||
})
|
||||
|
||||
before(function(cb) {
|
||||
async.map([server, server2], function(server, cb) {
|
||||
server.debug(function(res, body) {
|
||||
before(function() {
|
||||
return Promise.all([ server, server2 ].map(function(server) {
|
||||
return server.debug().status(200).then(function (body) {
|
||||
server.pid = body.pid
|
||||
exec('lsof -p ' + Number(server.pid), function(err, result) {
|
||||
assert.equal(err, null)
|
||||
server.fdlist = result.replace(/ +/g, ' ')
|
||||
cb()
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
exec('lsof -p ' + Number(server.pid), function(err, result) {
|
||||
assert.equal(err, null)
|
||||
server.fdlist = result.replace(/ +/g, ' ')
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
})
|
||||
}, cb)
|
||||
}))
|
||||
})
|
||||
|
||||
before(function auth(cb) {
|
||||
async.map([server, server2], function(server, cb) {
|
||||
server.auth('test', 'test', function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert.notEqual(body.ok.indexOf("'test'"), -1)
|
||||
cb()
|
||||
})
|
||||
}, cb)
|
||||
before(function auth() {
|
||||
return Promise.all([ server, server2 ].map(function(server, cb) {
|
||||
return server.auth('test', 'test').status(201).body_ok(/'test'/)
|
||||
}))
|
||||
})
|
||||
|
||||
it('authenticate', function(){/* test for before() */})
|
||||
|
@ -61,8 +61,8 @@ describe('Func', function() {
|
|||
require('./addtag')()
|
||||
require('./plugins')()
|
||||
|
||||
after(function(cb) {
|
||||
async.map([server, server2], function(server, cb) {
|
||||
after(function (cb) {
|
||||
async.map([ server, server2 ], function(server, cb) {
|
||||
exec('lsof -p ' + Number(server.pid), function(err, result) {
|
||||
assert.equal(err, null)
|
||||
result = result.split('\n').filter(function(q) {
|
||||
|
@ -79,3 +79,9 @@ describe('Func', function() {
|
|||
})
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', function (err) {
|
||||
process.nextTick(function () {
|
||||
throw err
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var assert = require('assert')
|
||||
var request = require('request')
|
||||
var request = require('./smart_request')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
function Server(url) {
|
||||
var self = Object.create(Server.prototype)
|
||||
|
@ -9,31 +10,25 @@ function Server(url) {
|
|||
return self
|
||||
}
|
||||
|
||||
function prep(cb) {
|
||||
return function(err, res, body) {
|
||||
if (err) throw err
|
||||
cb(res, body)
|
||||
}
|
||||
}
|
||||
|
||||
Server.prototype.request = function(options, cb) {
|
||||
Server.prototype.request = function(options) {
|
||||
assert(options.uri)
|
||||
var headers = options.headers || {}
|
||||
headers.accept = headers.accept || 'application/json'
|
||||
headers['user-agent'] = headers['user-agent'] || this.userAgent
|
||||
headers.authorization = headers.authorization || this.authstr
|
||||
|
||||
return request({
|
||||
url: this.url + options.uri,
|
||||
method: options.method || 'GET',
|
||||
headers: headers,
|
||||
encoding: options.encoding,
|
||||
json: options.json != null ? options.json : true,
|
||||
}, cb)
|
||||
})
|
||||
}
|
||||
|
||||
Server.prototype.auth = function(user, pass, cb) {
|
||||
Server.prototype.auth = function(user, pass) {
|
||||
this.authstr = 'Basic '+(Buffer(user+':'+pass)).toString('base64')
|
||||
this.request({
|
||||
return this.request({
|
||||
uri: '/-/user/org.couchdb.user:'+encodeURIComponent(user)+'/-rev/undefined',
|
||||
method: 'PUT',
|
||||
json: {
|
||||
|
@ -45,67 +40,67 @@ Server.prototype.auth = function(user, pass, cb) {
|
|||
roles: [],
|
||||
date: new Date(),
|
||||
}
|
||||
}, prep(cb))
|
||||
})
|
||||
}
|
||||
|
||||
Server.prototype.get_package = function(name, cb) {
|
||||
this.request({
|
||||
Server.prototype.get_package = function(name) {
|
||||
return this.request({
|
||||
uri: '/'+encodeURIComponent(name),
|
||||
method: 'GET',
|
||||
}, prep(cb))
|
||||
})
|
||||
}
|
||||
|
||||
Server.prototype.put_package = function(name, data, cb) {
|
||||
Server.prototype.put_package = function(name, data) {
|
||||
if (typeof(data) === 'object' && !Buffer.isBuffer(data)) data = JSON.stringify(data)
|
||||
this.request({
|
||||
return this.request({
|
||||
uri: '/'+encodeURIComponent(name),
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
}, prep(cb)).end(data)
|
||||
}).send(data)
|
||||
}
|
||||
|
||||
Server.prototype.put_version = function(name, version, data, cb) {
|
||||
Server.prototype.put_version = function(name, version, data) {
|
||||
if (typeof(data) === 'object' && !Buffer.isBuffer(data)) data = JSON.stringify(data)
|
||||
this.request({
|
||||
return this.request({
|
||||
uri: '/'+encodeURIComponent(name)+'/'+encodeURIComponent(version)+'/-tag/latest',
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
}, prep(cb)).end(data)
|
||||
}).send(data)
|
||||
}
|
||||
|
||||
Server.prototype.get_tarball = function(name, filename, cb) {
|
||||
this.request({
|
||||
Server.prototype.get_tarball = function(name, filename) {
|
||||
return this.request({
|
||||
uri: '/'+encodeURIComponent(name)+'/-/'+encodeURIComponent(filename),
|
||||
method: 'GET',
|
||||
}, prep(cb))
|
||||
})
|
||||
}
|
||||
|
||||
Server.prototype.put_tarball = function(name, filename, data, cb) {
|
||||
this.request({
|
||||
Server.prototype.put_tarball = function(name, filename, data) {
|
||||
return this.request({
|
||||
uri: '/'+encodeURIComponent(name)+'/-/'+encodeURIComponent(filename)+'/whatever',
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'content-type': 'application/octet-stream'
|
||||
},
|
||||
}, prep(cb)).end(data)
|
||||
}).send(data)
|
||||
}
|
||||
|
||||
Server.prototype.add_tag = function(name, tag, version, cb) {
|
||||
this.request({
|
||||
Server.prototype.add_tag = function(name, tag, version) {
|
||||
return this.request({
|
||||
uri: '/'+encodeURIComponent(name)+'/'+encodeURIComponent(tag),
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
}, prep(cb)).end(JSON.stringify(version))
|
||||
}).send(JSON.stringify(version))
|
||||
}
|
||||
|
||||
Server.prototype.put_tarball_incomplete = function(name, filename, data, size, cb) {
|
||||
var req = this.request({
|
||||
var promise = this.request({
|
||||
uri: '/'+encodeURIComponent(name)+'/-/'+encodeURIComponent(filename)+'/whatever',
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
|
@ -113,40 +108,50 @@ Server.prototype.put_tarball_incomplete = function(name, filename, data, size, c
|
|||
'content-length': size,
|
||||
},
|
||||
timeout: 1000,
|
||||
}, function(err) {
|
||||
assert(err)
|
||||
cb()
|
||||
})
|
||||
req.write(data)
|
||||
setTimeout(function() {
|
||||
req.req.abort()
|
||||
}, 20)
|
||||
}
|
||||
|
||||
Server.prototype.add_package = function(name, cb) {
|
||||
this.put_package(name, require('./package')(name), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('created new package'))
|
||||
cb()
|
||||
promise.request(function (req) {
|
||||
req.write(data)
|
||||
setTimeout(function() {
|
||||
req.req.abort()
|
||||
}, 20)
|
||||
})
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
promise
|
||||
.then(function() {
|
||||
reject(Error('no error'))
|
||||
})
|
||||
.catch(function(err) {
|
||||
if (err.code === 'ECONNRESET') {
|
||||
resolve()
|
||||
} else {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Server.prototype.whoami = function(cb) {
|
||||
this.request({ uri:'/-/whoami' }, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
cb(body.username)
|
||||
})
|
||||
Server.prototype.add_package = function(name) {
|
||||
return this.put_package(name, require('./package')(name))
|
||||
.status(201)
|
||||
.body_ok('created new package')
|
||||
}
|
||||
|
||||
Server.prototype.debug = function(cb) {
|
||||
this.request({
|
||||
Server.prototype.whoami = function() {
|
||||
return this.request({ uri:'/-/whoami' })
|
||||
.status(200)
|
||||
.then(function(x) { return x.username })
|
||||
}
|
||||
|
||||
Server.prototype.debug = function() {
|
||||
return this.request({
|
||||
uri: '/-/_debug',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
}, prep(cb))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = Server
|
||||
|
|
104
test/functional/lib/smart_request.js
Normal file
104
test/functional/lib/smart_request.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
|
||||
var assert = require('assert')
|
||||
var request = require('request')
|
||||
var sym = Symbol('smart_request_data')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
function smart_request(options) {
|
||||
var self = {}
|
||||
self[sym] = {}
|
||||
self[sym].error = Error()
|
||||
Error.captureStackTrace(self[sym].error, smart_request)
|
||||
|
||||
var result = new Promise(function (resolve, reject) {
|
||||
self[sym].request = request(options, function (err, res, body) {
|
||||
if (err) return reject(err)
|
||||
self[sym].response = res
|
||||
resolve(body)
|
||||
})
|
||||
})
|
||||
|
||||
return extend(self, result)
|
||||
}
|
||||
|
||||
function extend(self, promise) {
|
||||
promise[sym] = self[sym]
|
||||
Object.setPrototypeOf(promise, extensions)
|
||||
return promise
|
||||
}
|
||||
|
||||
var extensions = Object.create(Promise.prototype)
|
||||
|
||||
extensions.status = function (expected) {
|
||||
var self_data = this[sym]
|
||||
|
||||
return extend(this, this.then(function (body) {
|
||||
try {
|
||||
assert.equal(self_data.response.statusCode, expected)
|
||||
} catch(err) {
|
||||
self_data.error.message = err.message
|
||||
throw self_data.error
|
||||
}
|
||||
return body
|
||||
}))
|
||||
}
|
||||
|
||||
extensions.body_ok = function (expected) {
|
||||
var self_data = this[sym]
|
||||
|
||||
return extend(this, this.then(function (body) {
|
||||
try {
|
||||
if (Object.prototype.toString.call(expected) === '[object RegExp]') {
|
||||
assert(body.ok.match(expected), "'" + body.ok + "' doesn't match " + expected)
|
||||
} else {
|
||||
assert.equal(body.ok, expected)
|
||||
}
|
||||
assert.equal(body.error, null)
|
||||
} catch(err) {
|
||||
self_data.error.message = err.message
|
||||
throw self_data.error
|
||||
}
|
||||
return body
|
||||
}))
|
||||
}
|
||||
|
||||
extensions.body_error = function (expected) {
|
||||
var self_data = this[sym]
|
||||
|
||||
return extend(this, this.then(function (body) {
|
||||
try {
|
||||
if (Object.prototype.toString.call(expected) === '[object RegExp]') {
|
||||
assert(body.error.match(expected), body.error + " doesn't match " + expected)
|
||||
} else {
|
||||
assert.equal(body.error, expected)
|
||||
}
|
||||
assert.equal(body.ok, null)
|
||||
} catch(err) {
|
||||
self_data.error.message = err.message
|
||||
throw self_data.error
|
||||
}
|
||||
return body
|
||||
}))
|
||||
}
|
||||
|
||||
extensions.request = function (cb) {
|
||||
cb(this[sym].request)
|
||||
return this
|
||||
}
|
||||
|
||||
extensions.response = function (cb) {
|
||||
var self_data = this[sym]
|
||||
|
||||
return extend(this, this.then(function (body) {
|
||||
cb(self_data.response)
|
||||
return body
|
||||
}))
|
||||
}
|
||||
|
||||
extensions.send = function (data) {
|
||||
this[sym].request.end(data)
|
||||
return this
|
||||
}
|
||||
|
||||
module.exports = smart_request
|
||||
|
|
@ -8,12 +8,10 @@ module.exports = function() {
|
|||
var server = process.server
|
||||
var server2 = process.server2
|
||||
|
||||
it('testing anti-loop', function(cb) {
|
||||
server2.get_package('testloop', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('testing anti-loop', function () {
|
||||
return server2.get_package('testloop')
|
||||
.status(404)
|
||||
.body_error(/no such package/)
|
||||
})
|
||||
|
||||
;['fwd', /*'loop'*/].forEach(function(pkg) {
|
||||
|
@ -21,50 +19,42 @@ module.exports = function() {
|
|||
pkg = 'test' + pkg
|
||||
|
||||
describe(pkg, function() {
|
||||
before(function(cb) {
|
||||
server.put_package(pkg, require('./lib/package')(pkg), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('created new package'))
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_package(pkg, require('./lib/package')(pkg))
|
||||
.status(201)
|
||||
.body_ok(/created new package/)
|
||||
})
|
||||
|
||||
it(prefix+'creating new package', function(){})
|
||||
|
||||
describe(pkg, function() {
|
||||
before(function(cb) {
|
||||
server.put_version(pkg, '0.1.1', require('./lib/package')(pkg), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('published'))
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_version(pkg, '0.1.1', require('./lib/package')(pkg))
|
||||
.status(201)
|
||||
.body_ok(/published/)
|
||||
})
|
||||
|
||||
it(prefix+'uploading new package version', function(){})
|
||||
|
||||
it(prefix+'uploading incomplete tarball', function(cb) {
|
||||
server.put_tarball_incomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000, function(res, body) {
|
||||
cb()
|
||||
})
|
||||
it(prefix+'uploading incomplete tarball', function () {
|
||||
return server.put_tarball_incomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000)
|
||||
})
|
||||
|
||||
describe('tarball', function() {
|
||||
before(function(cb) {
|
||||
server.put_tarball(pkg, pkg+'.file', readfile('fixtures/binary'), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(body.ok)
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_tarball(pkg, pkg+'.file', readfile('fixtures/binary'))
|
||||
.status(201)
|
||||
.body_ok(/.*/)
|
||||
})
|
||||
|
||||
it(prefix+'uploading new tarball', function(){})
|
||||
|
||||
it(prefix+'downloading tarball from server1', function(cb) {
|
||||
server.get_tarball(pkg, pkg+'.file', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
cb()
|
||||
})
|
||||
it(prefix+'downloading tarball from server1', function () {
|
||||
return server.get_tarball(pkg, pkg+'.file')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -14,123 +14,105 @@ module.exports = function() {
|
|||
var express = process.express
|
||||
|
||||
describe('newnpmreg', function() {
|
||||
before(function(cb) {
|
||||
server.request({
|
||||
before(function () {
|
||||
return server.request({
|
||||
uri: '/testpkg-newnpmreg',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: JSON.parse(readfile('fixtures/newnpmreg.json')),
|
||||
}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 201)
|
||||
cb()
|
||||
})
|
||||
}).status(201)
|
||||
})
|
||||
|
||||
it('add pkg', function(){})
|
||||
it('add pkg', function () {})
|
||||
|
||||
it('server1 - tarball', function(cb) {
|
||||
server.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
|
||||
cb()
|
||||
})
|
||||
it('server1 - tarball', function () {
|
||||
return server.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - tarball', function(cb) {
|
||||
server2.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
|
||||
cb()
|
||||
})
|
||||
it('server2 - tarball', function () {
|
||||
return server2.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
|
||||
})
|
||||
})
|
||||
|
||||
it('server1 - package', function(cb) {
|
||||
server.get_package('testpkg-newnpmreg', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55551/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
||||
cb()
|
||||
})
|
||||
it('server1 - package', function () {
|
||||
return server.get_package('testpkg-newnpmreg')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55551/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - package', function(cb) {
|
||||
server2.get_package('testpkg-newnpmreg', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55552/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
||||
cb()
|
||||
})
|
||||
it('server2 - package', function () {
|
||||
return server2.get_package('testpkg-newnpmreg')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55552/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
||||
})
|
||||
})
|
||||
|
||||
it('server1 - readme', function(cb) {
|
||||
server.request({uri:'/-/readme/testpkg-newnpmreg'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body, '<p>blah blah blah</p>\n')
|
||||
cb()
|
||||
})
|
||||
it('server1 - readme', function () {
|
||||
return server.request({ uri: '/-/readme/testpkg-newnpmreg' })
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body, '<p>blah blah blah</p>\n')
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - readme', function(cb) {
|
||||
server2.request({uri:'/-/readme/testpkg-newnpmreg'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body, '<p>blah blah blah</p>\n')
|
||||
cb()
|
||||
})
|
||||
it('server2 - readme', function () {
|
||||
return server2.request({ uri: '/-/readme/testpkg-newnpmreg' })
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body, '<p>blah blah blah</p>\n')
|
||||
})
|
||||
})
|
||||
|
||||
describe('search', function() {
|
||||
function check(obj) {
|
||||
obj.testpkg.time.modified = '2014-10-02T07:07:51.000Z'
|
||||
assert.deepEqual(obj.testpkg, {
|
||||
"name": "testpkg",
|
||||
"dist-tags": {
|
||||
"latest": "0.0.1"
|
||||
},
|
||||
"maintainers": [],
|
||||
"readmeFilename": "",
|
||||
"time": {
|
||||
"modified": "2014-10-02T07:07:51.000Z"
|
||||
},
|
||||
"versions": {
|
||||
"0.0.1": "latest"
|
||||
}
|
||||
})
|
||||
obj['testpkg-newnpmreg'].time.modified = '2014-10-02T07:07:51.000Z'
|
||||
assert.deepEqual(obj['testpkg-newnpmreg'],
|
||||
{ name: 'testpkg-newnpmreg',
|
||||
description: '',
|
||||
'dist-tags': { latest: '0.0.0' },
|
||||
maintainers: [ { name: 'alex', email: 'alex@kocharin.ru' } ],
|
||||
readmeFilename: '',
|
||||
time: { modified: '2014-10-02T07:07:51.000Z' },
|
||||
versions: { '0.0.0': 'latest' },
|
||||
repository: { type: 'git', url: '' } })
|
||||
}
|
||||
|
||||
before(function(cb) {
|
||||
before(function () {
|
||||
express.get('/-/all', function(req, res) {
|
||||
res.send({})
|
||||
})
|
||||
cb()
|
||||
})
|
||||
|
||||
it('server1 - search', function(cb) {
|
||||
server.request({uri:'/-/all'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
check(body)
|
||||
cb()
|
||||
})
|
||||
it('server1 - search', function () {
|
||||
return server.request({ uri: '/-/all' })
|
||||
.status(200)
|
||||
.then(check)
|
||||
})
|
||||
|
||||
it('server2 - search', function(cb) {
|
||||
server2.request({uri:'/-/all'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
check(body)
|
||||
cb()
|
||||
})
|
||||
it('server2 - search', function () {
|
||||
return server2.request({ uri: '/-/all' })
|
||||
.status(200)
|
||||
.then(check)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -11,65 +11,59 @@ module.exports = function() {
|
|||
var server = process.server
|
||||
var server2 = process.server2
|
||||
|
||||
it('trying to fetch non-existent package / null storage', function(cb) {
|
||||
server.get_package('test-nullstorage-nonexist', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('trying to fetch non-existent package / null storage', function () {
|
||||
return server.get_package('test-nullstorage-nonexist')
|
||||
.status(404)
|
||||
.body_error(/no such package/)
|
||||
})
|
||||
|
||||
describe('test-nullstorage on server2', function() {
|
||||
before(server2.add_package.bind(server2, 'test-nullstorage2'))
|
||||
before(function () {
|
||||
return server2.add_package('test-nullstorage2')
|
||||
})
|
||||
|
||||
it('creating new package - server2', function(){/* test for before() */})
|
||||
|
||||
it('downloading non-existent tarball', function(cb) {
|
||||
server.get_tarball('test-nullstorage2', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such file'))
|
||||
cb()
|
||||
})
|
||||
it('downloading non-existent tarball', function () {
|
||||
return server.get_tarball('test-nullstorage2', 'blahblah')
|
||||
.status(404)
|
||||
.body_error(/no such file/)
|
||||
})
|
||||
|
||||
describe('tarball', function() {
|
||||
before(function(cb) {
|
||||
server2.put_tarball('test-nullstorage2', 'blahblah', readfile('fixtures/binary'), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(body.ok)
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server2.put_tarball('test-nullstorage2', 'blahblah', readfile('fixtures/binary'))
|
||||
.status(201)
|
||||
.body_ok(/.*/)
|
||||
})
|
||||
|
||||
before(function(cb) {
|
||||
before(function () {
|
||||
var pkg = require('./lib/package')('test-nullstorage2')
|
||||
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
|
||||
server2.put_version('test-nullstorage2', '0.0.1', pkg, function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('published'))
|
||||
cb()
|
||||
})
|
||||
return server2.put_version('test-nullstorage2', '0.0.1', pkg)
|
||||
.status(201)
|
||||
.body_ok(/published/)
|
||||
})
|
||||
|
||||
it('uploading new tarball', function(){/* test for before() */})
|
||||
it('uploading new tarball', function () {/* test for before() */})
|
||||
|
||||
it('downloading newly created tarball', function(cb) {
|
||||
server.get_tarball('test-nullstorage2', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
cb()
|
||||
})
|
||||
it('downloading newly created tarball', function () {
|
||||
return server.get_tarball('test-nullstorage2', 'blahblah')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
||||
})
|
||||
})
|
||||
|
||||
it('downloading newly created package', function(cb) {
|
||||
server.get_package('test-nullstorage2', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'test-nullstorage2')
|
||||
assert.equal(body.versions['0.0.1'].name, 'test-nullstorage2')
|
||||
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/test-nullstorage2/-/blahblah')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
||||
cb()
|
||||
})
|
||||
it('downloading newly created package', function () {
|
||||
return server.get_package('test-nullstorage2')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, 'test-nullstorage2')
|
||||
assert.equal(body.versions['0.0.1'].name, 'test-nullstorage2')
|
||||
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/test-nullstorage2/-/blahblah')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -12,40 +12,40 @@ module.exports = function() {
|
|||
authstr = server2.authstr
|
||||
})
|
||||
|
||||
it('should not authenticate with wrong password', function(cb) {
|
||||
server2.auth('authtest', 'wrongpass', function(res, body) {
|
||||
assert.equal(res.statusCode, 409)
|
||||
assert.equal(body.error, 'this user already exists')
|
||||
|
||||
server2.whoami(function(username) {
|
||||
assert.equal(username, undefined)
|
||||
cb()
|
||||
})
|
||||
})
|
||||
it('should not authenticate with wrong password', function () {
|
||||
return server2.auth('authtest', 'wrongpass')
|
||||
.status(409)
|
||||
.body_error('this user already exists')
|
||||
.then(function () {
|
||||
return server2.whoami()
|
||||
})
|
||||
.then(function (username) {
|
||||
assert.equal(username, null)
|
||||
})
|
||||
})
|
||||
|
||||
it('wrong password handled by plugin', function(cb) {
|
||||
server2.auth('authtest2', 'wrongpass', function(res, body) {
|
||||
assert.equal(res.statusCode, 409)
|
||||
assert.equal(body.error, 'registration is disabled')
|
||||
|
||||
server2.whoami(function(username) {
|
||||
assert.equal(username, undefined)
|
||||
cb()
|
||||
})
|
||||
})
|
||||
it('wrong password handled by plugin', function () {
|
||||
return server2.auth('authtest2', 'wrongpass')
|
||||
.status(409)
|
||||
.body_error('registration is disabled')
|
||||
.then(function () {
|
||||
return server2.whoami()
|
||||
})
|
||||
.then(function (username) {
|
||||
assert.equal(username, null)
|
||||
})
|
||||
})
|
||||
|
||||
it('right password handled by plugin', function(cb) {
|
||||
server2.auth('authtest2', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert.notEqual(body.ok.indexOf("'authtest2'"), -1)
|
||||
|
||||
server2.whoami(function(username) {
|
||||
assert.equal(username, 'authtest2')
|
||||
cb()
|
||||
})
|
||||
})
|
||||
it('right password handled by plugin', function () {
|
||||
return server2.auth('authtest2', 'blahblah')
|
||||
.status(201)
|
||||
.body_ok(/'authtest2'/)
|
||||
.then(function () {
|
||||
return server2.whoami()
|
||||
})
|
||||
.then(function (username) {
|
||||
assert.equal(username, 'authtest2')
|
||||
})
|
||||
})
|
||||
|
||||
after(function() {
|
||||
|
@ -61,70 +61,54 @@ module.exports = function() {
|
|||
})
|
||||
|
||||
describe('authtest', function() {
|
||||
before(function(cb) {
|
||||
server2.auth('authtest', 'test', function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert.notEqual(body.ok.indexOf("'authtest'"), -1)
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server2.auth('authtest', 'test')
|
||||
.status(201)
|
||||
.body_ok(/'authtest'/)
|
||||
})
|
||||
|
||||
it('access test-auth-allow', function(cb) {
|
||||
server2.get_package('test-auth-allow', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert.equal(body.error, 'no such package available')
|
||||
cb()
|
||||
})
|
||||
it('access test-auth-allow', function () {
|
||||
return server2.get_package('test-auth-allow')
|
||||
.status(404)
|
||||
.body_error('no such package available')
|
||||
})
|
||||
|
||||
it('access test-auth-deny', function(cb) {
|
||||
server2.get_package('test-auth-deny', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert.equal(body.error, "you're not allowed here")
|
||||
cb()
|
||||
})
|
||||
it('access test-auth-deny', function () {
|
||||
return server2.get_package('test-auth-deny')
|
||||
.status(403)
|
||||
.body_error("you're not allowed here")
|
||||
})
|
||||
|
||||
it('access test-auth-regular', function(cb) {
|
||||
server2.get_package('test-auth-regular', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert.equal(body.error, 'no such package available')
|
||||
cb()
|
||||
})
|
||||
it('access test-auth-regular', function () {
|
||||
return server2.get_package('test-auth-regular')
|
||||
.status(404)
|
||||
.body_error('no such package available')
|
||||
})
|
||||
})
|
||||
|
||||
describe('authtest2', function() {
|
||||
before(function(cb) {
|
||||
server2.auth('authtest2', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert.notEqual(body.ok.indexOf("'authtest2'"), -1)
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server2.auth('authtest2', 'blahblah')
|
||||
.status(201)
|
||||
.body_ok(/'authtest2'/)
|
||||
})
|
||||
|
||||
it('access test-auth-allow', function(cb) {
|
||||
server2.get_package('test-auth-allow', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert.equal(body.error, "i don't know anything about you")
|
||||
cb()
|
||||
})
|
||||
it('access test-auth-allow', function () {
|
||||
return server2.get_package('test-auth-allow')
|
||||
.status(403)
|
||||
.body_error("i don't know anything about you")
|
||||
})
|
||||
|
||||
it('access test-auth-deny', function(cb) {
|
||||
server2.get_package('test-auth-deny', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert.equal(body.error, "i don't know anything about you")
|
||||
cb()
|
||||
})
|
||||
it('access test-auth-deny', function () {
|
||||
return server2.get_package('test-auth-deny')
|
||||
.status(403)
|
||||
.body_error("i don't know anything about you")
|
||||
})
|
||||
|
||||
it('access test-auth-regular', function(cb) {
|
||||
server2.get_package('test-auth-regular', function(res, body) {
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert.equal(body.error, 'no such package available')
|
||||
cb()
|
||||
})
|
||||
it('access test-auth-regular', function () {
|
||||
return server2.get_package('test-auth-regular')
|
||||
.status(404)
|
||||
.body_error('no such package available')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -6,25 +6,27 @@ module.exports = function() {
|
|||
var server = process.server
|
||||
|
||||
describe('race', function() {
|
||||
before(function(cb) {
|
||||
server.put_package('race', require('./lib/package')('race'), function(res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
assert(~body.ok.indexOf('created new package'))
|
||||
cb()
|
||||
})
|
||||
before(function () {
|
||||
return server.put_package('race', require('./lib/package')('race'))
|
||||
.status(201)
|
||||
.body_ok(/created new package/)
|
||||
})
|
||||
|
||||
it('creating new package', function(){})
|
||||
|
||||
it('uploading 10 same versions', function(cb) {
|
||||
it('uploading 10 same versions', function (callback) {
|
||||
var fns = []
|
||||
for (var i=0; i<10; i++) {
|
||||
fns.push(function(cb_) {
|
||||
var data = require('./lib/package')('race')
|
||||
data.rand = Math.random()
|
||||
server.put_version('race', '0.0.1', data, function(res, body) {
|
||||
cb_(null, res, body)
|
||||
})
|
||||
|
||||
var _res
|
||||
server.put_version('race', '0.0.1', data)
|
||||
.response(function (res) { _res = res })
|
||||
.then(function (body) {
|
||||
cb_(null, [ _res, body ])
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -46,18 +48,21 @@ module.exports = function() {
|
|||
assert.equal(okcount, 1)
|
||||
_oksum += okcount
|
||||
|
||||
cb()
|
||||
callback()
|
||||
})
|
||||
})
|
||||
|
||||
it('uploading 10 diff versions', function(cb) {
|
||||
it('uploading 10 diff versions', function (callback) {
|
||||
var fns = []
|
||||
for (var i=0; i<10; i++) {
|
||||
;(function(i) {
|
||||
fns.push(function(cb_) {
|
||||
server.put_version('race', '0.1.'+String(i), require('./lib/package')('race'), function(res, body) {
|
||||
cb_(null, res, body)
|
||||
})
|
||||
var _res
|
||||
server.put_version('race', '0.1.'+String(i), require('./lib/package')('race'))
|
||||
.response(function (res) { _res = res })
|
||||
.then(function (body) {
|
||||
cb_(null, [ _res, body ])
|
||||
})
|
||||
})
|
||||
})(i)
|
||||
}
|
||||
|
@ -75,19 +80,19 @@ module.exports = function() {
|
|||
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++
|
||||
})
|
||||
assert.equal(okcount + failcount, 10)
|
||||
assert.notEqual(okcount, 1)
|
||||
_oksum += okcount
|
||||
|
||||
cb()
|
||||
callback()
|
||||
})
|
||||
})
|
||||
|
||||
// XXX: this should be after anything else, but we can't really ensure that with mocha
|
||||
it('downloading package', function(cb) {
|
||||
server.get_package('race', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(Object.keys(body.versions).length, _oksum)
|
||||
cb()
|
||||
})
|
||||
after('downloading package', function () {
|
||||
return server.get_package('race')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(Object.keys(body.versions).length, _oksum)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -40,31 +40,26 @@ module.exports = function() {
|
|||
}, 200)
|
||||
}
|
||||
|
||||
server.request({uri:'/testexp-racycrash/-/test.tar.gz'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(body, 'test test test\n')
|
||||
})
|
||||
server.request({ uri: '/testexp-racycrash/-/test.tar.gz' })
|
||||
.then(function (body) {
|
||||
assert.equal(body, 'test test test\n')
|
||||
})
|
||||
|
||||
function cb() {
|
||||
// test for NOT crashing
|
||||
server.request({uri:'/testexp-racycrash'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
_cb()
|
||||
})
|
||||
server.request({ uri: '/testexp-racycrash' })
|
||||
.status(200)
|
||||
.then(function () { _cb() })
|
||||
}
|
||||
})
|
||||
|
||||
it('should not store tarball', function(cb) {
|
||||
it('should not store tarball', function () {
|
||||
on_tarball = function(res) {
|
||||
res.socket.destroy()
|
||||
}
|
||||
|
||||
server.request({uri:'/testexp-racycrash/-/test.tar.gz'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(body.error, 'internal server error')
|
||||
cb()
|
||||
})
|
||||
return server.request({ uri: '/testexp-racycrash/-/test.tar.gz' })
|
||||
.body_error('internal server error')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,61 +13,57 @@ module.exports = function() {
|
|||
var server2 = process.server2
|
||||
|
||||
describe('test-scoped', function() {
|
||||
before(function(cb) {
|
||||
server.request({
|
||||
before(function () {
|
||||
return server.request({
|
||||
uri: '/@test%2fscoped',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: JSON.parse(readfile('fixtures/scoped.json')),
|
||||
}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 201)
|
||||
cb()
|
||||
})
|
||||
}).status(201)
|
||||
})
|
||||
|
||||
it('add pkg', function(){})
|
||||
it('add pkg', function () {})
|
||||
|
||||
it('server1 - tarball', function(cb) {
|
||||
server.get_tarball('@test/scoped', 'scoped-1.0.0.tgz', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), 'c59298948907d077c3b42f091554bdeea9208964')
|
||||
cb()
|
||||
})
|
||||
it('server1 - tarball', function () {
|
||||
return server.get_tarball('@test/scoped', 'scoped-1.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), 'c59298948907d077c3b42f091554bdeea9208964')
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - tarball', function(cb) {
|
||||
server2.get_tarball('@test/scoped', 'scoped-1.0.0.tgz', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), 'c59298948907d077c3b42f091554bdeea9208964')
|
||||
cb()
|
||||
})
|
||||
it('server2 - tarball', function () {
|
||||
return server2.get_tarball('@test/scoped', 'scoped-1.0.0.tgz')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), 'c59298948907d077c3b42f091554bdeea9208964')
|
||||
})
|
||||
})
|
||||
|
||||
it('server1 - package', function(cb) {
|
||||
server.get_package('@test/scoped', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].dist.tarball, 'http://localhost:55551/@test%2fscoped/-/scoped-1.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'})
|
||||
cb()
|
||||
})
|
||||
it('server1 - package', function () {
|
||||
return server.get_package('@test/scoped')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].dist.tarball, 'http://localhost:55551/@test%2fscoped/-/scoped-1.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'})
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - package', function(cb) {
|
||||
server2.get_package('@test/scoped', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].dist.tarball, 'http://localhost:55552/@test%2fscoped/-/scoped-1.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'})
|
||||
cb()
|
||||
})
|
||||
it('server2 - package', function () {
|
||||
return server2.get_package('@test/scoped')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].name, '@test/scoped')
|
||||
assert.equal(body.versions['1.0.0'].dist.tarball, 'http://localhost:55552/@test%2fscoped/-/scoped-1.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,88 +4,66 @@ module.exports = function() {
|
|||
var server = process.server
|
||||
|
||||
describe('Security', function() {
|
||||
before(server.add_package.bind(server, 'testpkg-sec'))
|
||||
|
||||
it('bad pkg #1', function(cb) {
|
||||
server.get_package('package.json', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(~body.error.indexOf('invalid package'))
|
||||
cb()
|
||||
})
|
||||
before(function() {
|
||||
return server.add_package('testpkg-sec')
|
||||
})
|
||||
|
||||
it('bad pkg #2', function(cb) {
|
||||
server.get_package('__proto__', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(~body.error.indexOf('invalid package'))
|
||||
cb()
|
||||
})
|
||||
it('bad pkg #1', function () {
|
||||
return server.get_package('package.json')
|
||||
.status(403)
|
||||
.body_error(/invalid package/)
|
||||
})
|
||||
|
||||
it('__proto__, connect stuff', function(cb) {
|
||||
server.request({uri:'/testpkg-sec?__proto__=1'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
it('bad pkg #2', function () {
|
||||
return server.get_package('__proto__')
|
||||
.status(403)
|
||||
.body_error(/invalid package/)
|
||||
})
|
||||
|
||||
// test for NOT outputting stack trace
|
||||
assert(!body || typeof(body) === 'object' || body.indexOf('node_modules') === -1)
|
||||
it('__proto__, connect stuff', function () {
|
||||
return server.request({ uri: '/testpkg-sec?__proto__=1' })
|
||||
.then(function (body) {
|
||||
// test for NOT outputting stack trace
|
||||
assert(!body || typeof(body) === 'object' || body.indexOf('node_modules') === -1)
|
||||
|
||||
// test for NOT crashing
|
||||
server.request({uri:'/testpkg-sec'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
cb()
|
||||
// test for NOT crashing
|
||||
return server.request({ uri: '/testpkg-sec' }).status(200)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('do not return package.json as an attachment', function(cb) {
|
||||
server.request({uri:'/testpkg-sec/-/package.json'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(body.error.match(/invalid filename/))
|
||||
cb()
|
||||
})
|
||||
it('do not return package.json as an attachment', function () {
|
||||
return server.request({ uri: '/testpkg-sec/-/package.json' })
|
||||
.status(403)
|
||||
.body_error(/invalid filename/)
|
||||
})
|
||||
|
||||
it('silly things - reading #1', function(cb) {
|
||||
server.request({uri:'/testpkg-sec/-/../../../../../../../../etc/passwd'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 404)
|
||||
cb()
|
||||
})
|
||||
it('silly things - reading #1', function () {
|
||||
return server.request({ uri: '/testpkg-sec/-/../../../../../../../../etc/passwd' })
|
||||
.status(404)
|
||||
})
|
||||
|
||||
it('silly things - reading #2', function(cb) {
|
||||
server.request({uri:'/testpkg-sec/-/%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(body.error.match(/invalid filename/))
|
||||
cb()
|
||||
})
|
||||
it('silly things - reading #2', function () {
|
||||
return server.request({ uri: '/testpkg-sec/-/%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd' })
|
||||
.status(403)
|
||||
.body_error(/invalid filename/)
|
||||
})
|
||||
|
||||
it('silly things - writing #1', function(cb) {
|
||||
server.put_tarball('testpkg-sec', 'package.json', '{}', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(body.error.match(/invalid filename/))
|
||||
cb()
|
||||
})
|
||||
it('silly things - writing #1', function () {
|
||||
return server.put_tarball('testpkg-sec', 'package.json', '{}')
|
||||
.status(403)
|
||||
.body_error(/invalid filename/)
|
||||
})
|
||||
|
||||
it('silly things - writing #3', function(cb) {
|
||||
server.put_tarball('testpkg-sec', 'node_modules', '{}', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(body.error.match(/invalid filename/))
|
||||
cb()
|
||||
})
|
||||
it('silly things - writing #3', function () {
|
||||
return server.put_tarball('testpkg-sec', 'node_modules', '{}')
|
||||
.status(403)
|
||||
.body_error(/invalid filename/)
|
||||
})
|
||||
|
||||
it('silly things - writing #4', function(cb) {
|
||||
server.put_tarball('testpkg-sec', '../testpkg.tgz', '{}', function(res, body) {
|
||||
assert.equal(res.statusCode, 403)
|
||||
assert(body.error.match(/invalid filename/))
|
||||
cb()
|
||||
})
|
||||
it('silly things - writing #4', function () {
|
||||
return server.put_tarball('testpkg-sec', '../testpkg.tgz', '{}')
|
||||
.status(403)
|
||||
.body_error(/invalid filename/)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,43 +8,39 @@ module.exports = function() {
|
|||
var server = process.server
|
||||
var express = process.express
|
||||
|
||||
it('tags - testing for 404', function(cb) {
|
||||
server.get_package('testexp_tags', function(res, body) {
|
||||
// shouldn't exist yet
|
||||
assert.equal(res.statusCode, 404)
|
||||
assert(~body.error.indexOf('no such package'))
|
||||
cb()
|
||||
})
|
||||
it('tags - testing for 404', function () {
|
||||
return server.get_package('testexp_tags')
|
||||
// shouldn't exist yet
|
||||
.status(404)
|
||||
.body_error(/no such package/)
|
||||
})
|
||||
|
||||
describe('tags', function() {
|
||||
before(function(cb) {
|
||||
before(function () {
|
||||
express.get('/testexp_tags', function(req, res) {
|
||||
res.send(JSON.parse(readfile('fixtures/tags.json')))
|
||||
})
|
||||
cb()
|
||||
})
|
||||
|
||||
it('fetching package again', function(cb) {
|
||||
server.get_package('testexp_tags', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(typeof(body.versions['1.1']), 'object')
|
||||
assert.equal(body['dist-tags'].something, '0.1.1alpha')
|
||||
// note: 5.4.3 is invalid tag, 0.1.3alpha is highest semver
|
||||
assert.equal(body['dist-tags'].latest, '0.1.3alpha')
|
||||
assert.equal(body['dist-tags'].bad, null)
|
||||
cb()
|
||||
})
|
||||
it('fetching package again', function () {
|
||||
return server.get_package('testexp_tags')
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(typeof(body.versions['1.1']), 'object')
|
||||
assert.equal(body['dist-tags'].something, '0.1.1alpha')
|
||||
// note: 5.4.3 is invalid tag, 0.1.3alpha is highest semver
|
||||
assert.equal(body['dist-tags'].latest, '0.1.3alpha')
|
||||
assert.equal(body['dist-tags'].bad, null)
|
||||
})
|
||||
})
|
||||
|
||||
;['0.1.1alpha', '0.1.1-alpha', '0000.00001.001-alpha'].forEach(function(ver) {
|
||||
it('fetching '+ver, function(cb) {
|
||||
server.request({uri:'/testexp_tags/'+ver}, function(err, res, body) {
|
||||
assert.equal(err, null)
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.version, '0.1.1alpha')
|
||||
cb()
|
||||
})
|
||||
it('fetching '+ver, function () {
|
||||
return server.request({uri:'/testexp_tags/'+ver})
|
||||
.status(200)
|
||||
.then(function (body) {
|
||||
assert.equal(body.version, '0.1.1alpha')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue