Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should only satisfy caveats that get more restrictive', () => {
const interval = 1000
const condition = 'expiration'
const firstCaveat = new Caveat({
condition,
value: Date.now() + interval,
})
const secondCaveat = new Caveat({
condition,
value: Date.now() + interval / 2, // more restrictive time
})
expect(satisfier).to.have.property('satisfyPrevious')
let isValid = verifyCaveats([firstCaveat, secondCaveat], satisfier)
expect(isValid, 'Expected caveats w/ increasing restrictiveness to pass')
.to.be.true
isValid = verifyCaveats([secondCaveat, firstCaveat], satisfier)
expect(
isValid,
'Expected caveats w/ decreasingly restrictive expirations to fail'
).to.be.false
})
})
condition,
value: Date.now() + interval,
})
const secondCaveat = new Caveat({
condition,
value: Date.now() + interval / 2, // more restrictive time
})
expect(satisfier).to.have.property('satisfyPrevious')
let isValid = verifyCaveats([firstCaveat, secondCaveat], satisfier)
expect(isValid, 'Expected caveats w/ increasing restrictiveness to pass')
.to.be.true
isValid = verifyCaveats([secondCaveat, firstCaveat], satisfier)
expect(
isValid,
'Expected caveats w/ decreasingly restrictive expirations to fail'
).to.be.false
})
})
it('should not support additional caveats from other origin', () => {
const firstCaveat = new Caveat({ condition, value: '84.123.45.2' })
const secondCaveat = new Caveat({ condition, value: '74.321.5.27' })
const request = { ip: firstCaveat.value, boltwallConfig: config }
const isValid = verifyCaveats(
[firstCaveat, secondCaveat],
satisfier,
request
)
expect(isValid).to.be.false
})
})