Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ def test_create_prefix_users(self):
prefix_pdf_file_path = self.base_driver.find_element(
By.XPATH, '//a[text()="Download User Credentials"]'
).get_property("href")
reqHeader = {
"Cookie": f"sessionid={self.base_driver.get_cookies()[0]['value']}"
}
reqHeader = {}
for cookies in self.base_driver.get_cookies():
if cookies["name"] == "sessionid":
reqHeader = {"Cookie": f"sessionid={cookies['value']}"}
break
curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
Comment on lines +230 to 235
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider explicit handling when sessionid cookie is not found.

The fix correctly avoids assuming cookie order, but if no sessionid cookie exists, reqHeader remains empty and the request proceeds without authentication. This could lead to confusing test failures (e.g., 401/403) without indicating the actual root cause.

Also, the loop variable cookies should be cookie (singular) since each iteration yields a single cookie dict.

Proposed improvement
         reqHeader = {}
-        for cookies in self.base_driver.get_cookies():
-            if cookies["name"] == "sessionid":
-                reqHeader = {"Cookie": f"sessionid={cookies['value']}"}
+        for cookie in self.base_driver.get_cookies():
+            if cookie["name"] == "sessionid":
+                reqHeader = {"Cookie": f"sessionid={cookie['value']}"}
                 break
+        else:
+            self.fail("sessionid cookie not found in browser cookies")
         curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
reqHeader = {}
for cookies in self.base_driver.get_cookies():
if cookies["name"] == "sessionid":
reqHeader = {"Cookie": f"sessionid={cookies['value']}"}
break
curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
reqHeader = {}
for cookie in self.base_driver.get_cookies():
if cookie["name"] == "sessionid":
reqHeader = {"Cookie": f"sessionid={cookie['value']}"}
break
else:
self.fail("sessionid cookie not found in browser cookies")
curlRequest = request.Request(prefix_pdf_file_path, headers=reqHeader)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/runtests.py` around lines 230 - 235, The loop over
self.base_driver.get_cookies() should use a singular loop variable (cookie) and
must explicitly handle the case where no "sessionid" is found: iterate through
cookies (cookie) to build reqHeader when cookie["name"] == "sessionid", then
before calling request.Request(prefix_pdf_file_path, headers=reqHeader) check if
reqHeader is empty and raise a clear error or fail the test (e.g., RuntimeError
or AssertionError) that includes context (e.g., "sessionid cookie not found" and
the list of cookies) so tests don't silently proceed unauthenticated.

try:
if request.urlopen(curlRequest, context=self.ctx).getcode() != 200:
Expand Down Expand Up @@ -362,9 +364,7 @@ def test_celery(self):
"openwisp_firmware_upgrader.tasks.create_all_device_firmwares",
"openwisp_firmware_upgrader.tasks.create_device_firmware",
"openwisp_firmware_upgrader.tasks.upgrade_firmware",
"openwisp_monitoring.check.tasks.auto_create_config_check",
"openwisp_monitoring.check.tasks.auto_create_iperf3_check",
"openwisp_monitoring.check.tasks.auto_create_ping",
"openwisp_monitoring.check.tasks.auto_create_check",
"openwisp_monitoring.check.tasks.perform_check",
"openwisp_monitoring.check.tasks.run_checks",
"openwisp_monitoring.device.tasks.delete_wifi_clients_and_sessions",
Expand All @@ -385,7 +385,6 @@ def test_celery(self):
"openwisp_notifications.tasks.ns_organization_user_deleted",
"openwisp_notifications.tasks.ns_register_unregister_notification_type",
"openwisp_notifications.tasks.update_org_user_notificationsetting",
"openwisp_notifications.tasks.update_superuser_notification_settings",
"openwisp_radius.tasks.cleanup_stale_radacct",
"openwisp_radius.tasks.convert_called_station_id",
"openwisp_radius.tasks.deactivate_expired_users",
Expand Down Expand Up @@ -490,7 +489,4 @@ def test_containers_down(self):


if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(TestServices("test_topology_graph"))
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
unittest.main(verbosity=2)
Loading