Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Deprecate includeSubdomains (lowercase d)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed Mar 10, 2019
1 parent d5793b3 commit 1b1e104
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
var deprecate = require('depd')('hsts')

var DEFAULT_MAX_AGE = 180 * 24 * 60 * 60

module.exports = function hsts (options) {
options = options || {}

if ('includeSubdomains' in options) {
deprecate('The "includeSubdomains" parameter is deprecated. Use "includeSubDomains" (with a capital D) instead.')
}

var maxAge = options.maxAge != null ? options.maxAge : DEFAULT_MAX_AGE
var includeSubDomains = (options.includeSubDomains !== false) && (options.includeSubdomains !== false)
var setIf = options.hasOwnProperty('setIf') ? options.setIf : alwaysTrue
Expand Down
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"beforeEach",
"it"
]
},
"dependencies": {
"depd": "2.0.0"
}
}
14 changes: 12 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,23 @@ describe('hsts', function () {
.expect('Strict-Transport-Security', 'max-age=15552000')
})

it('can disable subdomains with the includeSubdomains option', function () {
return request(app({
it('can disable subdomains with the includeSubdomains option, but a deprecation warning is shown', function () {
// We can remove this test in hsts@3.
const deprecationPromise = new Promise(resolve => {
process.on('deprecation', (deprecationError) => {
assert(deprecationError.message.indexOf('The "includeSubdomains" parameter is deprecated. Use "includeSubDomains" (with a capital D) instead.') !== -1)
resolve()
})
})

const supertestPromise = request(app({
includeSubdomains: false
}))
.get('/')
.expect(200)
.expect('Strict-Transport-Security', 'max-age=15552000')

return Promise.all([deprecationPromise, supertestPromise])
})

it('can enable preloading', function () {
Expand Down

0 comments on commit 1b1e104

Please sign in to comment.