1
1
import sys
2
2
import unittest
3
3
4
- from base_test_class import BaseTestCase
4
+ from base_test_class import BaseTestCase , on_exception_html_source_logger
5
5
from product_test import ProductTest
6
6
from selenium .webdriver .common .by import By
7
7
from selenium .webdriver .support .ui import Select
@@ -28,7 +28,110 @@ def test_create_endpoint(self):
28
28
# submit
29
29
driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
30
30
# Query the site to determine if the finding has been added
31
+ # Assert ot the query to dtermine status of failure
32
+ self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
33
+
34
+ driver .get (self .base_url + "endpoint" )
35
+ # "Click" the dropdown button to see options
36
+ driver .find_element (By .ID , "dropdownMenu1" ).click ()
37
+ # "Click" the New Endpoint
38
+ driver .find_element (By .LINK_TEXT , "New Endpoint" ).click ()
39
+ # Keep a good practice of clearing field before entering value
40
+ # Endpoints
41
+ driver .find_element (By .ID , "id_endpoint" ).clear ()
42
+ driver .find_element (By .ID , "id_endpoint" ).send_keys ("https://example.com:1" )
43
+ # Select product to assign endpoint to
44
+ Select (driver .find_element (By .ID , "id_product" )).select_by_visible_text ("QA Test" )
45
+ # submit
46
+ driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
47
+ # Query the site to determine if the finding has been added
48
+ # Assert ot the query to dtermine status of failure
49
+ self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
50
+
51
+ # 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
52
+
53
+ driver .get (self .base_url + "endpoint" )
54
+ # "Click" the dropdown button to see options
55
+ driver .find_element (By .ID , "dropdownMenu1" ).click ()
56
+ # "Click" the New Endpoint
57
+ driver .find_element (By .LINK_TEXT , "New Endpoint" ).click ()
58
+ # Keep a good practice of clearing field before entering value
59
+ # Endpoints
60
+ driver .find_element (By .ID , "id_endpoint" ).clear ()
61
+ driver .find_element (By .ID , "id_endpoint" ).send_keys ("https://example.com:1" )
62
+ # Select product to assign endpoint to
63
+ Select (driver .find_element (By .ID , "id_product" )).select_by_visible_text ("QA Test" )
64
+ # submit
65
+ driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
66
+ # Query the site to determine if the finding has been added
67
+ # Assert ot the query to dtermine status of failure
68
+ self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
69
+
70
+ driver .get (self .base_url + "endpoint" )
71
+ # "Click" the dropdown button to see options
72
+ driver .find_element (By .ID , "dropdownMenu1" ).click ()
73
+ # "Click" the New Endpoint
74
+ driver .find_element (By .LINK_TEXT , "New Endpoint" ).click ()
75
+ # Keep a good practice of clearing field before entering value
76
+ # Endpoints
77
+ driver .find_element (By .ID , "id_endpoint" ).clear ()
78
+ driver .find_element (By .ID , "id_endpoint" ).send_keys ("https://example.com:2" )
79
+ # Select product to assign endpoint to
80
+ Select (driver .find_element (By .ID , "id_product" )).select_by_visible_text ("QA Test" )
81
+ # submit
82
+ driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
83
+ # Query the site to determine if the finding has been added
84
+ # Assert ot the query to dtermine status of failure
85
+ self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
31
86
87
+ driver .get (self .base_url + "endpoint" )
88
+ # "Click" the dropdown button to see options
89
+ driver .find_element (By .ID , "dropdownMenu1" ).click ()
90
+ # "Click" the New Endpoint
91
+ driver .find_element (By .LINK_TEXT , "New Endpoint" ).click ()
92
+ # Keep a good practice of clearing field before entering value
93
+ # Endpoints
94
+ driver .find_element (By .ID , "id_endpoint" ).clear ()
95
+ driver .find_element (By .ID , "id_endpoint" ).send_keys ("https://example.com:3" )
96
+ # Select product to assign endpoint to
97
+ Select (driver .find_element (By .ID , "id_product" )).select_by_visible_text ("QA Test" )
98
+ # submit
99
+ driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
100
+ # Query the site to determine if the finding has been added
101
+ # Assert ot the query to dtermine status of failure
102
+ self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
103
+
104
+ driver .get (self .base_url + "endpoint" )
105
+ # "Click" the dropdown button to see options
106
+ driver .find_element (By .ID , "dropdownMenu1" ).click ()
107
+ # "Click" the New Endpoint
108
+ driver .find_element (By .LINK_TEXT , "New Endpoint" ).click ()
109
+ # Keep a good practice of clearing field before entering value
110
+ # Endpoints
111
+ driver .find_element (By .ID , "id_endpoint" ).clear ()
112
+ driver .find_element (By .ID , "id_endpoint" ).send_keys ("https://example.com:4" )
113
+ # Select product to assign endpoint to
114
+ Select (driver .find_element (By .ID , "id_product" )).select_by_visible_text ("QA Test" )
115
+ # submit
116
+ driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
117
+ # Query the site to determine if the finding has been added
118
+ # Assert ot the query to dtermine status of failure
119
+ self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
120
+
121
+ driver .get (self .base_url + "endpoint" )
122
+ # "Click" the dropdown button to see options
123
+ driver .find_element (By .ID , "dropdownMenu1" ).click ()
124
+ # "Click" the New Endpoint
125
+ driver .find_element (By .LINK_TEXT , "New Endpoint" ).click ()
126
+ # Keep a good practice of clearing field before entering value
127
+ # Endpoints
128
+ driver .find_element (By .ID , "id_endpoint" ).clear ()
129
+ driver .find_element (By .ID , "id_endpoint" ).send_keys ("https://example.com:5" )
130
+ # Select product to assign endpoint to
131
+ Select (driver .find_element (By .ID , "id_product" )).select_by_visible_text ("QA Test" )
132
+ # submit
133
+ driver .find_element (By .CSS_SELECTOR , "input.btn.btn-primary" ).click ()
134
+ # Query the site to determine if the finding has been added
32
135
# Assert ot the query to dtermine status of failure
33
136
self .assertTrue (self .is_success_message_present (text = "Endpoint added successfully" ))
34
137
@@ -58,6 +161,18 @@ def test_edit_endpoint(self):
58
161
# Assert ot the query to dtermine status of failure
59
162
self .assertTrue (self .is_success_message_present (text = "Endpoint updated successfully" ))
60
163
164
+ @on_exception_html_source_logger
165
+ def test_view_host (self ):
166
+ # Login to the site. Password will have to be modified
167
+ # to match an admin password in your own container
168
+ driver = self .driver
169
+ # Navigate to the host page
170
+ driver .get (self .base_url + "endpoint/host" )
171
+ # Select one of the previously created endpoint to edit
172
+ driver .find_element (By .LINK_TEXT , "example.com" ).click ()
173
+
174
+ self .assertTrue (self .is_text_present_on_page (text = "Host: example.com" ))
175
+
61
176
def test_delete_endpoint (self ):
62
177
# Login to the site. Password will have to be modified
63
178
# to match an admin password in your own container
@@ -87,6 +202,7 @@ def suite():
87
202
suite .addTest (ProductTest ("test_create_product" ))
88
203
suite .addTest (EndpointTest ("test_create_endpoint" ))
89
204
suite .addTest (EndpointTest ("test_edit_endpoint" ))
205
+ suite .addTest (EndpointTest ("test_view_host" ))
90
206
suite .addTest (EndpointTest ("test_delete_endpoint" ))
91
207
suite .addTest (ProductTest ("test_delete_product" ))
92
208
return suite
0 commit comments