def test_token_scope(self):
        token = self.get_token()
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.validate_claims(token)

        self.assertIn('Invalid JWT scope', str(error.exception))
    def test_token_too_old(self):
        token = self.get_token()
        token['iat'] = token['nbf']
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.validate_claims(token)

        self.assertIn('JWT too old', str(error.exception))
    def test_not_yet_valid_token(self):
        token = self.get_token()
        token['nbf'] = token['exp']
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.validate_claims(token)

        self.assertIn('JWT not yet valid', str(error.exception))
    def test_validate_authorized_party_invalid(self):
        token = self.get_token()
        token['azp'] = 'authorized-party'
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.validate_claims(token)

        self.assertIn('Invalid JWT authorized party', str(error.exception))
    def test_validate_authorized_party_missing(self):
        token = self.get_token()
        token['aud'] += ['second-audience']
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.validate_claims(token)

        self.assertIn('Missing JWT authorized party', str(error.exception))
 def test_token_iat_valid(self):
     token = self.get_token()
     token['iat'] = token['nbf']
     auth = JSONWebTokenAuthentication()
     self.assertEqual(auth.validate_claims(token), None)