jason810496 commented on code in PR #76963:
URL: https://github.com/apache/airflow/pull/76963#discussion_r4736794558


##########
airflow-core/src/airflow/models/revoked_token.py:
##########
@@ -54,11 +54,11 @@ def revoke(cls, jti: str, exp: datetime, *, session: 
Session = NEW_SESSION) -> N
         session.merge(cls(jti=jti, exp=exp))
 
     @classmethod
-    @provide_session
-    def is_revoked(cls, jti: str, *, session: Session = NEW_SESSION) -> bool:
-        """Check if a token JTI has been revoked."""
-        cls._maybe_cleanup_expired(session)
-        return bool(session.scalar(select(exists().where(cls.jti == jti))))
+    async def is_revoked_async(cls, jti: str) -> bool:
+        """Check token revocation using the async database engine."""

Review Comment:
   Nit: the name already says async. Could the docstring describe the result 
instead?
   
   ```suggestion
           """Return whether the token JTI has been revoked."""
   ```



##########
airflow-core/tests/unit/models/test_revoked_token.py:
##########
@@ -45,59 +52,55 @@ def test_revoke_inserts_row(self):
         assert arg.jti == "test-jti-123"
         assert arg.exp == exp
 
-    def test_is_revoked_returns_true(self):
-        """Test that a revoked JTI is detected."""
-        mock_session = MagicMock()
-        mock_session.scalar.return_value = True
-        result = RevokedToken.is_revoked("known-jti", session=mock_session)
-        assert result is True
 
-    def test_is_revoked_returns_false(self):
-        """Test that an unknown JTI returns False."""
-        mock_session = MagicMock()
-        mock_session.scalar.return_value = False
-        result = RevokedToken.is_revoked("unknown-jti", session=mock_session)
-        assert result is False
+FROZEN_NOW = datetime(2026, 11, 1, tzinfo=UTC)
+JWT_EXPIRATION_TIME = 3600
+CLEANUP_INTERVAL = JWT_EXPIRATION_TIME * 2  # mirrors _maybe_cleanup_expired
+LAST_CLEANUP_TIME = 4000.0
+
+
[email protected]_test
[email protected]
+class TestRevokedTokenAsync:
+    @pytest.fixture(autouse=True)
+    def seed_revoked_tokens(self, session, time_machine):
+        time_machine.move_to(FROZEN_NOW, tick=False)
+        clear_db_revoked_tokens()
+        session.add_all(
+            [
+                RevokedToken(jti="revoked-jti", exp=FROZEN_NOW + 
timedelta(days=1)),
+                RevokedToken(jti="expired-jti", exp=FROZEN_NOW - 
timedelta(days=1)),
+            ]
+        )
+        session.commit()
+        yield
+        clear_db_revoked_tokens()
+
+    @pytest.mark.parametrize(("jti", "expected"), [("revoked-jti", True), 
("unknown-jti", False)])
+    async def test_is_revoked_async(self, jti, expected):
+        with assert_queries_count(0, include_async_engine=False):
+            assert await RevokedToken.is_revoked_async(jti) is expected

Review Comment:
   Yes, a real DB is fine here, and most model tests already do that. It runs 
the actual query, which a mock session cannot check. The committed rows are 
needed anyway, since the async session reads on its own connection.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to