Skip to content

Commit

Permalink
Updates git client logging
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Jan 24, 2025
1 parent 04d1122 commit 9149c55
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/clients/git/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,49 @@ var auth = require("http-auth");
var Blog = require("models/blog");
var User = require("models/user");
var database = require("./database");
var clfdate = require("helper/clfdate");

module.exports = auth.connect(
// Beware that req as fourth argument might not be reliable:
// https://github.com/http-auth/http-auth/pull/67#issuecomment-244306701
auth.basic({ realm: "Git" }, function (email, token, callback, req) {

console.log(clfdate() + " Git: authenticate: checking user and token");

User.getByEmail(email, function (err, user) {
// There is no user with this email address
if (err || !user) {
console.log(clfdate() + " Git: authenticate: no user with email", email);
return callback(false);
}

console.log(clfdate() + " Git: authenticate: checking token");

database.checkToken(user.uid, token, function (err, valid) {
// The token is bad
if (err || !valid) return callback(false);
if (err || !valid) {
console.log(clfdate() + " Git: authenticate: bad token for user", user.uid);
return callback(false);
}

// User is attempting to push or pull another user's repo
Blog.get({ handle: req.params.gitHandle }, function (err, blog) {
// There is no blog with this handle
if (err || !blog) {
console.log(clfdate() + " Git: authenticate: no blog with handle", req.params.gitHandle);
return callback(false);
}

// The account associated with this email does not have permission
// to modify this blog.
if (blog.owner !== user.uid) {
console.log(clfdate() + " Git: authenticate: user", user.uid, "does not own blog", blog.id);
return callback(false);
}

req.blog = blog;

console.log(clfdate() + " Git: authenticate: user", user.uid, "has permission to modify blog", blog.id);
callback(true);
});
});
Expand Down

0 comments on commit 9149c55

Please sign in to comment.