Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
tests: add test for secret storage disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 19, 2019
1 parent 8851fa6 commit 09baec8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion index.js
Expand Up @@ -202,7 +202,6 @@ function getSecret (req, sessionKey, cookie) {
var key = cookie ? cookie.key : 'csrfSecret'

if (!bag) {
/* istanbul ignore next: should never actually run */
throw new Error('misconfigured csrf')
}

Expand Down
17 changes: 17 additions & 0 deletions test/test.js
Expand Up @@ -364,6 +364,23 @@ describe('csurf', function () {
.get('/')
.expect(200, 'true', done)
})

it('should error when secret storage missing', function (done) {
var app = connect()

app.use(session({ keys: ['a', 'b'] }))
app.use(csurf())
app.use(function (req, res) {
req.session = null
res.setHeader('x-run', 'true')
res.end(req.csrfToken())
})

request(app)
.get('/')
.expect('x-run', 'true')
.expect(500, /misconfigured csrf/, done)
})
})

describe('when using session storage', function () {
Expand Down

0 comments on commit 09baec8

Please sign in to comment.