Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port updates from upstream #2

Merged
merged 3 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ function Config(config) {
}
}

if (!self.npm_client_version) {
self.npm_client_version = "*"
}

if (!self.sentry_dsn) {
self.sentry_dsn = process.env.SENTRY_DSN;
}

var users = {all:true, anonymous:true, 'undefined':true, owner:true, none:true}

var check_user_or_uplink = function(arg) {
Expand Down
14 changes: 14 additions & 0 deletions lib/index-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var expressJson5 = require('express-json5')
var Error = require('http-errors')
var Path = require('path')
var Middleware = require('./middleware')
var Semver = require('semver');
var Utils = require('./utils')
var expect_json = Middleware.expect_json
var match = Middleware.match
Expand All @@ -22,6 +23,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 @@ -165,6 +167,11 @@ module.exports = function(config, auth, storage) {
var token = (req.body.name && req.body.password)
? auth.aes_encrypt(req.body.name + ':' + req.body.password).toString('base64')
: undefined

if (!Semver.satisfies(req.header('version'), config.npm_client_version) && config.npm_client_version !== '*') {
return next( Error[422]('Your npm version is not accepted. Required: "' + config.npm_client_version + '" Received: "' + req.header('version') + '"') )
}

if (req.remote_user.name != null) {
res.status(201)
return next({
Expand Down Expand Up @@ -202,6 +209,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
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var express = require('express')
var Error = require('http-errors')
var compression = require('compression')
var raven = require('raven')
var Auth = require('./auth')
var Logger = require('./logger')
var Config = require('./config')
Expand All @@ -16,13 +17,20 @@ module.exports = function(config_hash) {
var storage = Storage(config)
var auth = Auth(config)
var app = express()
var ravenClient = config.sentry_dsn ? new raven.Client(config.sentry_dsn) : null

if (ravenClient) {
ravenClient.patchGlobal()
}
// run in production mode by default, just in case
// it shouldn't make any difference anyway
app.set('env', process.env.NODE_ENV || 'production')

function error_reporting_middleware(req, res, next) {
res.report_error = res.report_error || function(err) {
if (ravenClient) {
raven.middleware.express.errorHandler(ravenClient)(err, req, res, next)
}
if (err.status && err.status >= 400 && err.status < 600) {
if (!res.headersSent) {
res.status(err.status)
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
jju: '1.x'
JSONStream: '1.x'

raven: '>=0.10.0'
mkdirp: '>=0.3.5 <1.0.0-0'
sinopia-htpasswd: '>= 0.4.3'
http-errors: '>=1.2.0'
Expand Down
1 change: 1 addition & 0 deletions test/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('Func', function() {
require('./scoped')()
require('./security')()
require('./adduser')()
require('./logout')()
require('./addtag')()
require('./plugins')()

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/)
})
})
}