Esempio n. 1
0
 def test_raw_jwt_to_proto_to_verified_jwt(self):
     nbf = datetime.datetime.fromtimestamp(1234567.89,
                                           datetime.timezone.utc)
     iat = datetime.datetime.fromtimestamp(2345678.9, datetime.timezone.utc)
     exp = datetime.datetime.fromtimestamp(3456789, datetime.timezone.utc)
     raw = jwt.new_raw_jwt(issuer='issuer',
                           subject='subject',
                           audiences=['audience1', 'audience2'],
                           jwt_id='jwt_id',
                           not_before=nbf,
                           issued_at=iat,
                           expiration=exp,
                           custom_claims={
                               'null': None,
                               'string': 'aString',
                               'number': 123.456,
                               'integer': 123,
                               'bool': True,
                               'list':
                               [None, True, 'foo', 42, {
                                   'pi': 3.14
                               }],
                               'obj': {
                                   'list': [1, 3.14],
                                   'null': None,
                                   'bool': False
                               }
                           })
     proto = _primitives.raw_jwt_to_proto(raw)
     verified = _primitives.proto_to_verified_jwt(proto)
     self.assertEqual(verified.issuer(), 'issuer')
     self.assertEqual(verified.subject(), 'subject')
     self.assertEqual(verified.audiences(), ['audience1', 'audience2'])
     self.assertEqual(verified.jwt_id(), 'jwt_id')
     self.assertEqual(verified.not_before(), nbf)
     self.assertEqual(verified.issued_at(), iat)
     self.assertEqual(verified.expiration(), exp)
     self.assertEqual(
         verified.custom_claim_names(),
         {'null', 'string', 'number', 'integer', 'bool', 'list', 'obj'})
     self.assertIsNone(verified.custom_claim('null'))
     self.assertEqual(verified.custom_claim('string'), 'aString')
     self.assertEqual(verified.custom_claim('number'), 123.456)
     self.assertEqual(verified.custom_claim('integer'), 123)
     self.assertEqual(verified.custom_claim('bool'), True)
     self.assertEqual(verified.custom_claim('list'),
                      [None, True, 'foo', 42, {
                          'pi': 3.14
                      }])
     self.assertEqual(verified.custom_claim('obj'), {
         'list': [1, 3.14],
         'null': None,
         'bool': False
     })
Esempio n. 2
0
 def test_empty_raw_jwt_to_proto_to_verified_jwt(self):
   raw = jwt.new_raw_jwt()
   proto = _primitives.raw_jwt_to_proto(raw)
   verified = _primitives.proto_to_verified_jwt(proto)
   self.assertFalse(verified.has_issuer())
   self.assertFalse(verified.has_subject())
   self.assertFalse(verified.has_audiences())
   self.assertFalse(verified.has_jwt_id())
   self.assertFalse(verified.has_not_before())
   self.assertFalse(verified.has_issued_at())
   self.assertFalse(verified.has_expiration())
   self.assertEmpty(verified.custom_claim_names())