0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-17 23:45:29 -05:00
This commit is contained in:
Alex Kocharin 2013-09-25 14:01:55 +04:00
parent 11bf03f130
commit 709ffe8e39
4 changed files with 67 additions and 36 deletions

View file

@ -27,9 +27,6 @@ dependencies:
minimatch: '*'
through: '*'
devDependencies:
galaxy: '*' # and node 0.11.2+ for testing
keywords: # TODO
- private
- repository

View file

@ -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
View 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;

View file

@ -1,17 +1,14 @@
#!/usr/local/bin/node --harmony
#!/usr/bin/env node
var galaxy = require('galaxy');
var Auth = galaxy.star(require('./lib/auth'));
var sleep = galaxy.star(function(ms, cb) {
setTimeout(cb, ms);
});
var Server = require('./lib/server');
process.argv = ['node', 'sinopia', '-c', './config.yaml'];
require('../bin/sinopia');
galaxy.unstar(function*() {
sleep(1000);
yield Auth.auth('test', 'test');
})();
setTimeout(function() {
var server = new Server('http://localhost:55550/');
server.auth('test', 'test', function() {
console.log('ok');
});
}, 1000);