|
10 | 10 | from scbzapv2.zap_context import ZapConfigureContext |
11 | 11 | from scbzapv2.zap_spider import ZapConfigureSpider |
12 | 12 | from scbzapv2.zap_scanner import ZapConfigureActiveScanner |
| 13 | +from scbzapv2.zap_extended import ZapExtended |
13 | 14 |
|
14 | 15 | def is_responsive(url): |
15 | 16 | try: |
@@ -91,103 +92,31 @@ def test_bodgeit_scan(get_bodgeit_url, get_juiceshop_url, get_zap_instance: ZAPv |
91 | 92 |
|
92 | 93 | zap = get_zap_instance |
93 | 94 | test_config_yaml = "./tests/mocks/scan-full-bodgeit-docker/" |
94 | | - |
95 | | - config = ZapConfiguration(test_config_yaml) |
96 | | - target = "http://bodgeit:8080/" |
97 | | - |
98 | | - logging.info('Configuring ZAP Context') |
99 | | - # Starting to configure the ZAP Instance based on the given Configuration |
100 | | - if config.has_configurations() and config.has_context_configurations: |
101 | | - local_zap_context = ZapConfigureContext(zap, config) |
102 | | - |
103 | | - configured_context = zap.context.context("scb-bodgeit-context") |
104 | | - assert configured_context["name"] == "scb-bodgeit-context" |
105 | | - |
106 | | - logging.info('Starting ZAP Spider with target %s', target) |
107 | | - # if a ZAP Configuration is defined start to configure the running ZAP instance (`zap`) |
108 | | - if config and config.has_spider_configurations: |
109 | | - # Starting to configure the ZAP Spider Instance based on the given Configuration |
110 | | - zap_spider = ZapConfigureSpider(zap, config) |
111 | | - spider_id = zap_spider.start_spider_by_url(target) |
112 | | - |
113 | | - assert int(zap.spider.status(spider_id)) > 0 |
114 | | - |
115 | | - zap_spider.wait_until_http_spider_finished(spider_id) |
116 | | - result_urls = len(zap.core.urls()) |
| 95 | + test_target = "http://bodgeit:8080/" |
117 | 96 |
|
118 | | - assert int(result_urls) > 10 |
119 | | - |
120 | | - logging.info('Starting ZAP Scanner with target %s', target) |
121 | | - # if a ZAP Configuration is defined start to configure the running ZAP instance (`zap`) |
122 | | - if config and config.has_scan_configurations: |
123 | | - # Starting to configure the ZAP Instance based on the given Configuration |
124 | | - zap_scan = ZapConfigureActiveScanner(zap, config) |
125 | | - # Search for the corresponding context based on the given targetUrl which should correspond to defined the spider url |
126 | | - scan_id = zap_scan.start_scan_by_url(target) |
127 | | - |
128 | | - assert int(zap.ascan.status(scan_id)) > 0 |
129 | | - |
130 | | - zap_scan.wait_until_finished(scan_id) |
131 | | - result_urls = len(zap.core.urls()) |
132 | | - |
133 | | - assert int(result_urls) > 10 |
134 | | - |
135 | | - alerts = zap_scan.get_alerts(target, [], []) |
| 97 | + zap_extended = ZapExtended(zap=zap, config_dir=test_config_yaml) |
| 98 | + zap_extended.scb_scan(target=test_target) |
| 99 | + |
| 100 | + alerts = zap_extended.get_zap_scan().get_alerts(test_target, [], []) |
136 | 101 |
|
137 | | - logging.info('Found ZAP Alerts: %s', str(len(alerts))) |
| 102 | + logging.info('Found ZAP Alerts: %s', str(len(alerts))) |
138 | 103 |
|
139 | | - assert int(len(alerts)) >= 5 |
| 104 | + assert int(len(alerts)) >= 5 |
140 | 105 |
|
141 | 106 | def test_juiceshop_scan(get_bodgeit_url, get_juiceshop_url, get_zap_instance: ZAPv2): |
142 | 107 |
|
143 | 108 | zap = get_zap_instance |
144 | 109 | test_config_yaml = "./tests/mocks/scan-full-juiceshop-docker/" |
145 | | - |
146 | | - config = ZapConfiguration(test_config_yaml) |
147 | | - target = "http://juiceshop:3000/" |
148 | | - |
149 | | - logging.info('Configuring ZAP Context') |
150 | | - # Starting to configure the ZAP Instance based on the given Configuration |
151 | | - if config.has_configurations() and config.has_context_configurations: |
152 | | - local_zap_context = ZapConfigureContext(zap, config) |
153 | | - |
154 | | - configured_context = zap.context.context("scb-juiceshop-context") |
155 | | - assert configured_context["name"] == "scb-juiceshop-context" |
156 | | - |
157 | | - logging.info('Starting ZAP Spider with target %s', target) |
158 | | - # if a ZAP Configuration is defined start to configure the running ZAP instance (`zap`) |
159 | | - if config and config.has_spider_configurations: |
160 | | - # Starting to configure the ZAP Spider Instance based on the given Configuration |
161 | | - zap_spider = ZapConfigureSpider(zap, config) |
162 | | - spider_id = zap_spider.start_spider_by_url(target) |
163 | | - |
164 | | - assert zap.ajaxSpider.status == 'running' |
165 | | - |
166 | | - zap_spider.wait_until_ajax_spider_finished() |
167 | | - result_urls = len(zap.core.urls()) |
| 110 | + test_target = "http://juiceshop:3000/" |
168 | 111 |
|
169 | | - assert int(result_urls) > 10 |
170 | | - |
171 | | - logging.info('Starting ZAP Scanner with target %s', target) |
172 | | - # if a ZAP Configuration is defined start to configure the running ZAP instance (`zap`) |
173 | | - if config and config.has_scan_configurations: |
174 | | - # Starting to configure the ZAP Instance based on the given Configuration |
175 | | - zap_scan = ZapConfigureActiveScanner(zap, config) |
176 | | - # Search for the corresponding context based on the given targetUrl which should correspond to defined the spider url |
177 | | - scan_id = zap_scan.start_scan_by_url(target) |
178 | | - |
179 | | - assert int(zap.ascan.status(scan_id)) > 0 |
180 | | - |
181 | | - zap_scan.wait_until_finished(scan_id) |
182 | | - result_urls = len(zap.core.urls()) |
183 | | - |
184 | | - assert int(result_urls) > 10 |
185 | | - |
186 | | - alerts = zap_scan.get_alerts(target, [], []) |
| 112 | + zap_extended = ZapExtended(zap=zap, config_dir=test_config_yaml) |
| 113 | + zap_extended.scb_scan(target=test_target) |
| 114 | + |
| 115 | + alerts = zap_extended.get_zap_scan().get_alerts(test_target, [], []) |
187 | 116 |
|
188 | | - logging.info('Found ZAP Alerts: %s', str(len(alerts))) |
| 117 | + logging.info('Found ZAP Alerts: %s', str(len(alerts))) |
189 | 118 |
|
190 | | - assert int(len(alerts)) >= 3 |
| 119 | + assert int(len(alerts)) >= 3 |
191 | 120 |
|
192 | 121 | # # https://medium.com/opsops/deepdive-into-pytest-parametrization-cb21665c05b9 |
193 | 122 | # @pytest.mark.parametrize("config_folder", ["./tests/mocks/scan-full-bodgeit/", "./tests/mocks/scan-full-juiceshop/"]) |
|
0 commit comments