Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

whoami talks to an endpoint with bearer auth

  • Loading branch information...
commit 5fca7c8605dcf43b13b6c369e409f5dda203c35b 1 parent cfd16e0
@othiym23 othiym23 authored
Showing with 45 additions and 0 deletions.
  1. +15 −0 lib/whoami.js
  2. +30 −0 test/whoami.js
View
15 lib/whoami.js
@@ -0,0 +1,15 @@
+module.exports = whoami
+
+var url = require("url")
+
+function whoami (uri, cb) {
+ if (!this.conf.getCredentialsByURI(uri)) {
+ return cb(new Error("Must be logged in to see who you are"))
+ }
+
+ this.request("GET", url.resolve(uri, "whoami"), null, function (er, userdata) {
+ if (er) return cb(er)
+
+ cb(null, userdata.username)
+ })
+}
View
30 test/whoami.js
@@ -0,0 +1,30 @@
+var tap = require("tap")
+
+var server = require("./lib/server.js")
+var common = require("./lib/common.js")
+
+var nerfed = "//localhost:" + server.port + "/:"
+
+var configuration = {}
+configuration[nerfed + "_authToken"] = "not-bad-meaning-bad-but-bad-meaning-wombat"
+
+var client = common.freshClient(configuration)
+
+var WHOIAM = "wombat"
+
+tap.test("whoami", function (t) {
+ server.expect("GET", "/whoami", function (req, res) {
+ t.equal(req.method, "GET")
+ // only available for token-based auth for now
+ t.equal(req.headers.authorization, "Bearer not-bad-meaning-bad-but-bad-meaning-wombat")
+
+ res.json({username : WHOIAM})
+ })
+
+ client.whoami(common.registry, function (error, wombat) {
+ t.ifError(error, "no errors")
+ t.equal(wombat, WHOIAM, "im a wombat")
+
+ t.end()
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.