Skip to content

view_endpoint: fix error #12343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 1, 2025
2 changes: 1 addition & 1 deletion dojo/templatetags/display_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def render(self, context):
iterable = template.Variable(self.iterable).resolve(context)
num_cols = self.num_cols
context[self.varname] = zip(
*[chain(iterable, [None] * (num_cols - 1))] * num_cols, strict=True)
*[chain(iterable, [None] * (num_cols - 1))] * num_cols, strict=False)
return ""

try:
Expand Down
118 changes: 117 additions & 1 deletion tests/endpoint_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import unittest

from base_test_class import BaseTestCase
from base_test_class import BaseTestCase, on_exception_html_source_logger
from product_test import ProductTest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
Expand All @@ -28,7 +28,110 @@ def test_create_endpoint(self):
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

driver.get(self.base_url + "endpoint")
# "Click" the dropdown button to see options
driver.find_element(By.ID, "dropdownMenu1").click()
# "Click" the New Endpoint
driver.find_element(By.LINK_TEXT, "New Endpoint").click()
# Keep a good practice of clearing field before entering value
# Endpoints
driver.find_element(By.ID, "id_endpoint").clear()
driver.find_element(By.ID, "id_endpoint").send_keys("https://example.com:1")
# Select product to assign endpoint to
Select(driver.find_element(By.ID, "id_product")).select_by_visible_text("QA Test")
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

# we add 5 endpoints to be able to test the fix for https://github.com/DefectDojo/django-DefectDojo/issues/12295 later in test_view_host

driver.get(self.base_url + "endpoint")
# "Click" the dropdown button to see options
driver.find_element(By.ID, "dropdownMenu1").click()
# "Click" the New Endpoint
driver.find_element(By.LINK_TEXT, "New Endpoint").click()
# Keep a good practice of clearing field before entering value
# Endpoints
driver.find_element(By.ID, "id_endpoint").clear()
driver.find_element(By.ID, "id_endpoint").send_keys("https://example.com:1")
# Select product to assign endpoint to
Select(driver.find_element(By.ID, "id_product")).select_by_visible_text("QA Test")
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

driver.get(self.base_url + "endpoint")
# "Click" the dropdown button to see options
driver.find_element(By.ID, "dropdownMenu1").click()
# "Click" the New Endpoint
driver.find_element(By.LINK_TEXT, "New Endpoint").click()
# Keep a good practice of clearing field before entering value
# Endpoints
driver.find_element(By.ID, "id_endpoint").clear()
driver.find_element(By.ID, "id_endpoint").send_keys("https://example.com:2")
# Select product to assign endpoint to
Select(driver.find_element(By.ID, "id_product")).select_by_visible_text("QA Test")
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

driver.get(self.base_url + "endpoint")
# "Click" the dropdown button to see options
driver.find_element(By.ID, "dropdownMenu1").click()
# "Click" the New Endpoint
driver.find_element(By.LINK_TEXT, "New Endpoint").click()
# Keep a good practice of clearing field before entering value
# Endpoints
driver.find_element(By.ID, "id_endpoint").clear()
driver.find_element(By.ID, "id_endpoint").send_keys("https://example.com:3")
# Select product to assign endpoint to
Select(driver.find_element(By.ID, "id_product")).select_by_visible_text("QA Test")
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

driver.get(self.base_url + "endpoint")
# "Click" the dropdown button to see options
driver.find_element(By.ID, "dropdownMenu1").click()
# "Click" the New Endpoint
driver.find_element(By.LINK_TEXT, "New Endpoint").click()
# Keep a good practice of clearing field before entering value
# Endpoints
driver.find_element(By.ID, "id_endpoint").clear()
driver.find_element(By.ID, "id_endpoint").send_keys("https://example.com:4")
# Select product to assign endpoint to
Select(driver.find_element(By.ID, "id_product")).select_by_visible_text("QA Test")
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

driver.get(self.base_url + "endpoint")
# "Click" the dropdown button to see options
driver.find_element(By.ID, "dropdownMenu1").click()
# "Click" the New Endpoint
driver.find_element(By.LINK_TEXT, "New Endpoint").click()
# Keep a good practice of clearing field before entering value
# Endpoints
driver.find_element(By.ID, "id_endpoint").clear()
driver.find_element(By.ID, "id_endpoint").send_keys("https://example.com:5")
# Select product to assign endpoint to
Select(driver.find_element(By.ID, "id_product")).select_by_visible_text("QA Test")
# submit
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
# Query the site to determine if the finding has been added
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint added successfully"))

Expand Down Expand Up @@ -58,6 +161,18 @@ def test_edit_endpoint(self):
# Assert ot the query to dtermine status of failure
self.assertTrue(self.is_success_message_present(text="Endpoint updated successfully"))

@on_exception_html_source_logger
def test_view_host(self):
# Login to the site. Password will have to be modified
# to match an admin password in your own container
driver = self.driver
# Navigate to the host page
driver.get(self.base_url + "endpoint/host")
# Select one of the previously created endpoint to edit
driver.find_element(By.LINK_TEXT, "example.com").click()

self.assertTrue(self.is_text_present_on_page(text="Host: example.com"))

def test_delete_endpoint(self):
# Login to the site. Password will have to be modified
# to match an admin password in your own container
Expand Down Expand Up @@ -87,6 +202,7 @@ def suite():
suite.addTest(ProductTest("test_create_product"))
suite.addTest(EndpointTest("test_create_endpoint"))
suite.addTest(EndpointTest("test_edit_endpoint"))
suite.addTest(EndpointTest("test_view_host"))
suite.addTest(EndpointTest("test_delete_endpoint"))
suite.addTest(ProductTest("test_delete_product"))
return suite
Expand Down