Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.

Commit f2a0957

Browse files
committed
Add Rudimentary Stats Endpoint Protection
1 parent 053d0e3 commit f2a0957

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ before_script:
2828
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
2929
- chmod +x ./cc-test-reporter
3030
- './cc-test-reporter before-build'
31-
- psql -c 'create database nitro_travis;' -U postgres
31+
- psql -c 'create database nitrotest;' -U postgres
3232
- npm run migrate
3333
after_script:
3434
- './cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT'

config/config.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ const config = {
66
// dist: path.resolve(__dirname, '../../nitro/dist'),
77

88
development: {
9-
url: process.env.DATABASE_URL || 'postgres://nitro:secret@localhost:5432/nitro',
9+
url:
10+
process.env.DATABASE_URL ||
11+
'postgres://nitro:secret@localhost:5432/nitro',
1012
dialect: 'postgres'
1113
},
1214
production: {
13-
url: process.env.DATABASE_URL || 'postgres://nitro:secret@localhost:5432/nitro',
15+
url:
16+
process.env.DATABASE_URL ||
17+
'postgres://nitro:secret@localhost:5432/nitro',
1418
dialect: 'postgres'
1519
},
1620
test: {
17-
url: process.env.DATABASE_URL_TEST || 'postgres://nitro:secret@localhost:5432/nitrotest',
21+
url:
22+
process.env.DATABASE_URL_TEST ||
23+
'postgres://postgres:@127.0.0.1/nitrotest',
1824
dialect: 'postgres'
1925
},
2026
travis: {
21-
url: 'postgres://postgres:@127.0.0.1/nitro_travis',
27+
url: 'postgres://postgres:@127.0.0.1/nitrotest',
2228
dialect: 'postgres'
2329
},
2430

2531
jwtstrategy: process.env.JWT_Strategy || 'bearer',
2632
jwtaudience: process.env.JWT_Audience || 'https://uat.nitrotasks.com/a/',
2733
jwtissuer: process.env.JWT_Issuer || 'https://dymajo.au.auth0.com/',
28-
jwksuri: process.env.JWKS_Uri || 'https://dymajo.au.auth0.com/.well-known/jwks.json',
34+
jwksuri:
35+
process.env.JWKS_Uri || 'https://dymajo.au.auth0.com/.well-known/jwks.json',
2936
jwtsecret: process.env.JWT_Secret || 'secret'
3037
}
31-
module.exports = config
38+
module.exports = config

lib/controllers/stats.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ const ArchivedTask = require('../models/archivedtask')
99
const Meta = require('../models/meta')
1010
const auth = passport.authenticate('bearer', { session: false })
1111

12-
// TODO: need to lock this down to admin users only - verify scopes
1312
stats.get('/', auth, async (req, res) => {
13+
// TODO: need to change to verify scopes
14+
const user = await User.findOne({
15+
where: {
16+
id: req.user
17+
}
18+
})
19+
if (
20+
process.env.NODE_ENV !== 'test' &&
21+
process.env.NODE_ENV !== 'travis' &&
22+
user.loginType.indexOf('@clients') === -1
23+
) {
24+
return res.status(401).send('Incorrect User Role')
25+
}
1426
const userStats = User.findAll({
1527
attributes: [
1628
[sequelize.fn('COUNT', sequelize.col('username')), 'user_count']

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"start": "node app.js",
88
"start-production": "if npm run check-postgres; then npm run start; fi",
99
"check-postgres": "./wait-for-it.sh -h $DATABASE_HOST -p $DATABASE_PORT",
10-
"test": "nyc mocha --exit",
10+
"test": "nyc mocha --require test/mocha.env.js --exit",
1111
"sequelize": "sequelize",
1212
"migrate": "sequelize db:migrate",
1313
"migrate:test": "cross-env NODE_ENV=test sequelize db:migrate:undo:all && cross-env NODE_ENV=test sequelize db:migrate && npm run test",
@@ -26,11 +26,7 @@
2626
"node": "8.4.x"
2727
},
2828
"nyc": {
29-
"reporter": [
30-
"lcov",
31-
"text",
32-
"html"
33-
]
29+
"reporter": ["lcov", "text", "html"]
3430
},
3531
"homepage": "http://nitrotasks.com",
3632
"dependencies": {

test/mocha.env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.env.NODE_ENV = 'test'

0 commit comments

Comments
 (0)