Files
bch-js/test/e2e/rate-limits/basic-auth-rate-limits.js
T

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-11-11 14:11:13 -08:00
/*
Mocha test that verifies that the bch-api server is enforcing its
access rules for Basic Authentication.
To Run Test:
- Update the restURL for bch-api you want to test against.
- Update the PRO_PASS value with a current PRO_PASSES string used by bch-api.
*/
2021-01-02 15:41:12 -08:00
const assert = require('chai').assert
2020-11-11 14:11:13 -08:00
2021-01-02 15:41:12 -08:00
const PRO_PASS = 'testpassword'
2020-11-11 14:11:13 -08:00
2021-01-02 15:41:12 -08:00
const BCHJS = require('../../../src/bch-js')
2020-11-11 14:11:13 -08:00
const bchjs = new BCHJS({
2020-12-05 19:28:33 -08:00
// restURL: `https://bchn.fullstack.cash/v4/`,
2021-01-02 15:41:12 -08:00
restURL: 'https://abc.fullstack.cash/v4/',
2020-12-05 19:28:33 -08:00
// restURL: `http://localhost:3000/v4/`,
2020-11-11 14:56:53 -08:00
authPass: PRO_PASS
2020-11-11 14:11:13 -08:00
})
2021-01-02 15:41:12 -08:00
describe('#Basic Authentication rate limits', () => {
it('should allow more than 20 RPM to full node', async () => {
2020-11-11 14:11:13 -08:00
for (let i = 0; i < 22; i++) {
const result = await bchjs.Control.getNetworkInfo()
if (i === 5) {
// console.log(`validating 5th call: ${i}`)
2021-01-02 15:41:12 -08:00
assert.property(result, 'version', 'more than 3 calls allowed')
2020-11-11 14:11:13 -08:00
}
if (i === 15) {
// console.log(`validating 5th call: ${i}`)
2021-01-02 15:41:12 -08:00
assert.property(result, 'version', 'more than 10 calls allowed')
2020-11-11 14:11:13 -08:00
}
}
}).timeout(45000)
2021-01-02 15:41:12 -08:00
it('should allow more than 20 RPM to an indexer', async () => {
const addr = 'bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf'
2020-11-11 14:11:13 -08:00
for (let i = 0; i < 22; i++) {
const result = await bchjs.Blockbook.balance(addr)
if (i === 5) {
// console.log(`validating 5th call: ${i}`)
2021-01-02 15:41:12 -08:00
assert.property(result, 'balance', 'more than 3 calls allowed')
2020-11-11 14:11:13 -08:00
}
if (i === 15) {
// console.log(`validating 5th call: ${i}`)
2021-01-02 15:41:12 -08:00
assert.property(result, 'balance', 'more than 10 calls allowed')
2020-11-11 14:11:13 -08:00
}
}
}).timeout(45000)
})