mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-17 23:45:29 -05:00
tests
This commit is contained in:
parent
11bf03f130
commit
709ffe8e39
4 changed files with 67 additions and 36 deletions
|
@ -27,9 +27,6 @@ dependencies:
|
||||||
minimatch: '*'
|
minimatch: '*'
|
||||||
through: '*'
|
through: '*'
|
||||||
|
|
||||||
devDependencies:
|
|
||||||
galaxy: '*' # and node 0.11.2+ for testing
|
|
||||||
|
|
||||||
keywords: # TODO
|
keywords: # TODO
|
||||||
- private
|
- private
|
||||||
- repository
|
- repository
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
|
|
||||||
var request = require('request');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
module.exports.auth = function(user, pass, cb) {
|
|
||||||
request({
|
|
||||||
url: 'http://localhost:55550/-/user/org.couchdb.user:'+escape(user)+'/-rev/undefined',
|
|
||||||
method: 'PUT',
|
|
||||||
headers: {
|
|
||||||
accept: 'application/json',
|
|
||||||
'user-agent': 'node/v0.10.8 linux x64',
|
|
||||||
authorization: 'Basic '+(new Buffer(user+':'+pass)).toString('base64'),
|
|
||||||
},
|
|
||||||
json: {
|
|
||||||
content: "doesn't matter, 'cause sinopia uses info from Authorization header anywayz",
|
|
||||||
}
|
|
||||||
}, function(req, res, body) {
|
|
||||||
assert.notEqual(body.ok.indexOf('"'+user+'"'), -1);
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
59
test/lib/server.js
Normal file
59
test/lib/server.js
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
var request = require('request');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
function Server(url) {
|
||||||
|
if (!(this instanceof Server)) return new Server(url);
|
||||||
|
this.url = url.replace(/\/$/, '');
|
||||||
|
this.userAgent = 'node/v0.10.8 linux x64';
|
||||||
|
}
|
||||||
|
|
||||||
|
Server.prototype.request = function(options, cb) {
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
|
||||||
|
return request({
|
||||||
|
url: this.url + options.uri,
|
||||||
|
method: options.method || 'GET',
|
||||||
|
headers: {
|
||||||
|
accept: options.headers.accept || 'application/json',
|
||||||
|
'user-agent': options.headers['user-agent'] || this.userAgent,
|
||||||
|
authorization: this.auth,
|
||||||
|
},
|
||||||
|
json: options.json
|
||||||
|
}, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Server.prototype.auth = function(user, pass, cb) {
|
||||||
|
this.auth = 'Basic '+(new Buffer(user+':'+pass)).toString('base64');
|
||||||
|
this.request({
|
||||||
|
uri: '/-/user/org.couchdb.user:'+escape(user)+'/-rev/undefined',
|
||||||
|
method: 'PUT',
|
||||||
|
json: {
|
||||||
|
content: "doesn't matter, 'cause sinopia uses info from Authorization header anywayz",
|
||||||
|
}
|
||||||
|
}, function(req, res, body) {
|
||||||
|
assert.notEqual(body.ok.indexOf('"'+user+'"'), -1);
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Server.prototype.get_package = function(name, cb) {
|
||||||
|
request({
|
||||||
|
uri: '/'+name,
|
||||||
|
method: 'GET',
|
||||||
|
}, function(req, res, body) {
|
||||||
|
cb(body);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Server.prototype.put_package = function(name, data, cb) {
|
||||||
|
request({
|
||||||
|
uri: '/'+name,
|
||||||
|
method: 'PUT',
|
||||||
|
json: data,
|
||||||
|
}, function(req, res, body) {
|
||||||
|
cb(body);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Server;
|
||||||
|
|
19
test/run.js
19
test/run.js
|
@ -1,17 +1,14 @@
|
||||||
#!/usr/local/bin/node --harmony
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var galaxy = require('galaxy');
|
var Server = require('./lib/server');
|
||||||
var Auth = galaxy.star(require('./lib/auth'));
|
|
||||||
|
|
||||||
var sleep = galaxy.star(function(ms, cb) {
|
|
||||||
setTimeout(cb, ms);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.argv = ['node', 'sinopia', '-c', './config.yaml'];
|
process.argv = ['node', 'sinopia', '-c', './config.yaml'];
|
||||||
require('../bin/sinopia');
|
require('../bin/sinopia');
|
||||||
|
|
||||||
galaxy.unstar(function*() {
|
setTimeout(function() {
|
||||||
sleep(1000);
|
var server = new Server('http://localhost:55550/');
|
||||||
yield Auth.auth('test', 'test');
|
server.auth('test', 'test', function() {
|
||||||
})();
|
console.log('ok');
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue