2017-04-19 14:15:28 -05:00
|
|
|
'use strict';
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
require('./lib/startup');
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const crypto = require('crypto');
|
2013-12-19 10:11:54 -05:00
|
|
|
|
|
|
|
function readfile(x) {
|
2017-04-19 14:15:28 -05:00
|
|
|
return require('fs').readFileSync(__dirname + '/' + x);
|
2013-12-19 10:11:54 -05:00
|
|
|
}
|
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
module.exports = function() {
|
|
|
|
let server = process.server;
|
|
|
|
let server2 = process.server2;
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('trying to fetch non-existent package', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.getPackage('testpkg').status(404).body_error(/no such package/);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
describe('testpkg', function() {
|
|
|
|
before(function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.addPackage('testpkg');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('creating new package', function() {/* test for before() */});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('downloading non-existent tarball', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('uploading incomplete tarball', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
describe('tarball', function() {
|
|
|
|
before(function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putTarball('testpkg', 'blahblah', readfile('fixtures/binary'))
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(201)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_ok(/.*/);
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('uploading new tarball', function() {/* test for before() */});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('downloading newly created tarball', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.getTarball('testpkg', 'blahblah')
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(200)
|
2017-04-19 14:15:28 -05:00
|
|
|
.then(function(body) {
|
|
|
|
assert.deepEqual(body, readfile('fixtures/binary'));
|
|
|
|
});
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('uploading new package version (bad sha)', function() {
|
|
|
|
let pkg = require('./lib/package')('testpkg');
|
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex');
|
2015-04-11 12:11:04 -05:00
|
|
|
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putVersion('testpkg', '0.0.1', pkg)
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(400)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_error(/shasum error/);
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
describe('version', function() {
|
|
|
|
before(function() {
|
|
|
|
let pkg = require('./lib/package')('testpkg');
|
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putVersion('testpkg', '0.0.1', pkg)
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(201)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_ok(/published/);
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('uploading new package version', function() {/* test for before() */});
|
2015-04-11 12:11:04 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('downloading newly created package', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.getPackage('testpkg')
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(200)
|
2017-04-19 14:15:28 -05:00
|
|
|
.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() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server2.getPackage('testpkg')
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(200)
|
2017-04-19 14:15:28 -05:00
|
|
|
.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() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putVersion('testpxg', '0.0.1', require('./lib/package')('testpxg'))
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(404)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_error(/no such package/);
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('doubleerr test', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putTarball('testfwd2', 'blahblah', readfile('fixtures/binary'))
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(404)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_error(/no such/);
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('publishing package / bad ro uplink', function() {
|
2017-06-28 15:56:02 -05:00
|
|
|
return server.putPackage('baduplink', require('./lib/package')('baduplink'))
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(503)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_error(/one of the uplinks is down, refuse to publish/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('who am I?', function() {
|
|
|
|
return server.whoami().then(function(username) {
|
|
|
|
assert.equal(username, 'test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-12-19 10:11:54 -05:00
|
|
|
|