forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_test.py
174 lines (156 loc) · 8.31 KB
/
file_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
import sys
import time
import unittest
from base_test_class import BaseTestCase
from product_test import ProductTest, WaitForPageLoad
from selenium.webdriver.common.by import By
dir_path = os.path.dirname(os.path.realpath(__file__))
class FileUploadTest(BaseTestCase):
def uncollapse_all(self, driver):
elems = driver.find_elements(By.NAME, "collapsible")
for elem in elems:
elem.click()
time.sleep(0.5)
return driver
def test_add_file_finding_level(self):
# The Name of the Finding created by test_add_product_finding => 'App Vulnerable to XSS'
# Test To Add Finding To product
# login to site, password set to fetch from environ
driver = self.login_page()
# Navigate to All Finding page
self.goto_all_findings_list(driver)
# Select and click on the particular finding to edit
driver.find_element(By.LINK_TEXT, "App Vulnerable to XSS").click()
# Click on the 'dropdownMenu1 button'
driver.find_element(By.ID, "dropdownMenu1").click()
# Click on `Edit Finding`
driver.find_element(By.LINK_TEXT, "Manage Files").click()
# select first file input field: form-0-image
# Set full image path for image file 'strange.png
image_path = os.path.join(dir_path, "finding_image.png")
driver.find_element(By.ID, "id_form-0-title").send_keys("Finding Title")
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
# Save uploaded image
with WaitForPageLoad(driver, timeout=50):
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").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="Files updated successfully"))
def test_delete_file_finding_level(self):
# login to site, password set to fetch from environ
driver = self.login_page()
# Navigate to All Finding page
self.goto_all_findings_list(driver)
# Select and click on the particular finding to edit
driver.find_element(By.LINK_TEXT, "App Vulnerable to XSS").click()
# Click on the 'dropdownMenu1 button'
driver.find_element(By.ID, "dropdownMenu1").click()
# Click on `Edit Finding`
driver.find_element(By.LINK_TEXT, "Manage Files").click()
# mark delete checkbox for first file input field: form-0-DELETE
driver.find_element(By.ID, "id_form-0-DELETE").click()
# Save selection(s) for image deletion
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").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="Files updated successfully"))
def test_add_file_test_level(self):
# View existing test from ProductTest()
# Login to the site.
driver = self.login_page()
# goto engagemnent list (and wait for javascript to load)
self.goto_all_engagements_overview(driver)
# Select a previously created engagement title
driver.find_element(By.PARTIAL_LINK_TEXT, "Ad Hoc Engagement").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Pen Test").click()
driver.find_element(By.NAME, "Manage Files").click()
# select first file input field: form-0-image
# Set full image path for image file 'strange.png
image_path = os.path.join(dir_path, "finding_image.png")
driver.find_element(By.ID, "id_form-0-title").send_keys("Test Title")
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
# Save uploaded image
with WaitForPageLoad(driver, timeout=50):
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").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="Files updated successfully"))
def test_delete_file_test_level(self):
# View existing test from ProductTest()
# Login to the site.
driver = self.login_page()
# goto engagemnent list (and wait for javascript to load)
self.goto_all_engagements_overview(driver)
# Select a previously created engagement title
driver.find_element(By.PARTIAL_LINK_TEXT, "Ad Hoc Engagement").click()
driver.find_element(By.PARTIAL_LINK_TEXT, "Pen Test").click()
driver.find_element(By.NAME, "Manage Files").click()
# mark delete checkbox for first file input field: form-0-DELETE
driver.find_element(By.ID, "id_form-0-DELETE").click()
# Save selection(s) for image deletion
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").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="Files updated successfully"))
def test_add_file_engagement_level(self):
# View existing test from ProductTest()
# Login to the site.
driver = self.login_page()
# goto engagemnent list (and wait for javascript to load)
self.goto_all_engagements_overview(driver)
# Select a previously created engagement title
driver.find_element(By.PARTIAL_LINK_TEXT, "Ad Hoc Engagement").click()
self.uncollapse_all(driver)
driver.find_element(By.NAME, "Manage Files").click()
# select first file input field: form-0-image
# Set full image path for image file 'strange.png
image_path = os.path.join(dir_path, "finding_image.png")
driver.find_element(By.ID, "id_form-0-title").send_keys("Engagement Title")
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
# Save uploaded image
with WaitForPageLoad(driver, timeout=50):
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").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="Files updated successfully"))
def test_delete_file_engagement_level(self):
# View existing test from ProductTest()
# Login to the site.
driver = self.login_page()
# goto engagemnent list (and wait for javascript to load)
self.goto_all_engagements_overview(driver)
# Select a previously created engagement title
driver.find_element(By.PARTIAL_LINK_TEXT, "Ad Hoc Engagement").click()
self.uncollapse_all(driver)
driver.find_element(By.NAME, "Manage Files").click()
# mark delete checkbox for first file input field: form-0-DELETE
driver.find_element(By.ID, "id_form-0-DELETE").click()
# Save selection(s) for image deletion
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").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="Files updated successfully"))
def add_file_tests_to_suite(suite):
# Add each test the the suite to be run
# success and failure is output by the test
suite.addTest(BaseTestCase("test_login"))
suite.addTest(ProductTest("test_create_product"))
suite.addTest(ProductTest("test_add_product_finding"))
suite.addTest(FileUploadTest("test_add_file_finding_level"))
suite.addTest(FileUploadTest("test_delete_file_finding_level"))
suite.addTest(FileUploadTest("test_add_file_test_level"))
suite.addTest(FileUploadTest("test_delete_file_test_level"))
suite.addTest(FileUploadTest("test_add_file_engagement_level"))
suite.addTest(FileUploadTest("test_delete_file_engagement_level"))
suite.addTest(ProductTest("test_delete_product"))
return suite
def suite():
suite = unittest.TestSuite()
add_file_tests_to_suite(suite)
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner(descriptions=True, failfast=True, verbosity=2)
ret = not runner.run(suite()).wasSuccessful()
BaseTestCase.tearDownDriver()
sys.exit(ret)