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

Update dependencies to enable Greenkeeper 🌴 #544

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# hoodie-server

[![Greenkeeper badge](https://badges.greenkeeper.io/hoodiehq/hoodie-server.svg)](https://greenkeeper.io/)

> Hapi plugin for Hoodie’s server core module

[![Build Status](https://travis-ci.org/hoodiehq/hoodie-server.svg?branch=master)](https://travis-ci.org/hoodiehq/hoodie-server)
Expand Down
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ function register (server, options, next) {
role: ['id:' + account.id]
})

.then(function (dbName) {
server.log(['store', 'info'], format('database %s created', dbName))
})
.then(function (dbName) {
server.log(['store', 'info'], format('database %s created', dbName))
})
})
server.plugins.account.api.accounts.on('remove', function (account) {
server.log(['account', 'info'], format('removed for %s (id: %s)', account.username, account.id))

server.plugins.store.api.destroy('user/' + account.id)

.then(function (dbName) {
server.log(['store', 'info'], format('database %s destroyed', dbName))
})
.then(function (dbName) {
server.log(['store', 'info'], format('database %s destroyed', dbName))
})
})

next(null, server, config)
Expand Down
20 changes: 10 additions & 10 deletions lib/config/admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ function getAdmins (state, callback) {

admins.set('admin', state.config.adminPassword)

.then(function () {
return admins.get('admin')
})
.then(function () {
return admins.get('admin')
})

.then(function (doc) {
state.admins = {
admin: '-pbkdf2-' + doc.derived_key + ',' + doc.salt + ',10'
}
callback()
})
.then(function (doc) {
state.admins = {
admin: '-pbkdf2-' + doc.derived_key + ',' + doc.salt + ',10'
}
callback()
})

.catch(callback)
.catch(callback)
}
28 changes: 14 additions & 14 deletions lib/config/secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ internals.randomstring = require('randomstring')
function getSecret (state, callback) {
state.db.config.get()

.then(function (config) {
if (config.secret) {
state.secret = config.secret
return callback()
}
.then(function (config) {
if (config.secret) {
state.secret = config.secret
return callback()
}

config.secret = internals.randomstring.generate({
charset: 'hex'
})
config.secret = internals.randomstring.generate({
charset: 'hex'
})

state.db.config.set(config)
state.db.config.set(config)

.then(function () {
state.secret = config.secret
callback()
.then(function () {
state.secret = config.secret
callback()
})
})
})

.catch(callback)
.catch(callback)
}
84 changes: 42 additions & 42 deletions lib/config/store/pre-auth-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,51 @@ function onStorePreAuth (request, reply) {
access: requiredAccess
})

.then(function (hasAccess) {
if (hasAccess) {
return reply.continue()
}

var sessionToken = toSessionToken(request)
if (!sessionToken) {
return reply(Boom.unauthorized())
}

return server.plugins.account.api.sessions.find(sessionToken)

// we have to nest the .then callback here because of the `return`
// statements above. If we would chain the .then below outside of this
// `.then`, then it would be executed after the two `return` statements
// above and cause `reply` to be called twice
.then(function (session) {
delete request.headers.authorization
request.headers.cookie = 'AuthSession=' + session.id

var roles = session.account.roles.concat('id:' + session.account.id, 'user')

return server.plugins.store.api.hasAccess(dbName, {
access: requiredAccess,
role: roles
})

.then(function (hasAccess) {
if (hasAccess) {
return reply.continue()
}

reply(Boom.unauthorized())
})
.then(function (hasAccess) {
if (hasAccess) {
return reply.continue()
}

var sessionToken = toSessionToken(request)
if (!sessionToken) {
return reply(Boom.unauthorized())
}

return server.plugins.account.api.sessions.find(sessionToken)

// we have to nest the .then callback here because of the `return`
// statements above. If we would chain the .then below outside of this
// `.then`, then it would be executed after the two `return` statements
// above and cause `reply` to be called twice
.then(function (session) {
delete request.headers.authorization
request.headers.cookie = 'AuthSession=' + session.id

var roles = session.account.roles.concat('id:' + session.account.id, 'user')

return server.plugins.store.api.hasAccess(dbName, {
access: requiredAccess,
role: roles
})

.then(function (hasAccess) {
if (hasAccess) {
return reply.continue()
}

reply(Boom.unauthorized())
})
})
})
})

.catch(function (error) {
if (error.status === 404) { // session not found
return reply(Boom.unauthorized())
}
.catch(function (error) {
if (error.status === 404) { // session not found
return reply(Boom.unauthorized())
}

server.log(['store', 'error'], error.message)
reply(Boom.wrap(error, 500))
})
server.log(['store', 'error'], error.message)
reply(Boom.wrap(error, 500))
})
}

function toSessionToken (request) {
Expand Down
37 changes: 23 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,43 @@
"url": "https://github.com/hoodiehq/hoodie-server/issues"
},
"homepage": "https://github.com/hoodiehq/hoodie-server#readme",
"greenkeeper": {
"ignore": [
"hapi",
"boom",
"h2o2",
"inert",
"vision"
]
},
"devDependencies": {
"coveralls": "^2.12.0",
"hapi": "^16.0.2",
"memdown": "^1.2.0",
"coveralls": "^3.0.0",
"hapi": "16.6.1",
"memdown": "^2.0.0",
"nock": "^9.0.9",
"nyc": "^10.1.2",
"nyc": "^11.7.1",
"pouchdb-adapter-memory": "^6.1.2",
"pouchdb-core": "^6.1.2",
"proxyquire": "^1.7.11",
"semantic-release": "^6.3.0",
"simple-mock": "^0.7.0",
"standard": "^9.0.1",
"tap": "^10.3.0"
"proxyquire": "^2.0.1",
"semantic-release": "^15.1.7",
"simple-mock": "^0.8.0",
"standard": "^11.0.1",
"tap": "^11.1.4"
},
"dependencies": {
"@hoodie/account-server": "^6.1.0",
"@hoodie/store-server": "^3.0.0",
"async": "^2.1.5",
"boom": "^4.2.0",
"h2o2": "^5.1.0",
"inert": "^4.0.1",
"jsonfile": "^2.3.1",
"boom": "4.3.1",
"h2o2": "6.1.0",
"inert": "4.2.1",
"jsonfile": "^4.0.0",
"lodash": "^4.14.1",
"pouchdb-admins": "^1.0.3",
"pouchdb-doc-api": "^1.0.1",
"randomstring": "^1.1.5",
"request": "^2.80.0",
"strip-url-auth": "^1.0.1",
"vision": "^4.1.0"
"vision": "4.1.1"
}
}
2 changes: 0 additions & 2 deletions test/unit/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ var serverMock = {
var adminsConfigMock = simple.stub().callbackWith(null)
var couchDbConfigMock = simple.stub().callbackWith(null)
var configPouchDbMock = simple.stub().callbackWith(null)
var appOptionsMock = simple.stub().returnWith('app options')
var secretConfigMock = simple.stub().callbackWith(null)
var storeConfigMock = simple.stub().callbackWith(null)

var getConfig = proxyquire('../../lib/config', {
'./account': accountConfigMock,
'./admins': adminsConfigMock,
'./app-options': appOptionsMock,
'./configure-pouchdb': configPouchDbMock,
'./secret': secretConfigMock,
'./store': storeConfigMock,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/config/store-pre-auth-hook-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var preAuthHook = proxyquire('../../../lib/config/store/pre-auth-hook', {
test('store pre auth hook', function (t) {
var hasAccessStub = simple.stub().returnWith({ // don’t use resolveWith to avoid async
then: function (callback) {
callback(true)
callback(true) // eslint-disable-line
return Promise.resolve()
}
})
Expand Down