Example #1
0
def test_claim_is_expired():
    token = paseto.create(key=private_key,
                          purpose='public',
                          claims={'my claims': [1, 2, 3]},
                          exp_seconds=-300)
    with pytest.raises(paseto.PasetoTokenExpired):
        paseto.parse(
            key=public_key,
            purpose='public',
            token=token,
        )
Example #2
0
def test_claim_is_expired():
    token = paseto.create(key=private_key,
                          purpose='public',
                          claims=my_claims,
                          exp_seconds=-300)
    with pytest.raises(BaseException):
        paseto.parse(
            key=public_key,
            purpose='public',
            token=token,
        )
Example #3
0
def decode_token():
    token = _paseto_required()
    parsed = paseto.parse(
        key=Config()._secret_key,
        purpose='local',
        token=token.encode(),
    )
    return parsed
Example #4
0
def decode_token_public():
    token = _paseto_required()
    parsed = paseto.parse(
        key=Config()._public_key,
        purpose='public',
        token=token.encode(),
    )
    return parsed
Example #5
0
def test_required_claims():
    token = paseto.create(key=private_key,
                          purpose='public',
                          claims={'my claims': [1, 2, 3]},
                          exp_seconds=-300)
    parsed = paseto.parse(key=public_key,
                          purpose='public',
                          token=token,
                          validate=False,
                          required_claims=['exp', 'my claims'])
    assert 'exp' in parsed['message']
    assert 'my claims' in parsed['message']

    with pytest.raises(paseto.PasetoValidationError):
        paseto.parse(key=public_key,
                     purpose='public',
                     token=token,
                     validate=False,
                     required_claims=['exp', 'missing'])
Example #6
0
def test_skip_validation_on_expired():
    token = paseto.create(key=private_key,
                          purpose='public',
                          claims={'my claims': [1, 2, 3]},
                          exp_seconds=-300)
    parsed = paseto.parse(key=public_key,
                          purpose='public',
                          token=token,
                          validate=False)
    assert parsed
Example #7
0
def test_required_claims():
    token = paseto.create(key=private_key,
                          purpose='public',
                          claims=my_claims,
                          exp_seconds=-300)
    parsed = paseto.parse(key=public_key,
                          purpose='public',
                          token=token,
                          validate=False,
                          required_claims=['exp', claims_name])
    assert 'exp' in parsed['message']
    assert 'my claims' in parsed['message']

    with pytest.raises(BaseException):
        paseto.parse(key=public_key,
                     purpose='public',
                     token=token,
                     validate=False,
                     required_claims=['exp', 'missing'])
Example #8
0
def test_exp_claim():
    token = paseto.create(key=private_key,
                          purpose='public',
                          claims={'my claims': [1, 2, 3]},
                          exp_seconds=300)
    parsed = paseto.parse(
        key=public_key,
        purpose='public',
        token=token,
    )
    assert parsed
Example #9
0
def test_create(options):
    create_params = {
        'key': options['key'],
        'purpose': options['purpose'],
        'claims': options['claims'],
        'footer': options['footer'],
    }

    token = paseto.create(**create_params)
    assert token.startswith(options['expected_header'].encode())
    parse_key = options.get('public_key', options['key'])
    parsed = paseto.parse(
        key=parse_key,
        purpose=options['purpose'],
        token=token,
    )
    assert parsed['message'] == options['claims']
    assert parsed['footer'] == options['footer']
                      purpose='local',
                      claims=data,
                      footer={'check': True},
                      exp_seconds=ttl)

print(f'''
  Token Data 
  
  {json.dumps(data, indent = 4)}
  
  PASETO 
  
  {token.decode("utf-8")}
''')

parsed_token = paseto.parse(key=key, purpose='local', token=token)

print(f'''
  Parsed Token data
  
  {json.dumps(parsed_token['message'], indent=2)}
  
  Token Footer
  
  {json.dumps(parsed_token['footer'], indent=2)}
  ''')

pk, sk = pysodium.crypto_sign_keypair()

token = paseto.create(key=sk,
                      purpose='public',