jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1217829?usp=email )

Change subject: tests: Disable file-based check in test_eval_security on Python 
> 3.9
......................................................................

tests: Disable file-based check in test_eval_security on Python > 3.9

Patching self.stat in setUp() does not work as expected on Python > 3.9.
The test file appears to exist even when it does not. Therefore, the
file existence check inside
login_tests.TestPasswordFile.test_eval_security is skipped for
Python > 3.9.

Bug: T410753
Change-Id: If033e507a89fbe40ed6df1df503f74b8e9668856
---
M tests/login_tests.py
1 file changed, 6 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/tests/login_tests.py b/tests/login_tests.py
index fa0ee65..963bff4 100755
--- a/tests/login_tests.py
+++ b/tests/login_tests.py
@@ -191,16 +191,17 @@

     def test_eval_security(self) -> None:
         """Test security that password file does not use eval() function."""
-        # Test file will will be created for Python 3.10-3.13
-        # due to self.stat patch in setUp().
-        no_file = (3, 9) < PYTHON_VERSION < (3, 14)
+        # File-based checks are limited to Python 3.9 only.
+        # On newer versions, self.stat patching in setUp() fails,
+        # making the file appear to exist.
+        use_file = PYTHON_VERSION[:2] == (3, 9)

         builtins.exploit_value = False
         exploit_code = (
             "__import__('builtins').__dict__"
             ".__setitem__('exploit_value', True)"
         )
-        if not no_file:
+        if use_file:
             exploit_filename = f'pwb_rce_{uuid.uuid4().hex[:8]}.txt'
             exploit_file = Path(exploit_filename)
             exploit_code = (
@@ -218,7 +219,7 @@
         with self.subTest(test='Test value was modified'):
             self.assertFalse(exploit_value)  # noqa: F821

-        if not no_file:
+        if use_file:
             with self.subTest(test='Test file exists'):
                 self.assertFalse(exploit_file.exists())


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1217829?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If033e507a89fbe40ed6df1df503f74b8e9668856
Gerrit-Change-Number: 1217829
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to