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 <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1217140?usp=email )
Change subject: tests: Fix label keys for WD item Q60
......................................................................
tests: Fix label keys for WD item Q60
It is controversial whether Q60 may have a 'mul' key or not.
Bug: T412188
Change-Id: Idec9fc9e6b6f6bacfaade960f81f923a80834d58
---
M tests/wikibase_tests.py
1 file changed, 17 insertions(+), 9 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 583123f..4097eb4 100755
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -228,6 +228,9 @@
}
}
+ keys = 'en', 'mul' # either en or mul may missing
+ labels = 'New York', 'New York City' # label could change
+
@classmethod
def setUpClass(cls) -> None:
"""Set up test class."""
@@ -237,7 +240,7 @@
def setUp(self) -> None:
"""Set up test."""
super().setUp()
- self.nyc = pywikibot.Page(pywikibot.page.Link('New York City',
+ self.nyc = pywikibot.Page(pywikibot.page.Link(self.labels[1],
self.site))
def test_item_normal(self) -> None:
@@ -283,9 +286,11 @@
self.assertNotHasAttr(item, '_content')
item.get()
self.assertHasAttr(item, '_content')
- self.assertIn('mul', item.labels)
+ key = next((k for k in self.keys if k in item.labels), None)
+ self.assertIsNotNone(key,
+ f'Expected one of {self.keys} in item.labels')
# label could change
- self.assertIn(item.labels['mul'], ['New York', 'New York City'])
+ self.assertIn(item.labels[key], self.labels)
self.assertEqual(item.title(), 'Q60')
def test_reuse_item_set_id(self) -> None:
@@ -295,12 +300,13 @@
work but modifying item.id does not currently work, and this
test highlights that it breaks silently.
"""
- # label could change
- label = ['New York', 'New York City']
wikidata = self.get_repo()
item = ItemPage(wikidata, 'Q60')
item.get()
- self.assertIn(item.labels['mul'], label)
+ key = next((k for k in self.keys if k in item.labels), None)
+ self.assertIsNotNone(key,
+ f'Expected one of {self.keys} in item.labels')
+ old_label = item.labels[key]
# When the id attribute is modified, the ItemPage goes into
# an inconsistent state.
@@ -312,7 +318,8 @@
# it doesn't help to clear this piece of saved state.
del item._content
# The labels are not updated; assertion showing undesirable behaviour:
- self.assertIn(item.labels['mul'], label)
+ self.assertEqual(item.labels[key], old_label)
+ self.assertIn(item.labels[key], self.labels)
def test_empty_item(self) -> None:
"""Test empty wikibase item.
@@ -452,10 +459,11 @@
def test_fromPage_lazy(self) -> None:
"""Test item from page with lazy_load."""
- page = pywikibot.Page(pywikibot.page.Link('New York City', self.site))
+ title = self.labels[1]
+ page = pywikibot.Page(pywikibot.page.Link(title, self.site))
item = ItemPage.fromPage(page, lazy_load=True)
self.assertEqual(item._defined_by(),
- {'sites': 'enwiki', 'titles': 'New York City'})
+ {'sites': 'enwiki', 'titles': title})
self.assertEqual(item._link._title, '-1')
self.assertNotHasAttr(item, 'id')
self.assertNotHasAttr(item, '_content')
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1217140?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: Idec9fc9e6b6f6bacfaade960f81f923a80834d58
Gerrit-Change-Number: 1217140
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot