1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-21 07:29:37 +01:00

Update unit test es6

This commit is contained in:
Juan Picado 2017-04-19 21:15:28 +02:00
parent 7970e52068
commit b05050da5b
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
36 changed files with 1448 additions and 1379 deletions

@ -1,80 +1,73 @@
'use strict';
module.exports = function () {
describe('access control', function () {
var server = process.server
var oldauth
module.exports = function() {
describe('access control', function() {
let server = process.server;
let oldauth;
before(function () {
oldauth = server.authstr
})
before(function() {
oldauth = server.authstr;
});
after(function () {
server.authstr = oldauth
})
after(function() {
server.authstr = oldauth;
});
function check_access(auth, pkg, ok) {
it((ok ? 'allows' : 'forbids') +' access ' + auth + ' to ' + pkg, function () {
server.authstr = auth
? 'Basic '+(new Buffer(auth).toString('base64'))
: undefined
var req = server.get_package(pkg)
it((ok ? 'allows' : 'forbids') +' access ' + auth + ' to ' + pkg, function() {
server.authstr = auth? `Basic ${(new Buffer(auth).toString('base64'))}`: undefined;
let req = server.get_package(pkg);
if (ok) {
return req.status(404)
.body_error(/no such package available/)
return req.status(404).body_error(/no such package available/);
} else {
return req.status(403)
.body_error(/not allowed to access package/)
return req.status(403).body_error(/not allowed to access package/);
}
})
});
}
function check_publish(auth, pkg, ok) {
it((ok ? 'allows' : 'forbids') + ' publish ' + auth + ' to ' + pkg, function () {
server.authstr = auth
? 'Basic '+(new Buffer(auth).toString('base64'))
: undefined
var req = server.put_package(pkg, require('./lib/package')(pkg))
it(`${(ok ? 'allows' : 'forbids')} publish ${auth} to ${pkg}`, function() {
server.authstr = auth? `Basic ${(new Buffer(auth).toString('base64'))}`: undefined;
let req = server.put_package(pkg, require('./lib/package')(pkg));
if (ok) {
return req.status(404)
.body_error(/this package cannot be added/)
return req.status(404).body_error(/this package cannot be added/);
} else {
return req.status(403)
.body_error(/not allowed to publish package/)
return req.status(403).body_error(/not allowed to publish package/);
}
})
});
}
const badPass = 'test:badpass';
const testPass = 'test:test';
const testAccessOnly = 'test-access-only';
const testPublishOnly = 'test-publish-only';
const testOnlyTest = 'test-only-test';
const testOnlyAuth = 'test-only-auth';
check_access(testPass, testAccessOnly, true);
check_access(undefined, testAccessOnly, true);
check_access(badPass, testAccessOnly, true);
check_publish(testPass, testAccessOnly, false);
check_publish(undefined, testAccessOnly, false);
check_publish(badPass, testAccessOnly, false);
check_access('test:test', 'test-access-only', true)
check_access(undefined, 'test-access-only', true)
check_access('test:badpass', 'test-access-only', true)
check_publish('test:test', 'test-access-only', false)
check_publish(undefined, 'test-access-only', false)
check_publish('test:badpass', 'test-access-only', false)
check_access(testPass, testPublishOnly, false);
check_access(undefined, testPublishOnly, false);
check_access(badPass, testPublishOnly, false);
check_publish(testPass, testPublishOnly, true);
check_publish(undefined, testPublishOnly, true);
check_publish(badPass, testPublishOnly, true);
check_access('test:test', 'test-publish-only', false)
check_access(undefined, 'test-publish-only', false)
check_access('test:badpass', 'test-publish-only', false)
check_publish('test:test', 'test-publish-only', true)
check_publish(undefined, 'test-publish-only', true)
check_publish('test:badpass', 'test-publish-only', true)
check_access('test:test', 'test-only-test', true)
check_access(undefined, 'test-only-test', false)
check_access('test:badpass', 'test-only-test', false)
check_publish('test:test', 'test-only-test', true)
check_publish(undefined, 'test-only-test', false)
check_publish('test:badpass', 'test-only-test', false)
check_access('test:test', 'test-only-auth', true)
check_access(undefined, 'test-only-auth', false)
check_access('test:badpass', 'test-only-auth', false)
check_publish('test:test', 'test-only-auth', true)
check_publish(undefined, 'test-only-auth', false)
check_publish('test:badpass', 'test-only-auth', false)
})
}
check_access(testPass, testOnlyTest, true);
check_access(undefined, testOnlyTest, false);
check_access(badPass, testOnlyTest, false);
check_publish(testPass, testOnlyTest, true);
check_publish(undefined, testOnlyTest, false);
check_publish(badPass, testOnlyTest, false);
check_access(testPass, testOnlyAuth, true);
check_access(undefined, testOnlyAuth, false);
check_access(badPass, testOnlyAuth, false);
check_publish(testPass, testOnlyAuth, true);
check_publish(undefined, testOnlyAuth, false);
check_publish(badPass, testOnlyAuth, false);
});
};

@ -1,46 +1,47 @@
'use strict';
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function () {
var server = process.server
module.exports = function() {
let server = process.server;
it('add tag - 404', function () {
return server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1')
.status(404)
.body_error(/no such package/)
})
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 () {
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)
})
'(' + 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 testpkg-tag', function() {
// TODO: ?
});
it('add tag - bad ver', function () {
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/)
})
.status(404)
.body_error(/version doesn't exist/);
});
it('add tag - bad tag', function () {
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/)
})
.status(403)
.body_error(/invalid tag/);
});
it('add tag - good', function () {
it('add tag - good', function() {
return server.add_tag('testpkg-tag', 'tagtagtag', '0.0.1')
.status(201)
.body_ok(/tagged/)
})
})
}
.status(201)
.body_ok(/tagged/);
});
});
};

@ -1,47 +1,49 @@
var Server = require('./lib/server')
var fs = require('fs')
var path = require('path')
'use strict';
const Server = require('./lib/server');
const fs = require('fs');
const path = require('path');
module.exports = function() {
var server = new Server('http://localhost:55551/')
const server = new Server('http://localhost:55551/');
describe('adduser', function() {
var user = String(Math.random())
var pass = String(Math.random())
before(function () {
const user = String(Math.random());
const pass = String(Math.random());
before(function() {
return server.auth(user, pass)
.status(201)
.body_ok(/user .* created/)
})
.body_ok(/user .* created/);
});
it('creating new user', function(){})
it('creating new user', function() {});
it('should log in', function () {
it('should log in', function() {
return server.auth(user, pass)
.status(201)
.body_ok(/you are authenticated as/)
})
.body_ok(/you are authenticated as/);
});
it('should not register more users', function () {
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/)
})
})
.body_error(/maximum amount of users reached/);
});
});
describe('adduser created with htpasswd', function() {
var user = 'preexisting'
var pass = 'preexisting'
before(function () {
let user = 'preexisting';
let pass = 'preexisting';
before(function() {
return fs.appendFileSync(
path.join(__dirname, 'test-storage', '.htpasswd'),
'preexisting:$apr1$4YSboUa9$yVKjE7.PxIOuK3M4D7VjX.'
)
})
it('should log in', function () {
);
});
it('should log in', function() {
return server.auth(user, pass)
.status(201)
.body_ok(/you are authenticated as/)
})
})
}
.body_ok(/you are authenticated as/);
});
});
};

@ -1,119 +1,121 @@
require('./lib/startup')
'use strict';
var assert = require('assert')
var crypto = require('crypto')
require('./lib/startup');
const assert = require('assert');
const crypto = require('crypto');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function () {
var server = process.server
var server2 = process.server2
module.exports = function() {
let server = process.server;
let server2 = process.server2;
it('trying to fetch non-existent package', function () {
return server.get_package('testpkg').status(404).body_error(/no such package/)
})
it('trying to fetch non-existent package', function() {
return server.get_package('testpkg').status(404).body_error(/no such package/);
});
describe('testpkg', function () {
before(function () {
return server.add_package('testpkg')
})
describe('testpkg', function() {
before(function() {
return server.add_package('testpkg');
});
it('creating new package', function (){/* test for before() */})
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/)
})
it('downloading non-existent tarball', function() {
return server.get_tarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
});
it('uploading incomplete tarball', function () {
return server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000)
})
it('uploading incomplete tarball', function() {
return server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000);
});
describe('tarball', function () {
before(function () {
describe('tarball', function() {
before(function() {
return server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/)
})
.body_ok(/.*/);
});
it('uploading new tarball', function (){/* test for before() */})
it('uploading new tarball', function() {/* test for before() */});
it('downloading newly created tarball', function () {
it('downloading newly created tarball', function() {
return server.get_tarball('testpkg', 'blahblah')
.status(200)
.then(function (body) {
assert.deepEqual(body, readfile('fixtures/binary'))
})
})
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
});
it('uploading new package version (bad sha)', function () {
var pkg = require('./lib/package')('testpkg')
pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex')
it('uploading new package version (bad sha)', function() {
let pkg = require('./lib/package')('testpkg');
pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex');
return server.put_version('testpkg', '0.0.1', pkg)
.status(400)
.body_error(/shasum error/)
})
.body_error(/shasum error/);
});
describe('version', function () {
before(function () {
var pkg = require('./lib/package')('testpkg')
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
describe('version', function() {
before(function() {
let pkg = require('./lib/package')('testpkg');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
return server.put_version('testpkg', '0.0.1', pkg)
.status(201)
.body_ok(/published/)
})
.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 () {
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'})
})
})
.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 () {
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'})
})
})
})
})
})
.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 () {
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/)
})
.body_error(/no such package/);
});
it('doubleerr test', function () {
it('doubleerr test', function() {
return server.put_tarball('testfwd2', 'blahblah', readfile('fixtures/binary'))
.status(404)
.body_error(/no such/)
})
.body_error(/no such/);
});
it('publishing package / bad ro uplink', function () {
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/)
})
.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')
})
})
}
it('who am I?', function() {
return server.whoami().then(function(username) {
assert.equal(username, 'test');
});
});
};

@ -1,64 +1,66 @@
var assert = require('assert')
var crypto = require('crypto')
'use strict';
const assert = require('assert');
const crypto = require('crypto');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function() {
var server = process.server
var server2 = process.server2
let server = process.server;
let server2 = process.server2;
it('downloading non-existent tarball #1 / srv2', function () {
it('downloading non-existent tarball #1 / srv2', function() {
return server2.get_tarball('testpkg-gh29', 'blahblah')
.status(404)
.body_error(/no such package/)
})
.body_error(/no such package/);
});
describe('pkg-gh29', function() {
before(function () {
before(function() {
return server.put_package('testpkg-gh29', require('./lib/package')('testpkg-gh29'))
.status(201)
.body_ok(/created new package/)
})
.body_ok(/created new package/);
});
it('creating new package / srv1', function(){})
it('creating new package / srv1', function() {});
it('downloading non-existent tarball #2 / srv2', function () {
it('downloading non-existent tarball #2 / srv2', function() {
return server2.get_tarball('testpkg-gh29', 'blahblah')
.status(404)
.body_error(/no such file/)
})
.body_error(/no such file/);
});
describe('tarball', function() {
before(function () {
before(function() {
return server.put_tarball('testpkg-gh29', 'blahblah', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/)
})
.body_ok(/.*/);
});
it('uploading new tarball / srv1', function(){})
it('uploading new tarball / srv1', function() {});
describe('pkg version', function() {
before(function () {
var pkg = require('./lib/package')('testpkg-gh29')
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
before(function() {
let pkg = require('./lib/package')('testpkg-gh29');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
return server.put_version('testpkg-gh29', '0.0.1', pkg)
.status(201)
.body_ok(/published/)
})
.body_ok(/published/);
});
it('uploading new package version / srv1', function(){})
it('uploading new package version / srv1', function() {});
it('downloading newly created tarball / srv2', function () {
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'))
})
})
})
})
})
}
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
});
});
});
});
};

@ -1,69 +1,71 @@
require('./lib/startup')
'use strict';
var assert = require('assert')
require('./lib/startup');
let assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function() {
var server = process.server
var express = process.express
let server = process.server;
let express = process.express;
describe('testexp_gzip', function() {
before(function() {
express.get('/testexp_gzip', function(req, res) {
var x = eval(
let x = eval(
'(' + readfile('fixtures/publish.json5')
.toString('utf8')
.replace(/__NAME__/g, 'testexp_gzip')
.replace(/__VERSION__/g, '0.0.1')
+ ')'
)
);
// overcoming compress threshold
x.versions['0.0.2'] = x.versions['0.0.1']
x.versions['0.0.3'] = x.versions['0.0.1']
x.versions['0.0.4'] = x.versions['0.0.1']
x.versions['0.0.5'] = x.versions['0.0.1']
x.versions['0.0.6'] = x.versions['0.0.1']
x.versions['0.0.7'] = x.versions['0.0.1']
x.versions['0.0.8'] = x.versions['0.0.1']
x.versions['0.0.9'] = x.versions['0.0.1']
x.versions['0.0.2'] = x.versions['0.0.1'];
x.versions['0.0.3'] = x.versions['0.0.1'];
x.versions['0.0.4'] = x.versions['0.0.1'];
x.versions['0.0.5'] = x.versions['0.0.1'];
x.versions['0.0.6'] = x.versions['0.0.1'];
x.versions['0.0.7'] = x.versions['0.0.1'];
x.versions['0.0.8'] = x.versions['0.0.1'];
x.versions['0.0.9'] = x.versions['0.0.1'];
require('zlib').gzip(JSON.stringify(x), function(err, buf) {
assert.equal(err, null)
assert.equal(req.headers['accept-encoding'], 'gzip')
res.header('content-encoding', 'gzip')
res.send(buf)
})
})
assert.equal(err, null);
assert.equal(req.headers['accept-encoding'], 'gzip');
res.header('content-encoding', 'gzip');
res.send(buf);
});
});
express.get('/testexp_baddata', function(req, res) {
assert.equal(req.headers['accept-encoding'], 'gzip')
res.header('content-encoding', 'gzip')
res.send(new Buffer([1,2,3,4,5,6,7,7,6,5,4,3,2,1]))
})
})
assert.equal(req.headers['accept-encoding'], 'gzip');
res.header('content-encoding', 'gzip');
res.send(new Buffer([1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]));
});
});
it('should not fail on bad gzip', function () {
it('should not fail on bad gzip', function() {
return server.get_package('testexp_baddata')
.status(404)
})
.status(404);
});
it('should understand gzipped data from uplink', function () {
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)
.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)
})
})
.then(function(body) {
assert.equal(body.name, 'testexp_gzip');
assert.equal(Object.keys(body.versions).length, 9);
});
});
it('should serve gzipped data', function () {
it('should serve gzipped data', function() {
return server.request({
uri: '/testexp_gzip',
encoding: null,
@ -72,25 +74,25 @@ module.exports = function() {
},
json: false,
}).status(200)
.response(function (res) {
assert.equal(res.headers['content-encoding'], 'gzip')
.response(function(res) {
assert.equal(res.headers['content-encoding'], 'gzip');
})
.then(function (body) {
.then(function(body) {
assert.throws(function() {
JSON.parse(body.toString('utf8'))
})
JSON.parse(body.toString('utf8'));
});
return new Promise(function (resolve) {
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()
})
})
})
})
})
}
assert.equal(err, null);
body = JSON.parse(buf);
assert.equal(body.name, 'testexp_gzip');
assert.equal(Object.keys(body.versions).length, 9);
resolve();
});
});
});
});
});
};

@ -1,67 +1,71 @@
var assert = require('assert')
'use strict';
let assert = require('assert');
module.exports = function() {
var server = process.server
var express = process.express
let server = process.server;
let express = process.express;
describe('Incomplete', function() {
before(function() {
express.get('/testexp-incomplete', function(_, res) {
res.send({
"name": "testexp-incomplete",
"versions": {
"0.1.0": {
"name": "testexp_tags",
"version": "0.1.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55550/testexp-incomplete/-/content-length.tar.gz"
}
'name': 'testexp-incomplete',
'versions': {
'0.1.0': {
'name': 'testexp_tags',
'version': '0.1.0',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-incomplete/-/content-length.tar.gz',
},
},
"0.1.1": {
"name": "testexp_tags",
"version": "0.1.1",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55550/testexp-incomplete/-/chunked.tar.gz"
}
}
}
})
})
'0.1.1': {
'name': 'testexp_tags',
'version': '0.1.1',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-incomplete/-/chunked.tar.gz',
},
},
},
});
});
})
;[ 'content-length', 'chunked' ].forEach(function(type) {
;['content-length', 'chunked'].forEach(function(type) {
it('should not store tarballs / ' + type, function(_cb) {
var called
let called;
express.get('/testexp-incomplete/-/'+type+'.tar.gz', function(_, res) {
if (called) return res.socket.destroy()
called = true
if (type !== 'chunked') res.header('content-length', 1e6)
res.write('test test test\n')
if (called) return res.socket.destroy();
called = true;
if (type !== 'chunked') res.header('content-length', 1e6);
res.write('test test test\n');
setTimeout(function() {
res.socket.write('200\nsss\n')
res.socket.destroy()
cb()
}, 10)
})
res.socket.write('200\nsss\n');
res.socket.destroy();
cb();
}, 10);
});
server.request({ uri: '/testexp-incomplete/-/'+type+'.tar.gz' })
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/))
.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' })
server.request({uri: '/testexp-incomplete/-/'+type+'.tar.gz'})
.body_error('internal server error')
.then(function () { _cb() })
.then(function() {
_cb();
});
}
})
})
})
}
});
});
});
};

@ -1,87 +1,94 @@
//require('es6-shim')
require('./lib/startup')
'use strict';
var assert = require('assert')
var async = require('async')
var exec = require('child_process').exec
require('./lib/startup');
const assert = require('assert');
const exec = require('child_process').exec;
describe('Func', function() {
var server = process.server
var server2 = process.server2
const server = process.server;
const server2 = process.server2;
before(function (cb) {
async.parallel([
function (cb) {
require('./lib/startup').start('./test-storage', './config-1.yaml', cb)
},
function (cb) {
require('./lib/startup').start('./test-storage2', './config-2.yaml', cb)
},
], cb)
})
before(function(done) {
Promise.all([
require('./lib/startup').start('./test-storage', './config-1.yaml'),
require('./lib/startup').start('./test-storage2', './config-2.yaml'),
]).then(() => {
done();
});
});
before(function() {
return Promise.all([ server, server2 ].map(function(server) {
return server.debug().status(200).then(function (body) {
server.pid = body.pid
return new Promise(function (resolve, reject) {
return Promise.all([server, server2].map(function(server) {
return server.debug().status(200).then(function(body) {
server.pid = body.pid;
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()
})
})
})
}))
})
assert.equal(err, null);
server.fdlist = result.replace(/ +/g, ' ');
resolve();
});
});
});
}));
});
before(function auth() {
return Promise.all([ server, server2 ].map(function(server, cb) {
return server.auth('test', 'test').status(201).body_ok(/'test'/)
}))
})
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() */})
it('authenticate', function() {/* test for before() */});
require('./access')()
require('./basic')()
require('./gh29')()
require('./tags')()
require('./gzip')()
require('./incomplete')()
require('./mirror')()
require('./newnpmreg')()
require('./nullstorage')()
require('./race')()
require('./racycrash')()
require('./scoped')()
require('./security')()
require('./adduser')()
require('./logout')()
require('./addtag')()
require('./plugins')()
require('./access')();
require('./basic')();
require('./gh29')();
require('./tags')();
require('./gzip')();
require('./incomplete')();
require('./mirror')();
require('./newnpmreg')();
require('./nullstorage')();
require('./race')();
require('./racycrash')();
require('./scoped')();
require('./security')();
require('./adduser')();
require('./logout')();
require('./addtag')();
require('./plugins')();
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) {
if (q.match(/TCP .*->.* \(ESTABLISHED\)/)) return false
if (q.match(/\/libcrypt-[^\/]+\.so/)) return false
if (q.match(/\/node_modules\/crypt3\/build\/Release/)) return false
return true
}).join('\n').replace(/ +/g, ' ')
after(function(done) {
const check = (server) => {
return new Promise(function(resolve, reject) {
exec('lsof -p ' + parseInt(server.pid, 10), function(err, result) {
if (err) {
reject();
} else {
result = result.split('\n').filter(function(q) {
if (q.match(/TCP .*->.* \(ESTABLISHED\)/)) return false;
if (q.match(/\/libcrypt-[^\/]+\.so/)) return false;
if (q.match(/\/node_modules\/crypt3\/build\/Release/)) return false;
return true;
}).join('\n').replace(/ +/g, ' ');
assert.equal(server.fdlist, result);
resolve();
}
});
});
};
Promise.all([check(server), check(server2)]).then(function() {
done();
}, (reason) => {
assert.equal(reason, null);
done();
});
});
});
assert.equal(server.fdlist, result)
cb()
})
}, cb)
})
})
process.on('unhandledRejection', function (err) {
process.nextTick(function () {
throw err
})
})
process.on('unhandledRejection', function(err) {
process.nextTick(function() {
throw err;
});
});

@ -1,12 +1,11 @@
module.exports = function(name, version) {
return {
"name": name,
"version": version || "0.0.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55551/"+encodeURIComponent(name)+"/-/blahblah"
}
}
}
name,
version: version || '0.0.0',
dist: {
shasum: 'fake',
tarball: `http://localhost:55551/${encodeURIComponent(name)}/-/blahblah`,
},
};
};

@ -1,20 +1,22 @@
var assert = require('assert')
var request = require('./smart_request')
'use strict';
const assert = require('assert');
const request = require('./smart_request');
function Server(url) {
var self = Object.create(Server.prototype)
self.url = url.replace(/\/$/, '')
self.userAgent = 'node/v0.10.8 linux x64'
self.authstr = 'Basic '+(new Buffer('test:test')).toString('base64')
return self
let self = Object.create(Server.prototype);
self.url = url.replace(/\/$/, '');
self.userAgent = 'node/v0.10.8 linux x64';
self.authstr = 'Basic '+(new Buffer('test:test')).toString('base64');
return self;
}
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
assert(options.uri);
let 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,
@ -22,11 +24,11 @@ Server.prototype.request = function(options) {
headers: headers,
encoding: options.encoding,
json: options.json != null ? options.json : true,
})
}
});
};
Server.prototype.auth = function(user, pass) {
this.authstr = 'Basic '+(new Buffer(user+':'+pass)).toString('base64')
this.authstr = 'Basic '+(new Buffer(user+':'+pass)).toString('base64');
return this.request({
uri: '/-/user/org.couchdb.user:'+encodeURIComponent(user)+'/-rev/undefined',
method: 'PUT',
@ -38,76 +40,76 @@ Server.prototype.auth = function(user, pass) {
type: 'user',
roles: [],
date: new Date(),
}
})
}
},
});
};
Server.prototype.logout = function(token) {
return this.request({
uri: '/-/user/token/'+encodeURIComponent(token),
method: 'DELETE'
})
}
method: 'DELETE',
});
};
Server.prototype.get_package = function(name) {
return this.request({
uri: '/'+encodeURIComponent(name),
method: 'GET',
})
}
});
};
Server.prototype.put_package = function(name, data) {
if (typeof(data) === 'object' && !Buffer.isBuffer(data)) data = JSON.stringify(data)
if (typeof(data) === 'object' && !Buffer.isBuffer(data)) data = JSON.stringify(data);
return this.request({
uri: '/'+encodeURIComponent(name),
method: 'PUT',
headers: {
'content-type': 'application/json'
'content-type': 'application/json',
},
}).send(data)
}
}).send(data);
};
Server.prototype.put_version = function(name, version, data) {
if (typeof(data) === 'object' && !Buffer.isBuffer(data)) data = JSON.stringify(data)
if (typeof(data) === 'object' && !Buffer.isBuffer(data)) data = JSON.stringify(data);
return this.request({
uri: '/'+encodeURIComponent(name)+'/'+encodeURIComponent(version)+'/-tag/latest',
method: 'PUT',
headers: {
'content-type': 'application/json'
'content-type': 'application/json',
},
}).send(data)
}
}).send(data);
};
Server.prototype.get_tarball = function(name, filename) {
return this.request({
uri: '/'+encodeURIComponent(name)+'/-/'+encodeURIComponent(filename),
method: 'GET',
encoding: null
})
}
encoding: null,
});
};
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'
'content-type': 'application/octet-stream',
},
}).send(data)
}
}).send(data);
};
Server.prototype.add_tag = function(name, tag, version) {
return this.request({
uri: '/'+encodeURIComponent(name)+'/'+encodeURIComponent(tag),
method: 'PUT',
headers: {
'content-type': 'application/json'
'content-type': 'application/json',
},
}).send(JSON.stringify(version))
}
}).send(JSON.stringify(version));
};
Server.prototype.put_tarball_incomplete = function(name, filename, data, size, cb) {
var promise = this.request({
let promise = this.request({
uri: '/'+encodeURIComponent(name)+'/-/'+encodeURIComponent(filename)+'/whatever',
method: 'PUT',
headers: {
@ -115,51 +117,53 @@ Server.prototype.put_tarball_incomplete = function(name, filename, data, size, c
'content-length': size,
},
timeout: 1000,
})
});
promise.request(function (req) {
req.write(data)
promise.request(function(req) {
req.write(data);
setTimeout(function() {
req.req.abort()
}, 20)
})
req.req.abort();
}, 20);
});
return new Promise(function (resolve, reject) {
return new Promise(function(resolve, reject) {
promise
.then(function() {
reject(Error('no error'))
reject(Error('no error'));
})
.catch(function(err) {
if (err.code === 'ECONNRESET') {
resolve()
resolve();
} else {
reject(err)
reject(err);
}
})
})
}
});
});
};
Server.prototype.add_package = function(name) {
return this.put_package(name, require('./package')(name))
.status(201)
.body_ok('created new package')
}
.body_ok('created new package');
};
Server.prototype.whoami = function() {
return this.request({ uri:'/-/whoami' })
return this.request({uri: '/-/whoami'})
.status(200)
.then(function(x) { return x.username })
}
.then(function(x) {
return x.username;
});
};
Server.prototype.debug = function() {
return this.request({
uri: '/-/_debug',
method: 'GET',
headers: {
'content-type': 'application/json'
'content-type': 'application/json',
},
})
}
});
};
module.exports = Server
module.exports = Server;

@ -1,103 +1,104 @@
'use strict';
var assert = require('assert')
var request = require('request')
var sym = Symbol('smart_request_data')
const assert = require('assert');
const request = require('request');
const sym = Symbol('smart_request_data');
function smart_request(options) {
var self = {}
self[sym] = {}
self[sym].error = Error()
Error.captureStackTrace(self[sym].error, smart_request)
let 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)
})
})
let 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)
return extend(self, result);
}
function extend(self, promise) {
promise[sym] = self[sym]
Object.setPrototypeOf(promise, extensions)
return promise
promise[sym] = self[sym];
Object.setPrototypeOf(promise, extensions);
return promise;
}
var extensions = Object.create(Promise.prototype)
var extensions = Object.create(Promise.prototype);
extensions.status = function (expected) {
var self_data = this[sym]
extensions.status = function(expected) {
let self_data = this[sym];
return extend(this, this.then(function (body) {
return extend(this, this.then(function(body) {
try {
assert.equal(self_data.response.statusCode, expected)
assert.equal(self_data.response.statusCode, expected);
} catch(err) {
self_data.error.message = err.message
throw self_data.error
self_data.error.message = err.message;
throw self_data.error;
}
return body
}))
}
return body;
}));
};
extensions.body_ok = function (expected) {
var self_data = this[sym]
extensions.body_ok = function(expected) {
let self_data = this[sym];
return extend(this, this.then(function (body) {
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)
assert(body.ok.match(expected), '\'' + body.ok + '\' doesn\'t match ' + expected);
} else {
assert.equal(body.ok, expected)
assert.equal(body.ok, expected);
}
assert.equal(body.error, null)
assert.equal(body.error, null);
} catch(err) {
self_data.error.message = err.message
throw self_data.error
self_data.error.message = err.message;
throw self_data.error;
}
return body
}))
}
return body;
}));
};
extensions.body_error = function (expected) {
var self_data = this[sym]
extensions.body_error = function(expected) {
let self_data = this[sym];
return extend(this, this.then(function (body) {
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)
assert(body.error.match(expected), body.error + ' doesn\'t match ' + expected);
} else {
assert.equal(body.error, expected)
assert.equal(body.error, expected);
}
assert.equal(body.ok, null)
assert.equal(body.ok, null);
} catch(err) {
self_data.error.message = err.message
throw self_data.error
self_data.error.message = err.message;
throw self_data.error;
}
return body
}))
}
return body;
}));
};
extensions.request = function (cb) {
cb(this[sym].request)
return this
}
extensions.request = function(cb) {
cb(this[sym].request);
return this;
};
extensions.response = function (cb) {
var self_data = this[sym]
extensions.response = function(cb) {
let self_data = this[sym];
return extend(this, this.then(function (body) {
cb(self_data.response)
return body
}))
}
return extend(this, this.then(function(body) {
cb(self_data.response);
return body;
}));
};
extensions.send = function (data) {
this[sym].request.end(data)
return this
}
extensions.send = function(data) {
this[sym].request.end(data);
return this;
};
module.exports = smart_request
module.exports = smart_request;

@ -1,40 +1,44 @@
var fork = require('child_process').fork
var express = require('express')
var rimraf = require('rimraf')
var Server = require('./server')
'use strict';
var forks = process.forks = []
process.server = Server('http://localhost:55551/')
process.server2 = Server('http://localhost:55552/')
process.express = express()
process.express.listen(55550)
const fork = require('child_process').fork;
const express = require('express');
const rimraf = require('rimraf');
const Server = require('./server');
module.exports.start = function start(dir, conf, cb) {
rimraf(__dirname + '/../' + dir, function() {
// filter out --debug-brk
var oldArgv = process.execArgv
process.execArgv = process.execArgv.filter(function(x) {
return x !== '--debug-brk'
})
const forks = process.forks = [];
process.server = Server('http://localhost:55551/');
process.server2 = Server('http://localhost:55552/');
process.express = express();
process.express.listen(55550);
var f = fork(__dirname + '/../../../bin/verdaccio'
, ['-c', __dirname + '/../' + conf]
, {silent: !process.env.TRAVIS}
)
forks.push(f)
f.on('message', function(msg) {
if ('verdaccio_started' in msg) {
cb(), cb = function(){}
}
})
f.on('error', function(err) {
throw err
})
process.execArgv = oldArgv
})
}
module.exports.start = function(dir, conf) {
return new Promise(function(resolve, reject) {
rimraf(__dirname + '/../' + dir, function() {
// filter out --debug-brk
let oldArgv = process.execArgv;
process.execArgv = process.execArgv.filter(function(x) {
return x !== '--debug-brk';
});
const f = fork(__dirname + '/../../../bin/verdaccio'
, ['-c', __dirname + '/../' + conf]
, {silent: !process.env.TRAVIS}
);
forks.push(f);
f.on('message', function(msg) {
if ('verdaccio_started' in msg) {
resolve();
}
});
f.on('error', function(err) {
reject(err);
});
process.execArgv = oldArgv;
});
});
};
process.on('exit', function() {
if (forks[0]) forks[0].kill()
if (forks[1]) forks[1].kill()
})
if (forks[0]) forks[0].kill();
if (forks[1]) forks[1].kill();
});

@ -1,11 +1,13 @@
'use strict';
module.exports = function() {
var server = process.server
let server = process.server;
describe('logout', function() {
it('should log out', function () {
it('should log out', function() {
return server.logout('some-token')
.status(200)
.body_ok(/Logged out/)
})
})
}
.body_ok(/Logged out/);
});
});
};

@ -1,64 +1,66 @@
var assert = require('assert')
'use strict';
let assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function() {
var server = process.server
var server2 = process.server2
let server = process.server;
let server2 = process.server2;
it('testing anti-loop', function () {
it('testing anti-loop', function() {
return server2.get_package('testloop')
.status(404)
.body_error(/no such package/)
.body_error(/no such package/);
})
;['fwd', /*'loop'*/].forEach(function(pkg) {
var prefix = pkg + ': '
pkg = 'test' + pkg
;['fwd'].forEach(function(pkg) {
let prefix = pkg + ': ';
pkg = 'test' + pkg;
describe(pkg, function() {
before(function () {
before(function() {
return server.put_package(pkg, require('./lib/package')(pkg))
.status(201)
.body_ok(/created new package/)
})
.body_ok(/created new package/);
});
it(prefix+'creating new package', function(){})
it(prefix+'creating new package', function() {});
describe(pkg, function() {
before(function () {
before(function() {
return server.put_version(pkg, '0.1.1', require('./lib/package')(pkg))
.status(201)
.body_ok(/published/)
})
.body_ok(/published/);
});
it(prefix+'uploading new package version', function(){})
it(prefix+'uploading new package version', function() {});
it(prefix+'uploading incomplete tarball', function () {
return server.put_tarball_incomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000)
})
it(prefix+'uploading incomplete tarball', function() {
return server.put_tarball_incomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000);
});
describe('tarball', function() {
before(function () {
before(function() {
return server.put_tarball(pkg, pkg+'.file', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/)
})
.body_ok(/.*/);
});
it(prefix+'uploading new tarball', function(){})
it(prefix+'uploading new tarball', function() {});
it(prefix+'downloading tarball from server1', function () {
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'))
})
})
})
})
})
})
}
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
});
});
});
});
});
};

@ -1,20 +1,22 @@
var assert = require('assert')
'use strict';
let assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
function sha(x) {
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex')
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex');
}
module.exports = function() {
var server = process.server
var server2 = process.server2
var express = process.express
let server = process.server;
let server2 = process.server2;
let express = process.express;
describe('newnpmreg', function() {
before(function () {
before(function() {
return server.request({
uri: '/testpkg-newnpmreg',
headers: {
@ -22,100 +24,100 @@ module.exports = function() {
},
method: 'PUT',
json: JSON.parse(readfile('fixtures/newnpmreg.json')),
}).status(201)
})
}).status(201);
});
it('add pkg', function () {})
it('add pkg', function() {});
it('server1 - tarball', function () {
it('server1 - tarball', function() {
return server.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
.status(200)
.then(function (body) {
.then(function(body) {
// not real sha due to utf8 conversion
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863')
})
})
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
});
});
it('server2 - tarball', function () {
it('server2 - tarball', function() {
return server2.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
.status(200)
.then(function (body) {
.then(function(body) {
// not real sha due to utf8 conversion
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863')
})
})
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
});
});
it('server1 - package', function () {
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'})
})
})
.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 () {
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'})
})
})
.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 () {
return server.request({ uri: '/-/readme/testpkg-newnpmreg' })
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')
})
})
.then(function(body) {
assert.equal(body, '<p>blah blah blah</p>\n');
});
});
it('server2 - readme', function () {
return server2.request({ uri: '/-/readme/testpkg-newnpmreg' })
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')
})
})
.then(function(body) {
assert.equal(body, '<p>blah blah blah</p>\n');
});
});
describe('search', function() {
function check(obj) {
obj['testpkg-newnpmreg'].time.modified = '2014-10-02T07:07:51.000Z'
obj['testpkg-newnpmreg'].time.modified = '2014-10-02T07:07:51.000Z';
assert.deepEqual(obj['testpkg-newnpmreg'],
{ name: 'testpkg-newnpmreg',
description: '',
author: '',
license: 'ISC',
'dist-tags': { latest: '0.0.0' },
maintainers: [ { name: 'alex', email: 'alex@kocharin.ru' } ],
readmeFilename: '',
time: { modified: '2014-10-02T07:07:51.000Z' },
versions: {},
repository: { type: 'git', url: '' } })
{'name': 'testpkg-newnpmreg',
'description': '',
'author': '',
'license': 'ISC',
'dist-tags': {latest: '0.0.0'},
'maintainers': [{name: 'alex', email: 'alex@kocharin.ru'}],
'readmeFilename': '',
'time': {modified: '2014-10-02T07:07:51.000Z'},
'versions': {},
'repository': {type: 'git', url: ''}});
}
before(function () {
before(function() {
express.get('/-/all', function(req, res) {
res.send({})
})
})
res.send({});
});
});
it('server1 - search', function () {
return server.request({ uri: '/-/all' })
it('server1 - search', function() {
return server.request({uri: '/-/all'})
.status(200)
.then(check)
})
.then(check);
});
it('server2 - search', function () {
return server2.request({ uri: '/-/all' })
it('server2 - search', function() {
return server2.request({uri: '/-/all'})
.status(200)
.then(check)
})
})
})
}
.then(check);
});
});
});
};

@ -1,71 +1,73 @@
require('./lib/startup')
'use strict';
var assert = require('assert')
var crypto = require('crypto')
require('./lib/startup');
let assert = require('assert');
let crypto = require('crypto');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function() {
var server = process.server
var server2 = process.server2
let server = process.server;
let server2 = process.server2;
it('trying to fetch non-existent package / null storage', function () {
it('trying to fetch non-existent package / null storage', function() {
return server.get_package('test-nullstorage-nonexist')
.status(404)
.body_error(/no such package/)
})
.body_error(/no such package/);
});
describe('test-nullstorage on server2', function() {
before(function () {
return server2.add_package('test-nullstorage2')
})
before(function() {
return server2.add_package('test-nullstorage2');
});
it('creating new package - server2', function(){/* test for before() */})
it('creating new package - server2', function() {/* test for before() */});
it('downloading non-existent tarball', function () {
it('downloading non-existent tarball', function() {
return server.get_tarball('test-nullstorage2', 'blahblah')
.status(404)
.body_error(/no such file/)
})
.body_error(/no such file/);
});
describe('tarball', function() {
before(function () {
before(function() {
return server2.put_tarball('test-nullstorage2', 'blahblah', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/)
})
.body_ok(/.*/);
});
before(function () {
var pkg = require('./lib/package')('test-nullstorage2')
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
before(function() {
let pkg = require('./lib/package')('test-nullstorage2');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
return server2.put_version('test-nullstorage2', '0.0.1', pkg)
.status(201)
.body_ok(/published/)
})
.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 () {
it('downloading newly created tarball', function() {
return server.get_tarball('test-nullstorage2', 'blahblah')
.status(200)
.then(function (body) {
assert.deepEqual(body, readfile('fixtures/binary'))
})
})
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
});
it('downloading newly created package', function () {
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'})
})
})
})
})
}
.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'});
});
});
});
});
};

@ -1,120 +1,122 @@
require('./lib/startup')
'use strict';
var assert = require('assert')
require('./lib/startup');
let assert = require('assert');
module.exports = function() {
var server2 = process.server2
let server2 = process.server2;
describe('authentication', function() {
var authstr
let authstr;
before(function() {
authstr = server2.authstr
})
authstr = server2.authstr;
});
it('should not authenticate with wrong password', function () {
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() {
return server2.whoami();
})
.then(function (username) {
assert.equal(username, null)
})
})
.then(function(username) {
assert.equal(username, null);
});
});
it('wrong password handled by plugin', function () {
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() {
return server2.whoami();
})
.then(function (username) {
assert.equal(username, null)
})
})
.then(function(username) {
assert.equal(username, null);
});
});
it('right password handled by plugin', function () {
it('right password handled by plugin', function() {
return server2.auth('authtest2', 'blahblah')
.status(201)
.body_ok(/'authtest2'/)
.then(function () {
return server2.whoami()
.then(function() {
return server2.whoami();
})
.then(function (username) {
assert.equal(username, 'authtest2')
})
})
.then(function(username) {
assert.equal(username, 'authtest2');
});
});
after(function() {
server2.authstr = authstr
})
})
server2.authstr = authstr;
});
});
describe('authorization', function() {
var authstr
let authstr;
before(function() {
authstr = server2.authstr
})
authstr = server2.authstr;
});
describe('authtest', function() {
before(function () {
before(function() {
return server2.auth('authtest', 'test')
.status(201)
.body_ok(/'authtest'/)
})
.body_ok(/'authtest'/);
});
it('access test-auth-allow', function () {
it('access test-auth-allow', function() {
return server2.get_package('test-auth-allow')
.status(404)
.body_error('no such package available')
})
.body_error('no such package available');
});
it('access test-auth-deny', function () {
it('access test-auth-deny', function() {
return server2.get_package('test-auth-deny')
.status(403)
.body_error("you're not allowed here")
})
.body_error('you\'re not allowed here');
});
it('access test-auth-regular', function () {
it('access test-auth-regular', function() {
return server2.get_package('test-auth-regular')
.status(404)
.body_error('no such package available')
})
})
.body_error('no such package available');
});
});
describe('authtest2', function() {
before(function () {
before(function() {
return server2.auth('authtest2', 'blahblah')
.status(201)
.body_ok(/'authtest2'/)
})
.body_ok(/'authtest2'/);
});
it('access test-auth-allow', function () {
it('access test-auth-allow', function() {
return server2.get_package('test-auth-allow')
.status(403)
.body_error("i don't know anything about you")
})
.body_error('i don\'t know anything about you');
});
it('access test-auth-deny', function () {
it('access test-auth-deny', function() {
return server2.get_package('test-auth-deny')
.status(403)
.body_error("i don't know anything about you")
})
.body_error('i don\'t know anything about you');
});
it('access test-auth-regular', function () {
it('access test-auth-regular', function() {
return server2.get_package('test-auth-regular')
.status(404)
.body_error('no such package available')
})
})
.body_error('no such package available');
});
});
after(function() {
server2.authstr = authstr
})
})
}
server2.authstr = authstr;
});
});
};

@ -1,25 +1,26 @@
'use strict';
module.exports = Plugin
module.exports = Plugin;
function Plugin(config, stuff) {
var self = Object.create(Plugin.prototype)
self._config = config
return self
let self = Object.create(Plugin.prototype);
self._config = config;
return self;
}
// plugin is expected to be compatible with...
Plugin.prototype.verdaccio_version = '1.1.0'
Plugin.prototype.verdaccio_version = '1.1.0';
Plugin.prototype.authenticate = function(user, password, cb) {
var self = this
let self = this;
if (user !== self._config.accept_user) {
// delegate to next plugin
return cb(null, false)
return cb(null, false);
}
if (password !== self._config.with_password) {
var err = Error("i don't like your password")
err.status = 403
return cb(err)
let err = Error('i don\'t like your password');
err.status = 403;
return cb(err);
}
return cb(null, [ user ])
}
return cb(null, [user]);
};

@ -1,30 +1,31 @@
'use strict';
module.exports = Plugin
module.exports = Plugin;
function Plugin(config, stuff) {
var self = Object.create(Plugin.prototype)
self._config = config
return self
let self = Object.create(Plugin.prototype);
self._config = config;
return self;
}
// plugin is expected to be compatible with...
Plugin.prototype.verdaccio_version = '1.1.0'
Plugin.prototype.verdaccio_version = '1.1.0';
Plugin.prototype.allow_access = function(user, package, cb) {
var self = this
if (!package.handled_by_auth_plugin) {
Plugin.prototype.allow_access = function(user, pkg, cb) {
let self = this;
if (!pkg.handled_by_auth_plugin) {
// delegate to next plugin
return cb(null, false)
return cb(null, false);
}
if (user.name !== self._config.allow_user) {
var err = Error("i don't know anything about you")
err.status = 403
return cb(err)
var err = Error('i don\'t know anything about you');
err.status = 403;
return cb(err);
}
if (package.name !== self._config.to_access) {
var err = Error("you're not allowed here")
err.status = 403
return cb(err)
if (pkg.name !== self._config.to_access) {
var err = Error('you\'re not allowed here');
err.status = 403;
return cb(err);
}
return cb(null, true)
}
return cb(null, true);
};

@ -1,99 +1,105 @@
var assert = require('assert')
var async = require('async')
var _oksum = 0
'use strict';
let assert = require('assert');
let async = require('async');
let _oksum = 0;
module.exports = function() {
var server = process.server
let server = process.server;
describe('race', function() {
before(function () {
before(function() {
return server.put_package('race', require('./lib/package')('race'))
.status(201)
.body_ok(/created new package/)
})
.body_ok(/created new package/);
});
it('creating new package', function(){})
it('creating new package', function() {});
it('uploading 10 same versions', function (callback) {
var fns = []
for (var i=0; i<10; i++) {
it('uploading 10 same versions', function(callback) {
let fns = [];
for (let i=0; i<10; i++) {
fns.push(function(cb_) {
var data = require('./lib/package')('race')
data.rand = Math.random()
let data = require('./lib/package')('race');
data.rand = Math.random();
var _res
let _res;
server.put_version('race', '0.0.1', data)
.response(function (res) { _res = res })
.then(function (body) {
cb_(null, [ _res, body ])
})
})
.response(function(res) {
_res = res;
})
.then(function(body) {
cb_(null, [_res, body]);
});
});
}
async.parallel(fns, function(err, res) {
var okcount = 0
var failcount = 0
let okcount = 0;
let failcount = 0;
assert.equal(err, null)
assert.equal(err, null);
res.forEach(function(arr) {
var resp = arr[0]
var body = arr[1]
let resp = arr[0];
let body = arr[1];
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++
})
assert.equal(okcount + failcount, 10)
assert.equal(okcount, 1)
_oksum += okcount
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++;
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++;
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++;
});
assert.equal(okcount + failcount, 10);
assert.equal(okcount, 1);
_oksum += okcount;
callback()
})
})
callback();
});
});
it('uploading 10 diff versions', function (callback) {
var fns = []
for (var i=0; i<10; i++) {
it('uploading 10 diff versions', function(callback) {
let fns = [];
for (let i=0; i<10; i++) {
;(function(i) {
fns.push(function(cb_) {
var _res
let _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)
.response(function(res) {
_res = res;
})
.then(function(body) {
cb_(null, [_res, body]);
});
});
})(i);
}
async.parallel(fns, function(err, res) {
var okcount = 0
var failcount = 0
let okcount = 0;
let failcount = 0;
assert.equal(err, null)
assert.equal(err, null);
res.forEach(function(arr) {
var resp = arr[0]
var body = arr[1]
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++
})
assert.equal(okcount + failcount, 10)
assert.notEqual(okcount, 1)
_oksum += okcount
let resp = arr[0];
let body = arr[1];
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++;
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++;
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++;
});
assert.equal(okcount + failcount, 10);
assert.notEqual(okcount, 1);
_oksum += okcount;
callback()
})
})
callback();
});
});
after('downloading package', function () {
after('downloading package', function() {
return server.get_package('race')
.status(200)
.then(function (body) {
assert.equal(Object.keys(body.versions).length, _oksum)
})
})
})
}
.then(function(body) {
assert.equal(Object.keys(body.versions).length, _oksum);
});
});
});
};

@ -1,66 +1,70 @@
var assert = require('assert')
'use strict';
let assert = require('assert');
module.exports = function() {
var server = process.server
var express = process.express
let server = process.server;
let express = process.express;
describe('Racy', function() {
var on_tarball
let on_tarball;
before(function() {
express.get('/testexp-racycrash', function(_, res) {
res.send({
"name": "testexp-racycrash",
"versions": {
"0.1.0": {
"name": "testexp_tags",
"version": "0.1.0",
"dist": {
"shasum": "fake",
"tarball": "http://localhost:55550/testexp-racycrash/-/test.tar.gz"
}
}
}
})
})
'name': 'testexp-racycrash',
'versions': {
'0.1.0': {
'name': 'testexp_tags',
'version': '0.1.0',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-racycrash/-/test.tar.gz',
},
},
},
});
});
express.get('/testexp-racycrash/-/test.tar.gz', function(_, res) {
on_tarball(res)
})
})
on_tarball(res);
});
});
it('should not crash on error if client disconnects', function(_cb) {
on_tarball = function(res) {
res.header('content-length', 1e6)
res.write('test test test\n')
res.header('content-length', 1e6);
res.write('test test test\n');
setTimeout(function() {
res.write('test test test\n')
res.socket.destroy()
cb()
}, 200)
}
res.write('test test test\n');
res.socket.destroy();
cb();
}, 200);
};
server.request({ uri: '/testexp-racycrash/-/test.tar.gz' })
.then(function (body) {
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' })
server.request({uri: '/testexp-racycrash'})
.status(200)
.then(function () { _cb() })
.then(function() {
_cb();
});
}
})
});
it('should not store tarball', function () {
it('should not store tarball', function() {
on_tarball = function(res) {
res.socket.destroy()
}
res.socket.destroy();
};
return server.request({ uri: '/testexp-racycrash/-/test.tar.gz' })
.body_error('internal server error')
})
})
}
return server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
.body_error('internal server error');
});
});
};

@ -1,19 +1,21 @@
var assert = require('assert')
'use strict';
let assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
function sha(x) {
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex')
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex');
}
module.exports = function() {
var server = process.server
var server2 = process.server2
let server = process.server;
let server2 = process.server2;
describe('test-scoped', function() {
before(function () {
before(function() {
return server.request({
uri: '/@test%2fscoped',
headers: {
@ -21,58 +23,58 @@ module.exports = function() {
},
method: 'PUT',
json: JSON.parse(readfile('fixtures/scoped.json')),
}).status(201)
})
}).status(201);
});
it('add pkg', function () {})
it('add pkg', function() {});
it('server1 - tarball', function () {
it('server1 - tarball', function() {
return server.get_tarball('@test/scoped', 'scoped-1.0.0.tgz')
.status(200)
.then(function (body) {
.then(function(body) {
// not real sha due to utf8 conversion
assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790')
})
})
assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790');
});
});
it('server2 - tarball', function () {
it('server2 - tarball', function() {
return server2.get_tarball('@test/scoped', 'scoped-1.0.0.tgz')
.status(200)
.then(function (body) {
.then(function(body) {
// not real sha due to utf8 conversion
assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790')
})
})
assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790');
});
});
it('server1 - package', function () {
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'})
})
})
.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 () {
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'})
})
})
.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'});
});
});
it('server2 - nginx workaround', function () {
return server2.request({ uri: '/@test/scoped/1.0.0' })
it('server2 - nginx workaround', function() {
return server2.request({uri: '/@test/scoped/1.0.0'})
.status(200)
.then(function (body) {
assert.equal(body.name, '@test/scoped')
assert.equal(body.dist.tarball, 'http://localhost:55552/@test%2fscoped/-/scoped-1.0.0.tgz')
})
})
})
}
.then(function(body) {
assert.equal(body.name, '@test/scoped');
assert.equal(body.dist.tarball, 'http://localhost:55552/@test%2fscoped/-/scoped-1.0.0.tgz');
});
});
});
};

@ -1,70 +1,72 @@
var assert = require('assert')
'use strict';
const assert = require('assert');
module.exports = function() {
var server = process.server
let server = process.server;
describe('Security', function() {
before(function() {
return server.add_package('testpkg-sec')
})
return server.add_package('testpkg-sec');
});
it('bad pkg #1', function () {
it('bad pkg #1', function() {
return server.get_package('package.json')
.status(403)
.body_error(/invalid package/)
})
.body_error(/invalid package/);
});
it('bad pkg #2', function () {
it('bad pkg #2', function() {
return server.get_package('__proto__')
.status(403)
.body_error(/invalid package/)
})
.body_error(/invalid package/);
});
it('__proto__, connect stuff', function () {
return server.request({ uri: '/testpkg-sec?__proto__=1' })
.then(function (body) {
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)
assert(!body || typeof(body) === 'object' || body.indexOf('node_modules') === -1);
// test for NOT crashing
return server.request({ uri: '/testpkg-sec' }).status(200)
})
})
return server.request({uri: '/testpkg-sec'}).status(200);
});
});
it('do not return package.json as an attachment', function () {
return server.request({ uri: '/testpkg-sec/-/package.json' })
it('do not return package.json as an attachment', function() {
return server.request({uri: '/testpkg-sec/-/package.json'})
.status(403)
.body_error(/invalid filename/)
})
.body_error(/invalid filename/);
});
it('silly things - reading #1', function () {
return server.request({ uri: '/testpkg-sec/-/../../../../../../../../etc/passwd' })
.status(404)
})
it('silly things - reading #1', function() {
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
.status(404);
});
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' })
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/)
})
.body_error(/invalid filename/);
});
it('silly things - writing #1', function () {
it('silly things - writing #1', function() {
return server.put_tarball('testpkg-sec', 'package.json', '{}')
.status(403)
.body_error(/invalid filename/)
})
.body_error(/invalid filename/);
});
it('silly things - writing #3', function () {
it('silly things - writing #3', function() {
return server.put_tarball('testpkg-sec', 'node_modules', '{}')
.status(403)
.body_error(/invalid filename/)
})
.body_error(/invalid filename/);
});
it('silly things - writing #4', function () {
it('silly things - writing #4', function() {
return server.put_tarball('testpkg-sec', '../testpkg.tgz', '{}')
.status(403)
.body_error(/invalid filename/)
})
})
}
.body_error(/invalid filename/);
});
});
};

@ -1,168 +1,170 @@
var assert = require('assert')
'use strict';
const assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x)
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function() {
var server = process.server
var express = process.express
let server = process.server;
let express = process.express;
it('tags - testing for 404', function () {
it('tags - testing for 404', function() {
return server.get_package('testexp_tags')
// shouldn't exist yet
.status(404)
.body_error(/no such package/)
})
.body_error(/no such package/);
});
describe('tags', function() {
before(function () {
before(function() {
express.get('/testexp_tags', function(req, res) {
var f = readfile('fixtures/tags.json').toString().replace(/__NAME__/g, 'testexp_tags')
res.send(JSON.parse(f))
})
})
let f = readfile('fixtures/tags.json').toString().replace(/__NAME__/g, 'testexp_tags');
res.send(JSON.parse(f));
});
});
it('fetching package again', function () {
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')
.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)
})
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 () {
return server.request({uri:'/testexp_tags/'+ver})
it('fetching '+ver, function() {
return server.request({uri: '/testexp_tags/'+ver})
.status(200)
.then(function (body) {
assert.equal(body.version, '0.1.1alpha')
})
})
})
})
.then(function(body) {
assert.equal(body.version, '0.1.1alpha');
});
});
});
});
describe('dist-tags methods', function() {
before(function () {
before(function() {
express.get('/testexp_tags2', function(req, res) {
var f = readfile('fixtures/tags.json').toString().replace(/__NAME__/g, 'testexp_tags2')
res.send(JSON.parse(f))
})
})
let f = readfile('fixtures/tags.json').toString().replace(/__NAME__/g, 'testexp_tags2');
res.send(JSON.parse(f));
});
});
// populate cache
before(function () {
before(function() {
return server.get_package('testexp_tags2')
.status(200)
})
.status(200);
});
beforeEach(function () {
beforeEach(function() {
return server.request({
method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags',
json: {
uri: '/-/package/testexp_tags2/dist-tags',
json: {
foo: '0.1.0',
bar: '0.1.1alpha',
baz: '0.1.2',
},
}).status(201).body_ok(/tags updated/)
})
}).status(201).body_ok(/tags updated/);
});
it('fetching tags', function () {
it('fetching tags', function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function (body) {
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
assert.deepEqual(body,
{ foo: '0.1.0',
{foo: '0.1.0',
bar: '0.1.1alpha',
baz: '0.1.2',
latest: '0.1.3alpha' })
})
})
latest: '0.1.3alpha'});
});
});
it('merging tags', function () {
it('merging tags', function() {
return server.request({
method: 'POST',
uri: '/-/package/testexp_tags2/dist-tags',
json: {
uri: '/-/package/testexp_tags2/dist-tags',
json: {
foo: '0.1.2',
quux: '0.1.0',
},
}).status(201).body_ok(/updated/).then(function () {
}).status(201).body_ok(/updated/).then(function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function (body) {
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
assert.deepEqual(body,
{ foo: '0.1.2',
{foo: '0.1.2',
bar: '0.1.1alpha',
baz: '0.1.2',
quux: '0.1.0',
latest: '0.1.3alpha' })
})
})
})
latest: '0.1.3alpha'});
});
});
});
it('replacing tags', function () {
it('replacing tags', function() {
return server.request({
method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags',
json: {
uri: '/-/package/testexp_tags2/dist-tags',
json: {
foo: '0.1.2',
quux: '0.1.0',
},
}).status(201).body_ok(/updated/).then(function () {
}).status(201).body_ok(/updated/).then(function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function (body) {
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
assert.deepEqual(body,
{ foo: '0.1.2',
{foo: '0.1.2',
quux: '0.1.0',
latest: '0.1.3alpha' })
})
})
})
latest: '0.1.3alpha'});
});
});
});
it('adding a tag', function () {
it('adding a tag', function() {
return server.request({
method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags/foo',
json: '0.1.3alpha',
}).status(201).body_ok(/tagged/).then(function () {
uri: '/-/package/testexp_tags2/dist-tags/foo',
json: '0.1.3alpha',
}).status(201).body_ok(/tagged/).then(function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function (body) {
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
assert.deepEqual(body,
{ foo: '0.1.3alpha',
{foo: '0.1.3alpha',
bar: '0.1.1alpha',
baz: '0.1.2',
latest: '0.1.3alpha' })
})
})
})
latest: '0.1.3alpha'});
});
});
});
it('removing a tag', function () {
it('removing a tag', function() {
return server.request({
method: 'DELETE',
uri: '/-/package/testexp_tags2/dist-tags/foo',
}).status(201).body_ok(/removed/).then(function () {
uri: '/-/package/testexp_tags2/dist-tags/foo',
}).status(201).body_ok(/removed/).then(function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function (body) {
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
assert.deepEqual(body,
{ bar: '0.1.1alpha',
{bar: '0.1.1alpha',
baz: '0.1.2',
latest: '0.1.3alpha' })
})
})
})
})
}
latest: '0.1.3alpha'});
});
});
});
});
};

@ -1,8 +1,9 @@
'use strict';
describe('config.yaml', function() {
it('should be parseable', function() {
var source = require('fs').readFileSync(__dirname + '/../../conf/default.yaml', 'utf8')
require('js-yaml').safeLoad(source)
})
})
let source = require('fs').readFileSync(__dirname + '/../../conf/default.yaml', 'utf8');
require('js-yaml').safeLoad(source);
});
});

@ -1,42 +1,44 @@
var assert = require('assert')
var parse = require('../../lib/utils').parse_address
'use strict';
let assert = require('assert');
let parse = require('../../lib/utils').parse_address;
describe('Parse address', function() {
function addTest(what, proto, host, port) {
it(what, function() {
if (proto === null) {
assert.strictEqual(parse(what), null)
assert.strictEqual(parse(what), null);
} else if (port) {
assert.deepEqual(parse(what), {
proto: proto,
host: host,
port: port,
})
});
} else {
assert.deepEqual(parse(what), {
proto: proto,
path: host,
})
});
}
})
});
}
addTest('4873', 'http', 'localhost', '4873')
addTest(':4873', 'http', 'localhost', '4873')
addTest('blah:4873', 'http', 'blah', '4873')
addTest('http://:4873', 'http', 'localhost', '4873')
addTest('https::4873', 'https', 'localhost', '4873')
addTest('https:blah:4873', 'https', 'blah', '4873')
addTest('https://blah:4873/', 'https', 'blah', '4873')
addTest('[::1]:4873', 'http', '::1', '4873')
addTest('https:[::1]:4873', 'https', '::1', '4873')
addTest('4873', 'http', 'localhost', '4873');
addTest(':4873', 'http', 'localhost', '4873');
addTest('blah:4873', 'http', 'blah', '4873');
addTest('http://:4873', 'http', 'localhost', '4873');
addTest('https::4873', 'https', 'localhost', '4873');
addTest('https:blah:4873', 'https', 'blah', '4873');
addTest('https://blah:4873/', 'https', 'blah', '4873');
addTest('[::1]:4873', 'http', '::1', '4873');
addTest('https:[::1]:4873', 'https', '::1', '4873');
addTest('unix:/tmp/foo.sock', 'http', '/tmp/foo.sock')
addTest('http:unix:foo.sock', 'http', 'foo.sock')
addTest('https://unix:foo.sock', 'https', 'foo.sock')
addTest('unix:/tmp/foo.sock', 'http', '/tmp/foo.sock');
addTest('http:unix:foo.sock', 'http', 'foo.sock');
addTest('https://unix:foo.sock', 'https', 'foo.sock');
addTest('blah', null)
addTest('blah://4873', null)
addTest('https://blah:4873///', null)
addTest('unix:1234', 'http', 'unix', '1234') // not unix socket
})
addTest('blah', null);
addTest('blah://4873', null);
addTest('https://blah:4873///', null);
addTest('unix:1234', 'http', 'unix', '1234'); // not unix socket
});

@ -1,17 +1,19 @@
var ReadTarball = require('../../lib/streams').ReadTarballStream
'use strict';
let ReadTarball = require('../../lib/streams').ReadTarballStream;
describe('mystreams', function() {
it('should delay events', function(cb) {
var test = new ReadTarball()
test.abort()
let test = new ReadTarball();
test.abort();
setTimeout(function() {
test.abort = function() {
cb()
}
cb();
};
test.abort = function() {
throw Error('fail')
}
}, 10)
})
})
throw Error('fail');
};
}, 10);
});
});

@ -1,88 +1,90 @@
var assert = require('assert')
var Storage = require('../../lib/up-storage')
'use strict';
require('../../lib/logger').setup([])
let assert = require('assert');
let Storage = require('../../lib/up-storage');
require('../../lib/logger').setup([]);
function setup(host, config, mainconfig) {
config.url = host
return Storage(config, mainconfig)
config.url = host;
return new Storage(config, mainconfig);
}
describe('Use proxy', function() {
it('should work fine without proxy', function() {
var x = setup('http://x/x', {}, {})
assert.equal(x.proxy, null)
})
let x = setup('http://x/x', {}, {});
assert.equal(x.proxy, null);
});
it('local config should take priority', function() {
var x = setup('http://x/x', {http_proxy: '123'}, {http_proxy: '456'})
assert.equal(x.proxy, '123')
})
let x = setup('http://x/x', {http_proxy: '123'}, {http_proxy: '456'});
assert.equal(x.proxy, '123');
});
it('no_proxy is invalid', function() {
var x = setup('http://x/x', {http_proxy: '123', no_proxy: false}, {})
assert.equal(x.proxy, '123')
var x = setup('http://x/x', {http_proxy: '123', no_proxy: null}, {})
assert.equal(x.proxy, '123')
var x = setup('http://x/x', {http_proxy: '123', no_proxy: []}, {})
assert.equal(x.proxy, '123')
var x = setup('http://x/x', {http_proxy: '123', no_proxy: ''}, {})
assert.equal(x.proxy, '123')
})
var x = setup('http://x/x', {http_proxy: '123', no_proxy: false}, {});
assert.equal(x.proxy, '123');
var x = setup('http://x/x', {http_proxy: '123', no_proxy: null}, {});
assert.equal(x.proxy, '123');
var x = setup('http://x/x', {http_proxy: '123', no_proxy: []}, {});
assert.equal(x.proxy, '123');
var x = setup('http://x/x', {http_proxy: '123', no_proxy: ''}, {});
assert.equal(x.proxy, '123');
});
it('no_proxy - simple/include', function() {
var x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'})
assert.equal(x.proxy, undefined)
})
let x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, undefined);
});
it('no_proxy - simple/not', function() {
var x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'})
assert.equal(x.proxy, '123')
})
let x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'});
assert.equal(x.proxy, '123');
});
it('no_proxy - various, single string', function() {
var x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'})
assert.equal(x.proxy, '123')
var x = setup('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'})
assert.equal(x.proxy, null)
var x = setup('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'})
assert.equal(x.proxy, '123')
var x = setup('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {})
assert.equal(x.proxy, null)
var x = setup('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {})
assert.equal(x.proxy, null)
var x = setup('http://blahh', {http_proxy: '123', no_proxy: 'blah'}, {})
assert.equal(x.proxy, '123')
})
var x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
assert.equal(x.proxy, '123');
var x = setup('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
assert.equal(x.proxy, null);
var x = setup('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'});
assert.equal(x.proxy, '123');
var x = setup('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {});
assert.equal(x.proxy, null);
var x = setup('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {});
assert.equal(x.proxy, null);
var x = setup('http://blahh', {http_proxy: '123', no_proxy: 'blah'}, {});
assert.equal(x.proxy, '123');
});
it('no_proxy - various, array', function() {
var x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'})
assert.equal(x.proxy, '123')
var x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'})
assert.equal(x.proxy, null)
var x = setup('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'})
assert.equal(x.proxy, null)
var x = setup('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'})
assert.equal(x.proxy, '123')
var x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo','bar','blah']})
assert.equal(x.proxy, '123')
var x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: ['foo','bar','blah']})
assert.equal(x.proxy, null)
})
var x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, '123');
var x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, null);
var x = setup('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, null);
var x = setup('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, '123');
var x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
assert.equal(x.proxy, '123');
var x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
assert.equal(x.proxy, null);
});
it('no_proxy - hostport', function() {
var x = setup('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'})
assert.equal(x.proxy, null)
var x = setup('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'})
assert.equal(x.proxy, null)
})
var x = setup('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, null);
var x = setup('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, null);
});
it('no_proxy - secure', function() {
var x = setup('https://something', {http_proxy: '123'}, {})
assert.equal(x.proxy, null)
var x = setup('https://something', {https_proxy: '123'}, {})
assert.equal(x.proxy, '123')
var x = setup('https://something', {http_proxy: '456', https_proxy: '123'}, {})
assert.equal(x.proxy, '123')
})
})
var x = setup('https://something', {http_proxy: '123'}, {});
assert.equal(x.proxy, null);
var x = setup('https://something', {https_proxy: '123'}, {});
assert.equal(x.proxy, '123');
var x = setup('https://something', {http_proxy: '456', https_proxy: '123'}, {});
assert.equal(x.proxy, '123');
});
});

@ -1,34 +1,36 @@
var assert = require('assert')
var parse_interval = require('../../lib/config').parse_interval
'use strict';
let assert = require('assert');
let parse_interval = require('../../lib/config').parse_interval;
describe('Parse interval', function() {
function add_test(str, res) {
it('parse ' + str, function() {
if (res === null) {
assert.throws(function() {
console.log(parse_interval(str))
})
console.log(parse_interval(str));
});
} else {
assert.strictEqual(parse_interval(str), res)
assert.strictEqual(parse_interval(str), res);
}
})
});
}
add_test(12345, 12345000)
add_test('1000', 1000000)
add_test('1.5s', 1500)
add_test('25ms', 25)
add_test('2m', 2*1000*60)
add_test('3h', 3*1000*60*60)
add_test('0.5d', 0.5*1000*60*60*24)
add_test('0.5w', 0.5*1000*60*60*24*7)
add_test('1M', 1000*60*60*24*30)
add_test('5s 20ms', 5020)
add_test('1y', 1000*60*60*24*365)
add_test('1y 5', null)
add_test('1m 1m', null)
add_test('1m 1y', null)
add_test('1y 1M 1w 1d 1h 1m 1s 1ms', 34822861001)
add_test(' 5s 25ms ', 5025)
})
add_test(12345, 12345000);
add_test('1000', 1000000);
add_test('1.5s', 1500);
add_test('25ms', 25);
add_test('2m', 2*1000*60);
add_test('3h', 3*1000*60*60);
add_test('0.5d', 0.5*1000*60*60*24);
add_test('0.5w', 0.5*1000*60*60*24*7);
add_test('1M', 1000*60*60*24*30);
add_test('5s 20ms', 5020);
add_test('1y', 1000*60*60*24*365);
add_test('1y 5', null);
add_test('1m 1m', null);
add_test('1m 1y', null);
add_test('1y 1M 1w 1d 1h 1m 1s 1ms', 34822861001);
add_test(' 5s 25ms ', 5025);
});

@ -1,4 +1,6 @@
var config = {
'use strict';
let config = {
storage: __dirname + '/test-storage',
packages: {
'*': {
@ -6,8 +8,8 @@ var config = {
},
},
logs: [
{type: 'stdout', format: 'pretty', level: 'fatal'}
{type: 'stdout', format: 'pretty', level: 'fatal'},
],
}
};
module.exports = config;

@ -1,39 +1,40 @@
var assert = require('assert');
var Search = require('../../lib/search');
var Storage = require('../../lib/storage');
var config_hash = require('./partials/config');
var Config = require('../../lib/config');
'use strict';
let assert = require('assert');
let Search = require('../../lib/search');
let Storage = require('../../lib/storage');
let config_hash = require('./partials/config');
let Config = require('../../lib/config');
require('../../lib/logger').setup([]);
var packages = [
let packages = [
{
name: 'test1',
description: 'description',
_npmUser: {
name: 'test_user',
}
},
},
{
name: 'test2',
description: 'description',
_npmUser: {
name: 'test_user',
}
},
},
{
name: 'test3',
description: 'description',
_npmUser: {
name: 'test_user',
}
},
},
]
];
describe('search', function() {
before(function() {
var config = Config(config_hash);
let config = Config(config_hash);
this.storage = new Storage(config);
Search.configureStorage(this.storage);
packages.map(function(item) {
@ -42,17 +43,17 @@ describe('search', function() {
});
it('search query item', function() {
var result = Search.query('t');
let result = Search.query('t');
assert(result.length === 3);
});
it('search remove item', function() {
var item = {
let item = {
name: 'test6',
description: 'description',
_npmUser: {
name: 'test_user',
}
},
};
Search.add(item);
var result = Search.query('test6');
@ -61,5 +62,4 @@ describe('search', function() {
var result = Search.query('test6');
assert(result.length === 0);
});
});

@ -1,41 +1,43 @@
var assert = require('assert')
var semver_sort = require('../../lib/utils').semver_sort
var merge = require('../../lib/storage')._merge_versions
'use strict';
require('../../lib/logger').setup([])
let assert = require('assert');
let semver_sort = require('../../lib/utils').semver_sort;
let merge = require('../../lib/storage')._merge_versions;
require('../../lib/logger').setup([]);
describe('Merge', function() {
it('simple', function() {
var x = {
versions: {a:1,b:1,c:1},
let x = {
'versions': {a: 1, b: 1, c: 1},
'dist-tags': {},
}
merge(x, {versions: {a:2,q:2}})
};
merge(x, {versions: {a: 2, q: 2}});
assert.deepEqual(x, {
versions: {a:1,b:1,c:1,q:2},
'versions': {a: 1, b: 1, c: 1, q: 2},
'dist-tags': {},
})
})
});
});
it('dist-tags - compat', function() {
var x = {
versions: {},
'dist-tags': {q:'1.1.1',w:'2.2.2'},
}
merge(x, {'dist-tags':{q:'2.2.2',w:'3.3.3',t:'4.4.4'}})
let x = {
'versions': {},
'dist-tags': {q: '1.1.1', w: '2.2.2'},
};
merge(x, {'dist-tags': {q: '2.2.2', w: '3.3.3', t: '4.4.4'}});
assert.deepEqual(x, {
versions: {},
'dist-tags': {q:'2.2.2',w:'3.3.3',t:'4.4.4'},
})
})
'versions': {},
'dist-tags': {q: '2.2.2', w: '3.3.3', t: '4.4.4'},
});
});
it('semver_sort', function() {
assert.deepEqual(semver_sort(['1.2.3','1.2','1.2.3a','1.2.3c','1.2.3-b']),
[ '1.2.3a',
assert.deepEqual(semver_sort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b']),
['1.2.3a',
'1.2.3-b',
'1.2.3c',
'1.2.3' ]
)
})
})
'1.2.3']
);
});
});

@ -1,44 +1,45 @@
var assert = require('assert')
var tag_version = require('../../lib/utils').tag_version
'use strict';
require('../../lib/logger').setup([])
let assert = require('assert');
let tag_version = require('../../lib/utils').tag_version;
require('../../lib/logger').setup([]);
describe('tag_version', function() {
it('add new one', function() {
var x = {
versions: {},
let x = {
'versions': {},
'dist-tags': {},
}
assert(tag_version(x, '1.1.1', 'foo', {}))
};
assert(tag_version(x, '1.1.1', 'foo', {}));
assert.deepEqual(x, {
versions: {},
'versions': {},
'dist-tags': {foo: '1.1.1'},
})
})
});
});
it('add (compat)', function() {
var x = {
versions: {},
let x = {
'versions': {},
'dist-tags': {foo: '1.1.0'},
}
assert(tag_version(x, '1.1.1', 'foo'))
};
assert(tag_version(x, '1.1.1', 'foo'));
assert.deepEqual(x, {
versions: {},
'versions': {},
'dist-tags': {foo: '1.1.1'},
})
})
});
});
it('add fresh tag', function() {
var x = {
versions: {},
let x = {
'versions': {},
'dist-tags': {foo: '1.1.0'},
}
assert(tag_version(x, '1.1.1', 'foo'))
};
assert(tag_version(x, '1.1.1', 'foo'));
assert.deepEqual(x, {
versions: {},
'versions': {},
'dist-tags': {foo: '1.1.1'},
})
})
})
});
});
});

@ -1,45 +1,47 @@
var assert = require('assert')
var express = require('express')
var request = require('request')
var rimraf = require('rimraf')
var verdaccio = require('../../')
var config = require('./partials/config');
'use strict';
let assert = require('assert');
let express = require('express');
let request = require('request');
let rimraf = require('rimraf');
let verdaccio = require('../../');
let config = require('./partials/config');
describe('toplevel', function() {
var port
let port;
before(function(done) {
rimraf(__dirname + '/test-storage', done)
})
rimraf(__dirname + '/test-storage', done);
});
before(function(done) {
var app = express()
app.use(verdaccio(config))
let app = express();
app.use(verdaccio(config));
var server = require('http').createServer(app)
let server = require('http').createServer(app);
server.listen(0, function() {
port = server.address().port
done()
})
})
port = server.address().port;
done();
});
});
it('should respond on /', function(done) {
request({
url: 'http://localhost:' + port + '/',
}, function(err, res, body) {
assert.equal(err, null)
assert(body.match(/<title>Verdaccio<\/title>/))
done()
})
})
assert.equal(err, null);
assert(body.match(/<title>Verdaccio<\/title>/));
done();
});
});
it('should respond on /whatever', function(done) {
request({
url: 'http://localhost:' + port + '/whatever',
}, function(err, res, body) {
assert.equal(err, null)
assert(body.match(/no such package available/))
done()
})
})
})
assert.equal(err, null);
assert(body.match(/no such package available/));
done();
});
});
});

@ -1,42 +1,44 @@
var assert = require('assert')
var validate = require('../../lib/utils').validate_name
'use strict';
let assert = require('assert');
let validate = require('../../lib/utils').validate_name;
describe('Validate', function() {
it('good ones', function() {
assert( validate('verdaccio') )
assert( validate('some.weird.package-zzz') )
assert( validate('old-package@0.1.2.tgz') )
})
assert( validate('verdaccio') );
assert( validate('some.weird.package-zzz') );
assert( validate('old-package@0.1.2.tgz') );
});
it('uppercase', function() {
assert( validate('EVE') )
assert( validate('JSONStream') )
})
assert( validate('EVE') );
assert( validate('JSONStream') );
});
it('no package.json', function() {
assert( !validate('package.json') )
})
assert( !validate('package.json') );
});
it('no path seps', function() {
assert( !validate('some/thing') )
assert( !validate('some\\thing') )
})
assert( !validate('some/thing') );
assert( !validate('some\\thing') );
});
it('no hidden', function() {
assert( !validate('.bin') )
})
assert( !validate('.bin') );
});
it('no reserved', function() {
assert( !validate('favicon.ico') )
assert( !validate('node_modules') )
assert( !validate('__proto__') )
})
assert( !validate('favicon.ico') );
assert( !validate('node_modules') );
assert( !validate('__proto__') );
});
it('other', function() {
assert( !validate('pk g') )
assert( !validate('pk\tg') )
assert( !validate('pk%20g') )
assert( !validate('pk+g') )
assert( !validate('pk:g') )
})
})
assert( !validate('pk g') );
assert( !validate('pk\tg') );
assert( !validate('pk%20g') );
assert( !validate('pk+g') );
assert( !validate('pk:g') );
});
});

@ -1,39 +1,41 @@
'use strict';
// ensure that all arguments are validated
var assert = require('assert')
let assert = require('assert');
describe('index.js app', test('index.js'))
describe('index-api.js app', test('index-api.js'))
describe('index-web.js app', test('index-web.js'))
describe('index.js app', test('index.js'));
describe('index-api.js app', test('index-api.js'));
describe('index-web.js app', test('index-web.js'));
function test(file) {
return function() {
var source = require('fs').readFileSync(__dirname + '/../../lib/' + file, 'utf8')
let source = require('fs').readFileSync(__dirname + '/../../lib/' + file, 'utf8');
var very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g
var m
var params = {}
let very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
let m;
let params = {};
while ((m = very_scary_regexp.exec(source)) != null) {
if (m[1] === 'set') continue
if (m[1] === 'set') continue;
var inner = m[2].slice(1, m[2].length-1)
var t
let inner = m[2].slice(1, m[2].length-1);
var t;
inner.split('/').forEach(function(x) {
if (m[1] === 'param') {
params[x] = 'ok'
params[x] = 'ok';
} else if (t = x.match(/^:([^?:]*)\??$/)) {
params[t[1]] = params[t[1]] || m[0].trim()
params[t[1]] = params[t[1]] || m[0].trim();
}
})
});
}
Object.keys(params).forEach(function(param) {
it('should validate ":'+param+'"', function() {
assert.equal(params[param], 'ok')
})
})
}
assert.equal(params[param], 'ok');
});
});
};
}