From 25e00a317268329a544ae3f108a4a3809d23fea9 Mon Sep 17 00:00:00 2001 From: Miguel Mejias Date: Wed, 10 Aug 2016 12:14:08 +0200 Subject: [PATCH] Implement logout endpoint --- lib/index-api.js | 8 ++++++++ test/functional/index.js | 2 +- test/functional/lib/server.js | 7 +++++++ test/functional/logout.js | 11 +++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/functional/logout.js diff --git a/lib/index-api.js b/lib/index-api.js index fa2a6e9d6..6483c11b4 100644 --- a/lib/index-api.js +++ b/lib/index-api.js @@ -24,6 +24,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$/)) @@ -204,6 +205,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') diff --git a/test/functional/index.js b/test/functional/index.js index c424eaa2c..34df7fd1c 100644 --- a/test/functional/index.js +++ b/test/functional/index.js @@ -59,6 +59,7 @@ describe('Func', function() { require('./scoped')() require('./security')() require('./adduser')() + require('./logout')() require('./addtag')() require('./plugins')() @@ -85,4 +86,3 @@ process.on('unhandledRejection', function (err) { throw err }) }) - diff --git a/test/functional/lib/server.js b/test/functional/lib/server.js index 8b21d7097..4a1af0ef7 100644 --- a/test/functional/lib/server.js +++ b/test/functional/lib/server.js @@ -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), diff --git a/test/functional/logout.js b/test/functional/logout.js new file mode 100644 index 000000000..3729e70c9 --- /dev/null +++ b/test/functional/logout.js @@ -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/) + }) + }) +}