How to use the lsat-js.Caveat function in lsat-js

To help you get started, we’ve selected a few lsat-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tierion / boltwall / tests / configs.spec.ts View on Github external
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)
github Tierion / boltwall / tests / configs.spec.ts View on Github external
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'
github Tierion / boltwall / tests / configs.spec.ts View on Github external
it('should validate expiration caveat', () => {
      const validCaveat = new Caveat({
        condition: 'expiration',
        value: Date.now() + 1000,
      })

      expect(validCaveat.condition).to.equal(satisfier.condition)
      let isValid = satisfier.satisfyFinal(validCaveat, {} as Request)
      expect(isValid, 'Valid caveat should have been satisfied').to.be.true

      const expired = new Caveat({
        condition: 'expiration',
        value: Date.now() - 100,
      })
      expect(expired.condition).to.equal(satisfier.condition)
      isValid = satisfier.satisfyFinal(expired, {} as Request)
      expect(isValid, 'expired caveat should be invalid').to.be.false
    })
github Tierion / boltwall / tests / configs.spec.ts View on Github external
it('should validate expiration caveat', () => {
      const validCaveat = new Caveat({
        condition: 'expiration',
        value: Date.now() + 1000,
      })

      expect(validCaveat.condition).to.equal(satisfier.condition)
      let isValid = satisfier.satisfyFinal(validCaveat, {} as Request)
      expect(isValid, 'Valid caveat should have been satisfied').to.be.true

      const expired = new Caveat({
        condition: 'expiration',
        value: Date.now() - 100,
      })
      expect(expired.condition).to.equal(satisfier.condition)
      isValid = satisfier.satisfyFinal(expired, {} as Request)
      expect(isValid, 'expired caveat should be invalid').to.be.false
    })
github Tierion / boltwall / tests / configs.spec.ts View on Github external
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
    })
  })
github Tierion / boltwall / tests / configs.spec.ts View on Github external
it('should create a caveat that restricts access by ip and be able to satisfy it', () => {
      const origin = '180.1.23.45'
      const expected = new Caveat({ condition, value: origin })

      const requests = [
        {
          name: 'request from proxy',
          req: { headers: { 'x-forwarded-for': origin } },
        },
        {
          name: 'request from proxy with array of ips',
          req: { headers: { 'x-forwarded-for': [origin, '127.0.0.1'] } },
        },
        {
          name: 'request with ip (express)',
          req: { ip: origin },
        },
        {
          name: 'request without express',
github Tierion / boltwall / tests / helpers.spec.ts View on Github external
const secondCaveatGetter = (): string => {
        const caveat = new Caveat({
          condition: 'middleName',
          value: 'danger',
        })
        return caveat.encode()
      }
      const firstCaveat = singleCaveatGetter(request)
github Tierion / boltwall / src / configs / origin.ts View on Github external
const getOriginCaveat: CaveatGetter = (req: Request) => {
  const origin = getOriginFromRequest(req)
  const caveat = new Caveat({ condition: 'ip', value: origin })
  return caveat.encode()
}

lsat-js

Utility library for working with LSAT auth tokens in javascript

MIT
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis

Similar packages