Permalink
Browse files

have git authenticate with basic auth over http with the opts.secret …

…if provided
  • Loading branch information...
1 parent 363c5a9 commit c01ef9f4a9afb6bbb9305b9104068364b1ece980 @substack committed Jul 28, 2012
Showing with 30 additions and 5 deletions.
  1. +7 −2 index.js
  2. +20 −0 lib/web.js
  3. +1 −1 package.json
  4. +2 −2 test/command.js
View
@@ -30,7 +30,7 @@ function Propagit (opts) {
}
this.readable = true;
- this.secret = opts.secret;
+ this.secret = opts.secret || '';
this.middleware = [];
var base = opts.basedir || process.cwd();
@@ -53,11 +53,16 @@ Propagit.prototype.connect = function (hub) {
}
self.hub = upnode.connect(hub, function (remote, conn) {
+ var auth = self.secret && 'git:' + encodeURIComponent(self.secret);
+
remote.auth(self.secret, function (err, res) {
if (err) self.emit('error', err)
else {
self.ports = res.ports;
- self.gitUri = 'http://' + hub.host + ':' + self.ports.git;
+ self.gitUri = 'http://'
+ + (self.secret ? auth + '@' : '')
+ + hub.host + ':' + self.ports.git
+ ;
conn.emit('up', res);
};
});
View
@@ -2,6 +2,26 @@ var http = require('http');
module.exports = function (repos, secret) {
return http.createServer(function (req, res) {
+ if (!secret) return repos.handle(req, res);
+
+ if (!req.headers.authorization) {
+ res.statusCode = 401;
+ res.setHeader('www-authenticate', 'Basic');
+ res.end('must authenticate with basic auth');
+ return;
+ }
+ var m = req.headers.authorization.match(/^Basic (\S+)/);
+ if (!m) {
+ res.statusCode = 401;
+ return res.end('unsupported authorization format');
+ }
+
+ var s = Buffer(m[1], 'base64').toString().split(':');
+ if (s[0] !== 'git' || s[1] !== secret) {
+ res.statusCode = 401;
+ return res.end('invalid secret phrase');
+ }
+
return repos.handle(req, res);
});
};
View
@@ -1,7 +1,7 @@
{
"name" : "propagit",
"description" : "cascading multi-server git deployment",
- "version" : "0.5.5",
+ "version" : "0.6.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/propagit.git"
View
@@ -44,9 +44,9 @@ test('command line deploy', function (t) {
'git commit -m"web server"',
'git log|head -n1',
function (line) {
- var commit = line.split(/\s+/)[1]
+ var commit = line.split(/\s+/)[1];
exec(
- 'git push http://localhost:'
+ 'git push http://git:beepboop@localhost:'
+ (port + 1)
+ '/webapp.git master',
opts,

0 comments on commit c01ef9f

Please sign in to comment.