feat(Basic Authentication): Adding back in for controlling access

This commit is contained in:
Chris Troutner
2020-11-11 14:56:24 -08:00
parent b8589a54aa
commit 28f0a1de56
3 changed files with 37 additions and 35 deletions
+4 -2
View File
@@ -33,7 +33,7 @@ util.inspect.defaultOptions = { depth: 1 }
// let _this
// Set default rate limit value for testing
const PRO_PASSES = process.env.PRO_PASS ? process.env.PRO_PASS : 'BITBOX'
const PRO_PASSES = process.env.PRO_PASSES ? process.env.PRO_PASSES : 'testpassword'
// Convert the pro-tier password string into an array split by ':'.
const PRO_PASS = PRO_PASSES.split(':')
@@ -82,6 +82,7 @@ class AuthMW {
// Success
req.locals.proLimit = true
console.log(`User ${req.ip} authenticated using Basic Auth`)
break
}
}
@@ -96,7 +97,8 @@ class AuthMW {
// Middleware called by the route.
mw () {
return passport.authenticate(['anonymous', 'basic'], {
console.log('Initializing passport')
return passport.authenticate(['basic', 'anonymous'], {
session: false
})
}
+3 -2
View File
@@ -154,8 +154,9 @@ class RateLimits {
// For internal calls, increase rate limits to as fast as possible.
if (
key.toString().indexOf('172.17.') > -1 ||
key.toString().indexOf('::ffff:127.0.0.1') > -1
key.toString().indexOf('172.17.') > -1
// Comment out the line below when running bch-js e2e rate limit tests.
// key.toString().indexOf('::ffff:127.0.0.1') > -1
) {
pointsToConsume = 1
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
+30 -31
View File
@@ -1,7 +1,6 @@
/*
This integration tests should be run against a live bch-api REST server. It
tests to ensure the rate-limits are working as expected. Adjust the values
in the tests below to match the rate limit setting in your own installation.
These tests have been deprecated. To test bch-api rate limits, run the e2e
tests in the bch-js repository.
*/
'use strict'
@@ -134,32 +133,32 @@ describe('#JWT rate limits', () => {
// }
// })
it('should unlock pro-tier for a valid JWT token', async () => {
try {
// Actual rate limit is 60 per minute X 4 nodes = 240 rpm.
const options = {
method: 'GET',
url: `${SERVER}control/`,
headers: {
Authorization: `Token ${TEST_JWT}`
}
}
const promises = []
for (let i = 0; i < 60; i++) {
const promise = axios(options)
promises.push(promise)
}
await Promise.all(promises)
// assert.equal(true, false, "Unexpected result!")
assert.equal(true, true, 'Not throwing an error is a pass!')
} catch (err) {
console.log(`err.response: ${util.inspect(err.response)}`)
assert.equal(true, false, 'Unexpected result!')
}
// Override default timeout for this test.
}).timeout(20000)
// it('should unlock pro-tier for a valid JWT token', async () => {
// try {
// // Actual rate limit is 60 per minute X 4 nodes = 240 rpm.
// const options = {
// method: 'GET',
// url: `${SERVER}control/`,
// headers: {
// Authorization: `Token ${TEST_JWT}`
// }
// }
//
// const promises = []
// for (let i = 0; i < 60; i++) {
// const promise = axios(options)
// promises.push(promise)
// }
//
// await Promise.all(promises)
//
// // assert.equal(true, false, "Unexpected result!")
// assert.equal(true, true, 'Not throwing an error is a pass!')
// } catch (err) {
// console.log(`err.response: ${util.inspect(err.response)}`)
//
// assert.equal(true, false, 'Unexpected result!')
// }
// // Override default timeout for this test.
// }).timeout(20000)
})