This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
constants.py
executable file
·896 lines (813 loc) · 38.2 KB
/
constants.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
#!/usr/bin/env python3
"""
Constants for use during tests
"""
# built-ins
import copy
import secrets
from pathlib import Path
from typing import Dict, List, Union
from xml.etree import ( # nosec (Used only when TYPE_CHECKING)
ElementTree as InsecureElementTree,
)
# third party
from defusedxml import ElementTree
import yaml
## Sample Results API environmental information
VALID_RESULTS_API: Dict[str, Union[str, bool, Dict[str, str]]] = {}
VALID_RESULTS_API["base_url"] = "https://analysiscenter.veracode.com/api/"
VALID_RESULTS_API["version"] = {
"detailedreport.do": "5.0",
"detailedreportpdf.do": "4.0",
"getaccountcustomfieldlist.do": "5.0",
"getappbuilds.do": "4.0",
"getcallstacks.do": "5.0",
"summaryreport.do": "4.0",
"summaryreportpdf.do": "4.0",
"thirdpartyreportpdf.do": "4.0",
}
VALID_RESULTS_API["app_id"] = "1337"
VALID_RESULTS_API["api_key_id"] = secrets.token_hex(16)
VALID_RESULTS_API["api_key_secret"] = secrets.token_hex(64) # nosec
VALID_RESULTS_API["ignore_compliance_status"] = False
VALID_RESULTS_API_DIFFERENT_APP_ID = copy.deepcopy(VALID_RESULTS_API)
VALID_RESULTS_API_DIFFERENT_APP_ID["app_id"] = "31337"
INVALID_RESULTS_API_MISSING_VERSION_KEY = copy.deepcopy(VALID_RESULTS_API)
del INVALID_RESULTS_API_MISSING_VERSION_KEY["version"]
INVALID_RESULTS_API_INCORRECT_APP_ID = copy.deepcopy(VALID_RESULTS_API)
INVALID_RESULTS_API_INCORRECT_APP_ID["app_id"] = 1337
INVALID_RESULTS_API_INCORRECT_VERSION_VALUES = copy.deepcopy(VALID_RESULTS_API)
for value in VALID_RESULTS_API["version"]:
INVALID_RESULTS_API_INCORRECT_VERSION_VALUES["version"][value] = float(
VALID_RESULTS_API["version"][value]
)
INVALID_RESULTS_API_MISSING_DOMAIN = copy.deepcopy(VALID_RESULTS_API)
INVALID_RESULTS_API_MISSING_DOMAIN["base_url"] = "https:///api/"
INVALID_RESULTS_API_INCORRECT_COMPLIANCE_STATUS = copy.deepcopy(VALID_RESULTS_API)
INVALID_RESULTS_API_INCORRECT_COMPLIANCE_STATUS["ignore_compliance_status"] = "True"
INVALID_RESULTS_API_INVALID_PORT = copy.deepcopy(VALID_RESULTS_API)
INVALID_RESULTS_API_INVALID_PORT[
"base_url"
] = "https://analysiscenter.veracode.com:65536/api/"
VALID_RESULTS_API_WITH_PORT_IN_URL = copy.deepcopy(VALID_RESULTS_API)
VALID_RESULTS_API_WITH_PORT_IN_URL[
"base_url"
] = "https://analysiscenter.veracode.com:443/api/"
# Valid Results API getappbuilds.do information, but no
# policy_compliance_status
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS: Dict[
str, Union[str, bytes, InsecureElementTree.Element]
] = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<applicationbuilds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/2.0/applicationbuilds"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/2.0/applicationbuilds
https://analysiscenter.veracode.com/resource/2.0/applicationbuilds.xsd"
account_id="00000000001">
<application app_name="app name" app_id="1337" industry_vertical="Manufacturing" assurance_level="Very High"
business_criticality="Very High" origin="Not Specified" modified_date="2019-08-13T14:00:10-04:00"
cots="false" business_unit="Not Specified" tags="">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
<customfield name="Custom 6" value=""/>
<customfield name="Custom 7" value=""/>
<customfield name="Custom 8" value=""/>
<customfield name="Custom 9" value=""/>
<customfield name="Custom 10" value=""/>
</application>
</applicationbuilds>
<!-- Parameters: report_changed_since=08/25/2019 only_latest=true include_in_progress=false -->""" # pylint: disable=line-too-long
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS["bytes"] = bytes(
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS["string"], "utf-8"
)
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS[
"Element"
] = ElementTree.fromstring(
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS["bytes"]
)
# Valid Results API getappbuilds.do information, with a failing
# policy_compliance_status
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_FAILING_POLICY_COMPLIANCE_STATUS = {}
# Variant of
# VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS to
# add a failing policy_compliance_status
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_FAILING_POLICY_COMPLIANCE_STATUS[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<applicationbuilds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/2.0/applicationbuilds"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/2.0/applicationbuilds
https://analysiscenter.veracode.com/resource/2.0/applicationbuilds.xsd"
account_id="00000000001">
<application app_name="app name" app_id="1337" industry_vertical="Manufacturing" assurance_level="Very High"
business_criticality="Very High" origin="Not Specified" modified_date="2019-08-13T14:00:10-04:00"
cots="false" business_unit="Not Specified" tags="">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
<customfield name="Custom 6" value=""/>
<customfield name="Custom 7" value=""/>
<customfield name="Custom 8" value=""/>
<customfield name="Custom 9" value=""/>
<customfield name="Custom 10" value=""/>
<build version="2019-10 Testing" build_id="1234321" submitter="Jon Zeolla" platform="Not Specified" lifecycle_stage="Deployed (In production and actively developed)" results_ready="true" policy_name="Veracode Recommended Medium" policy_version="1" policy_compliance_status="Did Not Pass" rules_status="Did Not Pass" grace_period_expired="false" scan_overdue="false">
<analysis_unit analysis_type="Static" published_date="2019-10-13T16:20:30-04:00" published_date_sec="1570998030" status="Results Ready"/>
</build>
</application>
</applicationbuilds>
<!-- Parameters: report_changed_since=08/25/2019 only_latest=true include_in_progress=false -->""" # pylint: disable=line-too-long
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_FAILING_POLICY_COMPLIANCE_STATUS[
"bytes"
] = bytes(
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_FAILING_POLICY_COMPLIANCE_STATUS[
"string"
],
"utf-8",
)
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_FAILING_POLICY_COMPLIANCE_STATUS[
"Element"
] = ElementTree.fromstring(
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_FAILING_POLICY_COMPLIANCE_STATUS[
"bytes"
]
)
# Valid Results API getappbuilds.do information, with a passing
# policy_compliance_status
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_PASSING_POLICY_COMPLIANCE_STATUS = {}
# Variant of
# VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_NO_BUILDS to
# add a passing policy_compliance_status
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_PASSING_POLICY_COMPLIANCE_STATUS[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<applicationbuilds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/2.0/applicationbuilds"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/2.0/applicationbuilds
https://analysiscenter.veracode.com/resource/2.0/applicationbuilds.xsd"
account_id="00000000001">
<application app_name="app name" app_id="1337" industry_vertical="Manufacturing" assurance_level="Very High"
business_criticality="Very High" origin="Not Specified" modified_date="2019-08-13T14:00:10-04:00"
cots="false" business_unit="Not Specified" tags="">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
<customfield name="Custom 6" value=""/>
<customfield name="Custom 7" value=""/>
<customfield name="Custom 8" value=""/>
<customfield name="Custom 9" value=""/>
<customfield name="Custom 10" value=""/>
<build version="2019-10 Testing" build_id="1234321" submitter="Jon Zeolla" platform="Not Specified" lifecycle_stage="Deployed (In production and actively developed)" results_ready="true" policy_name="Veracode Recommended Medium" policy_version="1" policy_compliance_status="Pass" rules_status="Pass" grace_period_expired="false" scan_overdue="false">
<analysis_unit analysis_type="Static" published_date="2019-10-13T16:20:30-04:00" published_date_sec="1570998030" status="Results Ready"/>
</build>
</application>
</applicationbuilds>
<!-- Parameters: report_changed_since=08/25/2019 only_latest=true include_in_progress=false -->""" # pylint: disable=line-too-long
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_PASSING_POLICY_COMPLIANCE_STATUS[
"bytes"
] = bytes(
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_PASSING_POLICY_COMPLIANCE_STATUS[
"string"
],
"utf-8",
)
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_PASSING_POLICY_COMPLIANCE_STATUS[
"Element"
] = ElementTree.fromstring(
VALID_RESULTS_API_GETAPPBUILDS_RESPONSE_XML_PASSING_POLICY_COMPLIANCE_STATUS[
"bytes"
]
)
## Sample Upload API environmental information
VALID_UPLOAD_API: Dict[str, Union[str, Dict[str, str], Path, bool]] = {}
VALID_UPLOAD_API["base_url"] = "https://analysiscenter.veracode.com/api/"
VALID_UPLOAD_API["version"] = {
"beginprescan.do": "5.0",
"beginscan.do": "5.0",
"createapp.do": "5.0",
"createbuild.do": "5.0",
"deleteapp.do": "5.0",
"deletebuild.do": "5.0",
"getappinfo.do": "5.0",
"getapplist.do": "5.0",
"getbuildinfo.do": "5.0",
"getbuildlist.do": "5.0",
"getfilelist.do": "5.0",
"getpolicylist.do": "5.0",
"getprescanresults.do": "5.0",
"getvendorlist.do": "5.0",
"removefile.do": "5.0",
"updateapp.do": "5.0",
"updatebuild.do": "5.0",
"uploadfile.do": "5.0",
"uploadlargefile.do": "5.0",
}
VALID_UPLOAD_API["app_id"] = "1337"
VALID_UPLOAD_API["build_dir"] = Path("/usr/local/bin/").absolute()
VALID_UPLOAD_API["build_id"] = "v1.2.3"
VALID_UPLOAD_API["sandbox_id"] = "321"
VALID_UPLOAD_API["scan_all_nonfatal_top_level_modules"] = True
VALID_UPLOAD_API["auto_scan"] = True
VALID_UPLOAD_API["api_key_id"] = secrets.token_hex(16)
VALID_UPLOAD_API["api_key_secret"] = secrets.token_hex(64) # nosec
INVALID_UPLOAD_API_MISSING_BUILD_DIR = copy.deepcopy(VALID_UPLOAD_API)
del INVALID_UPLOAD_API_MISSING_BUILD_DIR["build_dir"]
INVALID_UPLOAD_API_BUILD_DIR = copy.deepcopy(VALID_UPLOAD_API)
INVALID_UPLOAD_API_BUILD_DIR["build_dir"] = "/usr/local/bin/"
INVALID_UPLOAD_API_MISSING_DOMAIN = copy.deepcopy(VALID_UPLOAD_API)
INVALID_UPLOAD_API_MISSING_DOMAIN["base_url"] = "https:///api/"
INVALID_UPLOAD_API_INCORRECT_VERSION_VALUES = copy.deepcopy(VALID_UPLOAD_API)
for value in VALID_UPLOAD_API["version"]:
INVALID_UPLOAD_API_INCORRECT_VERSION_VALUES["version"][value] = float(
VALID_UPLOAD_API["version"][value]
)
INVALID_UPLOAD_API_BUILD_ID = copy.deepcopy(VALID_UPLOAD_API)
INVALID_UPLOAD_API_BUILD_ID["build_id"] = "invalid(build_id)"
INVALID_UPLOAD_API_SCAN_ALL_NONFATAL_TOP_LEVEL_MODULES = copy.deepcopy(VALID_UPLOAD_API)
INVALID_UPLOAD_API_SCAN_ALL_NONFATAL_TOP_LEVEL_MODULES[
"scan_all_nonfatal_top_level_modules"
] = "True"
INVALID_UPLOAD_API_AUTO_SCAN = copy.deepcopy(VALID_UPLOAD_API)
INVALID_UPLOAD_API_AUTO_SCAN["auto_scan"] = "False"
# Valid Upload API uploadlargefile.do information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/lzZ1eON0Bkr8iYjNVD9tqw
VALID_UPLOAD_API_UPLOADLARGEFILE_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_UPLOAD_API_UPLOADLARGEFILE_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<filelist xmlns="https://analysiscenter.veracode.com/schema/2.0/filelist"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
account_id="00000000001" app_id="1337" build_id="3131313131" filelist_version="1.1"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/2.0/filelist
https://analysiscenter.veracode.com/resource/2.0/filelist.xsd">
<file file_id="-9223372036854775808" file_name="valid_file.pdb" file_status="Uploaded"/>
</filelist>"""
VALID_UPLOAD_API_UPLOADLARGEFILE_RESPONSE_XML["bytes"] = bytes(
VALID_UPLOAD_API_UPLOADLARGEFILE_RESPONSE_XML["string"], "utf-8"
)
VALID_UPLOAD_API_UPLOADLARGEFILE_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_UPLOAD_API_UPLOADLARGEFILE_RESPONSE_XML["bytes"]
)
# Valid Upload API beginprescan.do information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/PX5ReM5acqjM~IOVEg2~rA
VALID_UPLOAD_API_BEGINPRESCAN_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_UPLOAD_API_BEGINPRESCAN_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<buildinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/4.0/buildinfo"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/4.0/buildinfo
https://analysiscenter.veracode.com/resource/4.0/buildinfo.xsd"
buildinfo_version="1.4" account_id="00000000001" app_id="1337" build_id="3131313131">
<build version="v1" build_id="3131313131" submitter="JoeUser" platform="Not Specified"
lifecycle_stage="Not Specified" results_ready="false" policy_name="Veracode Transitional Very High"
policy_version="1" policy_compliance_status="Not Assessed" rules_status="Not Assessed"
grace_period_expired="false" scan_overdue="false" legacy_scan_engine="false">
<analysis_unit analysis_type="Static" status="Pre-Scan Submitted"/>
</build>
</buildinfo>"""
VALID_UPLOAD_API_BEGINPRESCAN_RESPONSE_XML["bytes"] = bytes(
VALID_UPLOAD_API_BEGINPRESCAN_RESPONSE_XML["string"], "utf-8"
)
VALID_UPLOAD_API_BEGINPRESCAN_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_UPLOAD_API_BEGINPRESCAN_RESPONSE_XML["bytes"]
)
# Valid Upload API createbuild.do information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/vhuQ5lMdxRNQWUK1br1mDg
VALID_UPLOAD_API_CREATEBUILD_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_UPLOAD_API_CREATEBUILD_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<buildinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/4.0/buildinfo"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/4.0/buildinfo
https://analysiscenter.veracode.com/resource/4.0/buildinfo.xsd" buildinfo_version="1.4"
account_id="00000000001" app_id="1337" sandbox_id="1122" build_id="3131313131"><build version="2019-10 Testing"
build_id="3131313131" submitter="JoeUser" platform="Not Specified" lifecycle_stage="Not Specified"
results_ready="false" policy_name="Veracode Transitional Very High" policy_version="1" policy_compliance_status="Not Assessed"
rules_status="Not Assessed" grace_period_expired="false" scan_overdue="false" legacy_scan_engine="false">
<analysis_unit analysis_type="Static" status="Incomplete"/>
</build>
</buildinfo>"""
VALID_UPLOAD_API_CREATEBUILD_RESPONSE_XML["bytes"] = bytes(
VALID_UPLOAD_API_CREATEBUILD_RESPONSE_XML["string"], "utf-8"
)
VALID_UPLOAD_API_CREATEBUILD_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_UPLOAD_API_CREATEBUILD_RESPONSE_XML["bytes"]
)
# Valid Upload API getappinfo.do information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/kb2SM9net26_L91VploQGw
VALID_UPLOAD_API_GETAPPINFO_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_UPLOAD_API_GETAPPINFO_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<appinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/2.0/appinfo"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/2.0/appinfo
https://analysiscenter.veracode.com/resource/2.0/appinfo.xsd" appinfo_version="1.1"
account_id="00000000001">
<application app_id="1337" app_name="app name" description="app description" business_criticality="Very High"
policy="Veracode Transitional Very High" policy_updated_date="2019-08-13T14:02:08-04:00"
teams="Demo Team" origin="Not Specified" industry_vertical="Other" app_type="Other" deployment_method="Not Specified"
is_web_application="false" archer_app_name="archer app name" modified_date="2019-08-15T11:27:47-04:00"
cots="false" vast="false" business_unit="Not Specified" tags="">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
<customfield name="Custom 6" value=""/>
<customfield name="Custom 7" value=""/>
<customfield name="Custom 8" value=""/>
<customfield name="Custom 9" value=""/>
<customfield name="Custom 10" value="foo"/>
</application>
</appinfo>"""
VALID_UPLOAD_API_GETAPPINFO_RESPONSE_XML["bytes"] = bytes(
VALID_UPLOAD_API_GETAPPINFO_RESPONSE_XML["string"], "utf-8"
)
VALID_UPLOAD_API_GETAPPINFO_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_UPLOAD_API_GETAPPINFO_RESPONSE_XML["bytes"]
)
# Valid Upload API getappinfo.do information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/rERUQewXKGx2D_zaoi6wGw
VALID_UPLOAD_API_DELETEBUILD_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_UPLOAD_API_DELETEBUILD_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<buildlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/2.0/buildlist"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/2.0/buildlist
https://analysiscenter.veracode.com/resource/2.0/buildlist.xsd" buildlist_version="1.3"
account_id="12345" app_id="54321" app_name="Application Name">
</buildlist>"""
VALID_UPLOAD_API_DELETEBUILD_RESPONSE_XML["bytes"] = bytes(
VALID_UPLOAD_API_DELETEBUILD_RESPONSE_XML["string"], "utf-8"
)
VALID_UPLOAD_API_DELETEBUILD_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_UPLOAD_API_DELETEBUILD_RESPONSE_XML["bytes"]
)
## Sample Sandbox API environmental information
VALID_SANDBOX_API: Dict[str, Union[str, Dict[str, str], Path, bool]] = {}
VALID_SANDBOX_API["base_url"] = "https://analysiscenter.veracode.com/api/"
VALID_SANDBOX_API["version"] = {
"createsandbox.do": "5.0",
"getsandboxlist.do": "5.0",
"promotesandbox.do": "5.0",
"updatesandbox.do": "5.0",
"deletesandbox.do": "5.0",
}
VALID_SANDBOX_API["app_id"] = "1337"
VALID_SANDBOX_API["build_id"] = "v1.2.3"
VALID_SANDBOX_API["sandbox_id"] = "321"
VALID_SANDBOX_API["sandbox_name"] = "fb/jonzeolla/add-sandbox_name"
VALID_SANDBOX_API["api_key_id"] = secrets.token_hex(16)
VALID_SANDBOX_API["api_key_secret"] = secrets.token_hex(64) # nosec
INVALID_SANDBOX_API_BUILD_ID = copy.deepcopy(VALID_SANDBOX_API)
INVALID_SANDBOX_API_BUILD_ID["build_id"] = "invalid(build_id)"
INVALID_SANDBOX_API_SANDBOX_NAME = copy.deepcopy(VALID_SANDBOX_API)
INVALID_SANDBOX_API_SANDBOX_NAME["sandbox_name"] = r"invalid\sandbox_name"
INVALID_SANDBOX_API_INCORRECT_VERSION_VALUES = copy.deepcopy(VALID_SANDBOX_API)
for value in VALID_SANDBOX_API["version"]:
INVALID_SANDBOX_API_INCORRECT_VERSION_VALUES["version"][value] = float(
VALID_SANDBOX_API["version"][value]
)
# Valid Sandbox API information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/twPT73YBy_iQvrsGEZamhQ
VALID_SANDBOX_GETSANDBOXLIST_API_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_SANDBOX_GETSANDBOXLIST_API_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<sandboxlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/4.0/sandboxlist"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/4.0/sandboxlist
https://analysiscenter.veracode.com/resource/4.0/sandboxlist.xsd"
sandboxlist_version="1.0" account_id="12345" app_id="31337">
<sandbox sandbox_id="111111111" sandbox_name="Project Security" owner="[email protected]"
last_modified="2019-09-17T14:08:35-04:00">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
</sandbox>
<sandbox sandbox_id="22222222" sandbox_name="Project Refactor" owner="[email protected]"
last_modified="2019-09-17T14:04:13-04:00">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
</sandbox>
</sandboxlist>"""
VALID_SANDBOX_GETSANDBOXLIST_API_RESPONSE_XML["bytes"] = bytes(
VALID_SANDBOX_GETSANDBOXLIST_API_RESPONSE_XML["string"], "utf-8"
)
VALID_SANDBOX_GETSANDBOXLIST_API_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_SANDBOX_GETSANDBOXLIST_API_RESPONSE_XML["bytes"]
)
# Valid Sandbox API information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/jp8rPey8I5WsuWz7bY2SZg
VALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
VALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<sandboxinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/4.0/sandboxinfo"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/4.0/sandboxinfo
https://analysiscenter.veracode.com/resource/4.0/sandboxinfo.xsd" sandboxinfo_version="1.2"
account_id="12345" app_id="31337">
<sandbox sandbox_id="1111111" sandbox_name="Project Security" sandbox_status="sandbox" owner="[email protected]"
modified_date="2019-09-17T14:08:35-04:00" created_date="2019-09-17T14:08:35-04:00">
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
</sandbox>
</sandboxinfo>"""
VALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML["bytes"] = bytes(
VALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML["string"], "utf-8"
)
VALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML["Element"] = ElementTree.fromstring(
VALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML["bytes"]
)
# Invalid Sandbox API information
# https://help.veracode.com/reader/LMv_dtSHyb7iIxAQznC~9w/jp8rPey8I5WsuWz7bY2SZg
INVALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML_NO_SANDBOX = {}
# Unfortunately, this varies slightly from the Veracode-provided example
# because (1) the xml library cannot parse the XML using a XSD file, and (2)
# the placeholders Veracode provided in its documentation result in invalid XML
# regardless.
INVALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML_NO_SANDBOX[
"string"
] = """<?xml version="1.0" encoding="UTF-8"?>
<sandboxinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://analysiscenter.veracode.com/schema/4.0/sandboxinfo"
xsi:schemaLocation="https://analysiscenter.veracode.com/schema/4.0/sandboxinfo
https://analysiscenter.veracode.com/resource/4.0/sandboxinfo.xsd" sandboxinfo_version="1.2"
account_id="12345" app_id="31337">
</sandboxinfo>"""
INVALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML_NO_SANDBOX["bytes"] = bytes(
INVALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML_NO_SANDBOX["string"], "utf-8"
)
INVALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML_NO_SANDBOX[
"Element"
] = ElementTree.fromstring(
INVALID_SANDBOX_CREATESANDBOX_API_RESPONSE_XML_NO_SANDBOX["bytes"]
)
INVALID_SANDBOX_API_INCORRECT_DOMAIN = copy.deepcopy(VALID_RESULTS_API)
INVALID_SANDBOX_API_INCORRECT_DOMAIN["base_url"] = "https:///api/"
## Example file info
VALID_FILE: Dict[str, Union[str, List[str], bytes, Path]] = {}
VALID_FILE["name"] = "valid_file.pdb"
VALID_FILE["names"] = [
"valid_file.exe",
"valid_file.pdb",
"valid_file.dll",
"valid_file.jar",
"valid_file.zip",
"valid_file.tar",
"valid_file.tgz",
"valid_file.war",
"valid_file.ear",
"valid_file.jar",
"valid_file.apk",
"valid_file.ipa",
"valid_file.tar.gz",
"this.is.a.valid.file.dll",
"this.is..also..valid.jar",
]
VALID_FILE["bytes"] = b"Seiso was here!\n"
VALID_FILE["Path"] = Path("/path/" + str(VALID_FILE["name"]))
INVALID_FILE: Dict[str, Union[str, List[str], bytes, Path]] = {}
INVALID_FILE["name"] = "invalid_file.tar.gz.bar"
INVALID_FILE["names"] = [
"invalid_file.thingy",
"invalid_file",
"invalid_file.tar.gz.bar",
"invalid_file.dll.gz",
"invalid_file.exe.docx",
]
INVALID_FILE["bytes"] = b"Seiso was here!\n"
INVALID_FILE["Path"] = Path("/path/" + str(INVALID_FILE["name"]))
## Veracode error responses
VERACODE_ERROR_RESPONSE_XML: Dict[str, bytes] = {}
VERACODE_ERROR_RESPONSE_XML[
"bytes"
] = b'<?xml version="1.0" encoding="UTF-8"?>\n\n<error>App not in state where new builds are allowed.</error>\n' # pylint: disable=line-too-long
VERACODE_ERROR_RESPONSE_XML["Element"] = ElementTree.fromstring(
VERACODE_ERROR_RESPONSE_XML["bytes"]
)
XML_API_VALID_RESPONSE_XML_ERROR: Dict[str, bytes] = {}
XML_API_VALID_RESPONSE_XML_ERROR[
"bytes"
] = b'<?xml version="1.0" encoding="UTF-8"?>\n\n<error>Access denied.</error>\n'
XML_API_VALID_RESPONSE_XML_ERROR["Element"] = ElementTree.fromstring(
XML_API_VALID_RESPONSE_XML_ERROR["bytes"]
)
XML_API_INVALID_RESPONSE_XML_ERROR: Dict[str, bytes] = {}
XML_API_INVALID_RESPONSE_XML_ERROR[
"bytes"
] = b'<?xml version="1.0" encoding="UTF-8"?>\n\n<Invalid Error Message.</error>\n'
# Configs
INVALID_CONFIG_DIRTY = {
"a": 1,
"b": {},
"c": {"hideme": None, "keepme": "KEEP", "list": ["a", {}, "b", None]},
"emptydict": {},
None: "hide",
}
INVALID_CONFIG_NO_NONE = {
"a": 1,
"b": {},
"c": {"keepme": "KEEP", "list": ["a", {}, "b"]},
"emptydict": {},
}
INVALID_CONFIG_NO_EMPTY_DICT = {
"a": 1,
"c": {"hideme": None, "keepme": "KEEP", "list": ["a", "b", None]},
None: "hide",
}
INVALID_CONFIG_CLEAN = {
"a": 1,
"c": {"keepme": "KEEP", "list": ["a", "b"]},
}
SIMPLE_CONFIG_FILE = {}
SIMPLE_CONFIG_FILE["name"] = "easy_sast.yml"
SIMPLE_CONFIG_FILE["Path"] = Path("/path/" + str(SIMPLE_CONFIG_FILE["name"]))
SIMPLE_CONFIG_FILE[
"string"
] = '''---
loglevel: "WARNING"'''
SIMPLE_CONFIG_FILE["bytes"] = bytes(SIMPLE_CONFIG_FILE["string"], "utf-8")
INVALID_CONFIG_FILES = [
Path("./easy_sast.yml.gz"),
Path("./config.txt.yml"),
Path("./thing.notyml"),
Path("./not_a_config.pdb"),
Path("./config.yalm"),
Path("./yaml.config"),
Path("./setup.cfg"),
Path("./config.ini"),
Path("./file.json"),
Path("./yaml"),
Path("./yml"),
Path("./config"),
]
VALID_CLEAN_FILE_CONFIG = {}
VALID_CLEAN_FILE_CONFIG[
"string"
] = '''---
apis:
results:
base_url: "https://analysiscenter.veracode.com/api/"
version: {
"detailedreport.do": "5.0",
"detailedreportpdf.do": "4.0",
"getaccountcustomfieldlist.do": "5.0",
"getappbuilds.do": "4.0",
"getcallstacks.do": "5.0",
"summaryreport.do": "4.0",
"summaryreportpdf.do": "4.0",
"thirdpartyreportpdf.do": "4.0",
}
app_id: "31337"
ignore_compliance_status: False
upload:
base_url: "https://analysiscenter.veracode.com/api/"
version: {
"beginprescan.do": "5.0",
"beginscan.do": "5.0",
"createapp.do": "5.0",
"createbuild.do": "5.0",
"deleteapp.do": "5.0",
"deletebuild.do": "5.0",
"getappinfo.do": "5.0",
"getapplist.do": "5.0",
"getbuildinfo.do": "5.0",
"getbuildlist.do": "5.0",
"getfilelist.do": "5.0",
"getpolicylist.do": "5.0",
"getprescanresults.do": "5.0",
"getvendorlist.do": "5.0",
"removefile.do": "5.0",
"updateapp.do": "5.0",
"updatebuild.do": "5.0",
"uploadfile.do": "5.0",
"uploadlargefile.do": "5.0"
}
app_id: "31337"
build_dir: "/build/"
build_id: "2037-03-13_03-14-15"
scan_all_nonfatal_top_level_modules: True
auto_scan: True
sandbox:
base_url: "https://analysiscenter.veracode.com/api/"
version: {
"createsandbox.do": "5.0",
"getsandboxlist.do": "5.0",
"promotesandbox.do": "5.0",
"updatesandbox.do": "5.0",
"deletesandbox.do": "5.0"
}
app_id: "31337"
sandbox_name: "fb/jonzeolla/name-of-branch"
loglevel: "warning"
workflow:
- "submit_artifacts"
- "check_compliance"'''
VALID_CLEAN_FILE_CONFIG["bytes"] = bytes(VALID_CLEAN_FILE_CONFIG["string"], "utf-8")
VALID_CLEAN_FILE_CONFIG["dict"] = yaml.safe_load(VALID_CLEAN_FILE_CONFIG["bytes"])
# VALID_CLEAN_FILE_CONFIG is already normalized, but separating it here in case
# in the future it isn't and we want to update the places where this is used to
# mock the response to normalized_file_config
VALID_CLEAN_FILE_CONFIG_NORMALIZED = copy.deepcopy(VALID_CLEAN_FILE_CONFIG)
CLEAN_DEFAULT_CONFIG = {
"workflow": ["submit_artifacts", "check_compliance"],
"loglevel": "WARNING",
"apis": {"upload": {}, "results": {}, "sandbox": {}},
}
CLEAN_FILE_CONFIG = {
"apis": {
"results": {
"base_url": "https://analysiscenter.veracode.com/api/",
"version": {
"detailedreport.do": "5.0",
"detailedreportpdf.do": "4.0",
"getaccountcustomfieldlist.do": "5.0",
"getappbuilds.do": "4.0",
"getcallstacks.do": "5.0",
"summaryreport.do": "4.0",
"summaryreportpdf.do": "4.0",
"thirdpartyreportpdf.do": "4.0",
},
"app_id": "31337",
"ignore_compliance_status": False,
},
"upload": {
"base_url": "https://analysiscenter.veracode.com/api/",
"version": {
"beginprescan.do": "5.0",
"beginscan.do": "5.0",
"createapp.do": "5.0",
"createbuild.do": "5.0",
"deleteapp.do": "5.0",
"deletebuild.do": "5.0",
"getappinfo.do": "5.0",
"getapplist.do": "5.0",
"getbuildinfo.do": "5.0",
"getbuildlist.do": "5.0",
"getfilelist.do": "5.0",
"getpolicylist.do": "5.0",
"getprescanresults.do": "5.0",
"getvendorlist.do": "5.0",
"removefile.do": "5.0",
"updateapp.do": "5.0",
"updatebuild.do": "5.0",
"uploadfile.do": "5.0",
"uploadlargefile.do": "5.0",
},
"app_id": "31337",
"build_dir": Path("/build/").absolute(),
"build_id": "2037-03-13_03-14-15",
"scan_all_nonfatal_top_level_modules": True,
"auto_scan": True,
},
"sandbox": {
"base_url": "https://analysiscenter.veracode.com/api/",
"version": {
"createsandbox.do": "5.0",
"getsandboxlist.do": "5.0",
"promotesandbox.do": "5.0",
"updatesandbox.do": "5.0",
"deletesandbox.do": "5.0",
},
"app_id": "31337",
"sandbox_name": VALID_SANDBOX_API["sandbox_name"],
},
},
"loglevel": "WARNING",
"workflow": ["submit_artifacts", "check_compliance"],
}
CLEAN_ENV_CONFIG = {
"api_key_id": "95e637f1a25d453cdfdc30a338287ba8",
"api_key_secret": "f7bb8c01bce05290ac8939f1d27d90ab84d2e05bb4671ca2f88d609d07afa723265348d708bdd0a1707a499528f6aa5c83133f4c5aca06a528d30b61fd4b6b28",
}
CLEAN_ARGS_CONFIG = {
"config_file": Path("/easy_sast/easy_sast.yml"),
"apis": {
"results": {"ignore_compliance_status": False},
"upload": {"scan_all_nonfatal_top_level_modules": True, "auto_scan": True},
"sandbox": {"sandbox_name": VALID_SANDBOX_API["sandbox_name"]},
},
}
CLEAN_FILE_CONFIG_NO_RESULTS_API = copy.deepcopy(CLEAN_FILE_CONFIG)
CLEAN_FILE_CONFIG_NO_RESULTS_API["apis"] = {"upload": {}}
CLEAN_FILE_CONFIG_NO_UPLOAD_API = copy.deepcopy(CLEAN_FILE_CONFIG)
CLEAN_FILE_CONFIG_NO_UPLOAD_API["apis"] = {"results": {}}
CLEAN_EFFECTIVE_CONFIG = {
"workflow": ["submit_artifacts", "check_compliance"],
"loglevel": "WARNING",
"apis": {
"sandbox": {
"base_url": "https://analysiscenter.veracode.com/api/",
"version": {
"createsandbox.do": "5.0",
"getsandboxlist.do": "5.0",
"promotesandbox.do": "5.0",
"updatesandbox.do": "5.0",
"deletesandbox.do": "5.0",
},
"app_id": "31337",
"sandbox_name": VALID_SANDBOX_API["sandbox_name"],
},
"upload": {
"base_url": "https://analysiscenter.veracode.com/api/",
"version": {
"beginprescan.do": "5.0",
"beginscan.do": "5.0",
"createapp.do": "5.0",
"createbuild.do": "5.0",
"deleteapp.do": "5.0",
"deletebuild.do": "5.0",
"getappinfo.do": "5.0",
"getapplist.do": "5.0",
"getbuildinfo.do": "5.0",
"getbuildlist.do": "5.0",
"getfilelist.do": "5.0",
"getpolicylist.do": "5.0",
"getprescanresults.do": "5.0",
"getvendorlist.do": "5.0",
"removefile.do": "5.0",
"updateapp.do": "5.0",
"updatebuild.do": "5.0",
"uploadfile.do": "5.0",
"uploadlargefile.do": "5.0",
},
"app_id": "31337",
"build_dir": Path("/build/").absolute(),
"build_id": "2037-03-13_03-14-15",
"scan_all_nonfatal_top_level_modules": True,
"auto_scan": True,
},
"results": {
"base_url": "https://analysiscenter.veracode.com/api/",
"version": {
"detailedreport.do": "5.0",
"detailedreportpdf.do": "4.0",
"getaccountcustomfieldlist.do": "5.0",
"getappbuilds.do": "4.0",
"getcallstacks.do": "5.0",
"summaryreport.do": "4.0",
"summaryreportpdf.do": "4.0",
"thirdpartyreportpdf.do": "4.0",
},
"app_id": "31337",
"ignore_compliance_status": False,
},
},
"api_key_id": "95e637f1a25d453cdfdc30a338287ba8",
"api_key_secret": "f7bb8c01bce05290ac8939f1d27d90ab84d2e05bb4671ca2f88d609d07afa723265348d708bdd0a1707a499528f6aa5c83133f4c5aca06a528d30b61fd4b6b28",
"config_file": Path("/easy_sast/easy_sast.yml"),
}