Skip to content

Commit

Permalink
implement logout endpoint(detail: rlidwka#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
braveoyster committed Mar 17, 2017
1 parent 3f55fb4 commit cf63e38
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function(config, auth, storage) {
app.param('tag', validate_name)
app.param('version', validate_name)
app.param('revision', validate_name)
app.param('token', validate_name)

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

app.delete('/-/user/token/:token', function(req, res, next) {
res.status(200)
next({
ok: 'Logged out',
})
})

function tag_package_version(req, res, next) {
if (typeof(req.body) !== 'string') return next('route')

Expand Down
7 changes: 7 additions & 0 deletions test/functional/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Server.prototype.auth = function(user, pass) {
})
}

Server.prototype.logout = function(token) {
return this.request({
uri: '/-/user/token/'+encodeURIComponent(token),
method: 'DELETE'
})
}

Server.prototype.get_package = function(name) {
return this.request({
uri: '/'+encodeURIComponent(name),
Expand Down
11 changes: 11 additions & 0 deletions test/functional/logout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function() {
var server = process.server

describe('logout', function() {
it('should log out', function () {
return server.logout('some-token')
.status(200)
.body_ok(/Logged out/)
})
})
}

0 comments on commit cf63e38

Please sign in to comment.