bito-code-review[bot] commented on code in PR #43074:
URL: https://github.com/apache/superset/pull/43074#discussion_r3761355554
##########
tests/unit_tests/utils/encrypt_test.py:
##########
@@ -75,6 +75,30 @@ def test_default_engine_is_aes_cbc() -> None:
assert isinstance(field.engine, AesEngine)
+def test_trailing_asterisk_survives_round_trip() -> None:
+ """A secret ending in a literal '*' must not be truncated on decrypt.
+
+ Reported in apache/superset#32664: a Redshift/Postgres password ending in
+ '*' connects fine (Test Connection succeeds) but authentication fails
+ after the Database row is saved and reloaded. The default AES-CBC field
+ uses sqlalchemy_utils' "naive" padding scheme, which pads short values
+ with literal '*' bytes and unpads by unconditionally stripping every
+ trailing '*' on decrypt (see NaivePadding.unpad). That strips a real
+ trailing '*' in the secret right along with the padding, silently
+ corrupting any password/token that happens to end in that character.
+ """
+ field = SQLAlchemyUtilsAdapter().create(SECRET, String(1024))
+
+ encrypted = field.process_bind_param("mypassword*", DIALECT)
+ decrypted = field.process_result_value(encrypted, DIALECT)
+
+ assert decrypted == "mypassword*", (
+ f"expected the trailing '*' to survive the round trip, got
{decrypted!r} "
+ "-- the default naive padding scheme strips real trailing '*' bytes "
+ "along with its own padding"
+ )
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Test will always fail without fix</b></div>
<div id="fix">
This test will always fail: the current `SQLAlchemyUtilsAdapter` uses
`sqlalchemy_utils`'s default AES-CBC engine with `NaivePadding`, which
unconditionally strips trailing '*' on decrypt (see `NaivePadding.unpad`). The
test documents the corruption bug but provides no fix path. A test asserting
correct behavior that always fails in the shipped code is not a regression test
— it's a failing invariant. To serve its purpose, either the fix must land
alongside this test, or the test should be marked
`@pytest.mark.xfail(reason='awaiting fix for apache/superset#32664')` to
indicate it's a known-failing pin.
</div>
</div>
<small><i>Code Review Run #85c853</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]