Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const middlename = req.body?.middlename
if (caveat.value === middlename) return true
return false
},
},
}
// get an express App with our custom options
const middlename = 'danger'
app = getApp(options)
let resp = await request
.agent(app)
.get(protectedRoute)
.send({ middlename })
.expect(402)
const lsat = Lsat.fromChallenge(resp.header['www-authenticate'])
// make a valid lsat with secret
lsat.setPreimage(invoiceResponse.secret)
// make a request with the wrong body parameter
// which should fail authorization (because macaroon won't validate)
resp = await request
.agent(app)
.get(protectedRoute)
.set('Authorization', lsat.toToken())
.send({ middlename: 'scott' })
.expect(401)
// make a request with a valid request body
resp = await request
.agent(app)
it('should return 402 if request has LSAT with a macaroon but no secret', async () => {
const resp: request.Response = await request
.agent(app)
.get(protectedRoute)
.set('Authorization', lsat.toToken())
.expect(402)
const lsatFromChallenge = Lsat.fromChallenge(resp.header['www-authenticate'])
expect(lsatFromChallenge.baseMacaroon).to.include(
macaroon,
'Expected response to include the macaroon sent in Authorization header'
)
})