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

Commit 9ab131e

Browse files
michaelnisizkat
authored andcommitted
Add ping command
1 parent 10d4d4c commit 9ab131e

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

lib/ping.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
module.exports = ping
3+
4+
var url = require("url")
5+
6+
function ping (uri, cb) {
7+
var c = this.conf.getCredentialsByURI(uri)
8+
if (!c || !c.auth) {
9+
var er = new Error("Must be logged in to ping the registry")
10+
er.code = "ENEEDAUTH"
11+
return cb(er)
12+
}
13+
var parsed = url.parse(uri)
14+
parsed.auth = c.username + ":" + escape(c.password)
15+
uri = url.resolve(parsed, "/-/ping?write=true")
16+
this.get(uri, null, function (er, fullData) {
17+
if (er) {
18+
cb(er)
19+
} else if (fullData) {
20+
console.log(fullData)
21+
cb(null, fullData)
22+
} else {
23+
cb(new Error("No data received"))
24+
}
25+
})
26+
}

test/ping.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var tap = require("tap")
2+
3+
var server = require("./lib/server.js")
4+
var common = require("./lib/common.js")
5+
6+
var DEP_USER = "username"
7+
var HOST = "localhost"
8+
9+
var nerfed = "//" + HOST + ":" + server.port + "/:"
10+
11+
var configuration = {}
12+
configuration[nerfed + "username"] = DEP_USER
13+
configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64")
14+
configuration[nerfed + "email"] = "[email protected]"
15+
16+
var client = common.freshClient(configuration)
17+
18+
tap.test("ping registry", function (t) {
19+
t.plan(3)
20+
server.expect("GET", "/-/ping?write=true", function (req, res) {
21+
t.equal(req.method, "GET")
22+
res.statusCode = 200
23+
res.json({
24+
ok: true
25+
, host: HOST
26+
, peer: HOST
27+
, username: DEP_USER
28+
})
29+
})
30+
31+
client.ping(common.registry, function (er, found) {
32+
t.ifError(er, "no errors")
33+
var wanted = {
34+
ok: true
35+
, host: HOST
36+
, peer: HOST
37+
, username: DEP_USER
38+
}
39+
t.same(found, wanted)
40+
t.end()
41+
})
42+
})

0 commit comments

Comments
 (0)