Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
lookup a user.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored and othiym23 committed Jan 16, 2015
1 parent 63afb72 commit 5eb31ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
53 changes: 29 additions & 24 deletions lib/star.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = star

var assert = require("assert")
var assert = require("assert"),
url = require("url")

function star (uri, params, cb) {
assert(typeof uri === "string", "must pass registry URI to star")
Expand All @@ -21,28 +22,32 @@ function star (uri, params, cb) {
var client = this
this.request(uri+"?write=true", { auth : auth }, function (er, fullData) {
if (er) return cb(er)

fullData = {
_id : fullData._id,
_rev : fullData._rev,
users : fullData.users || {}
}

if (starred) {
client.log.info("starring", fullData._id)
fullData.users[auth.username] = true
client.log.verbose("starring", fullData)
} else {
delete fullData.users[auth.username]
client.log.info("unstarring", fullData._id)
client.log.verbose("unstarring", fullData)
}

var options = {
method : "PUT",
body : fullData,
auth : auth
}
return client.request(uri, options, cb)

client.whoami(uri, params, function(err, username) {
if (er) return cb(er)

fullData = {
_id : fullData._id,
_rev : fullData._rev,
users : fullData.users || {}
}

if (starred) {
client.log.info("starring", fullData._id)
fullData.users[username] = true
client.log.verbose("starring", fullData)
} else {
delete fullData.users[username]
client.log.info("unstarring", fullData._id)
client.log.verbose("unstarring", fullData)
}

var options = {
method : "PUT",
body : fullData,
auth : auth
}
return client.request(uri, options, cb)
})
})
}
9 changes: 9 additions & 0 deletions test/star.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ test("if token auth, sets bearer on get and put", function(t) {
.get('/underscore?write=true')
.reply(200, {})

var getUser = nock('http://localhost:1010', {
reqheaders: {
authorization: 'Bearer foo'
}
})
.get('/-/whoami')
.reply(200)

var starPut = nock('http://localhost:1010', {
reqheaders: {
authorization: 'Bearer foo'
Expand All @@ -160,6 +168,7 @@ test("if token auth, sets bearer on get and put", function(t) {
client.star("http://localhost:1010/underscore", params, function (error, data) {
starGet.done()
starPut.done()
getUser.done()
t.end()
})
})

0 comments on commit 5eb31ed

Please sign in to comment.