Skip to content

Commit cf63e38

Browse files
committed
implement logout endpoint(detail: rlidwka#297)
1 parent 3f55fb4 commit cf63e38

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/index-api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = function(config, auth, storage) {
2222
app.param('tag', validate_name)
2323
app.param('version', validate_name)
2424
app.param('revision', validate_name)
25+
app.param('token', validate_name)
2526

2627
// these can't be safely put into express url for some reason
2728
app.param('_rev', match(/^-rev$/))
@@ -202,6 +203,13 @@ module.exports = function(config, auth, storage) {
202203
}
203204
})
204205

206+
app.delete('/-/user/token/:token', function(req, res, next) {
207+
res.status(200)
208+
next({
209+
ok: 'Logged out',
210+
})
211+
})
212+
205213
function tag_package_version(req, res, next) {
206214
if (typeof(req.body) !== 'string') return next('route')
207215

test/functional/lib/server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Server.prototype.auth = function(user, pass) {
4343
})
4444
}
4545

46+
Server.prototype.logout = function(token) {
47+
return this.request({
48+
uri: '/-/user/token/'+encodeURIComponent(token),
49+
method: 'DELETE'
50+
})
51+
}
52+
4653
Server.prototype.get_package = function(name) {
4754
return this.request({
4855
uri: '/'+encodeURIComponent(name),

test/functional/logout.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = function() {
2+
var server = process.server
3+
4+
describe('logout', function() {
5+
it('should log out', function () {
6+
return server.logout('some-token')
7+
.status(200)
8+
.body_ok(/Logged out/)
9+
})
10+
})
11+
}

0 commit comments

Comments
 (0)