Exemple #1
0
    def test_get_scopes(self):
        # Test fetching scopes of a valid grant
        oauth_grant = db_oauth_grant.create(
            client_id=self.oauth_client["client_id"],
            code="Test Code",
            redirect_uri="https://example.com",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes="review user",
        )
        self.assertIn("review", db_oauth_grant.get_scopes(oauth_grant["id"]))

        # Test fetching scopes of a grant that does not exist
        db_oauth_grant.delete(client_id=self.oauth_client["client_id"], code=oauth_grant["code"])
        with self.assertRaises(db_exceptions.NoDataFoundException):
            db_oauth_grant.get_scopes(oauth_grant["id"])

        # Test fetching scopes of grant with no scopes
        oauth_grant = db_oauth_grant.create(
            client_id=self.oauth_client["client_id"],
            code="Test Code",
            redirect_uri="https://example.com",
            expires=datetime.now() + timedelta(seconds=200),
            user_id=self.user.id,
            scopes=None,
        )
        self.assertEqual([], db_oauth_grant.get_scopes(oauth_grant["id"]))
Exemple #2
0
 def test_delete(self):
     oauth_grant = db_oauth_grant.create(
         client_id=self.oauth_client["client_id"],
         code="Test Code",
         redirect_uri="https://example.com",
         expires=datetime.now() + timedelta(seconds=200),
         user_id=self.user.id,
         scopes=None,
     )
     self.assertEqual(len(db_oauth_grant.list_grants(client_id=self.oauth_client["client_id"])), 1)
     db_oauth_grant.delete(client_id=self.oauth_client["client_id"], code=oauth_grant["code"])
     self.assertEqual(len(db_oauth_grant.list_grants(client_id=self.oauth_client["client_id"])), 0)
Exemple #3
0
 def discard_grant(client_id, code):
     db_oauth_grant.delete(client_id=client_id, code=code)