Skip to content
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
2 changes: 2 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const _MAX_BACKOFF_WAIT_SECS = 32
const _BACKOFF_FACTOR = 2
const _RATE_LIMITED_RESP_CODE = 429
const _CA_BUNDLE_VERSION = '1.0'

const DUO_PINNED_CERT = `
# Source URL: https://www.amazontrust.com/repository/AmazonRootCA1.cer
Expand Down Expand Up @@ -468,5 +469,6 @@ module.exports = {
'_MAX_BACKOFF_WAIT_SECS': _MAX_BACKOFF_WAIT_SECS,
'_BACKOFF_FACTOR': _BACKOFF_FACTOR,
'_RATE_LIMITED_RESP_CODE': _RATE_LIMITED_RESP_CODE,
'_CA_BUNDLE_VERSION': _CA_BUNDLE_VERSION,
'DUO_PINNED_CERT': DUO_PINNED_CERT
}
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Client.prototype.apiCall = function (method, path, params, callback) {
var headers = {
'Date': date,
'Host': this.host,
'User-Agent': `duo_api_nodejs/${_PACKAGE_VERSION}`
'User-Agent': `duo_api_nodejs/${_PACKAGE_VERSION} ca_bundle/${constants._CA_BUNDLE_VERSION} (ca_pinning=${this.enableCAPinning ? 'enabled' : 'disabled'})`
}
var body = ''
var params_go_in_body = ['POST', 'PUT', 'PATCH'].includes(method)
Expand Down
22 changes: 22 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,26 @@ describe('CA Pinning Configuration', function () {
done()
})
})

it('User agent includes ca_bundle version and ca_pinning=enabled when pinning is on', function (done) {
var client = new duo_api.Client(IKEY, SKEY, API_HOSTNAME)
client.jsonApiCall('GET', '/foo/bar', {}, function (resp) {
var options = requestSpy.firstCall.args[0]
var ua = options.headers['User-Agent']
assert(ua.includes('ca_bundle/' + constants._CA_BUNDLE_VERSION))
assert(ua.includes('(ca_pinning=enabled)'))
done()
})
})

it('User agent includes ca_pinning=disabled when pinning is off', function (done) {
var client = new duo_api.Client(IKEY, SKEY, API_HOSTNAME, duo_api.SIGNATURE_VERSION_2, false)
client.jsonApiCall('GET', '/foo/bar', {}, function (resp) {
var options = requestSpy.firstCall.args[0]
var ua = options.headers['User-Agent']
assert(ua.includes('ca_bundle/' + constants._CA_BUNDLE_VERSION))
assert(ua.includes('(ca_pinning=disabled)'))
done()
})
})
})
Loading