gitlabcis 1.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. gitlabcis/__init__.py +12 -0
  2. gitlabcis/__main__.py +7 -0
  3. gitlabcis/benchmarks/__init__.py +8 -0
  4. gitlabcis/benchmarks/artifacts_4/__init__.py +4 -0
  5. gitlabcis/benchmarks/artifacts_4/access_to_artifacts_4_2.py +139 -0
  6. gitlabcis/benchmarks/artifacts_4/origin_traceability_4_4.py +11 -0
  7. gitlabcis/benchmarks/artifacts_4/package_registries_4_3.py +105 -0
  8. gitlabcis/benchmarks/artifacts_4/verification_4_1.py +83 -0
  9. gitlabcis/benchmarks/build_pipelines_2/__init__.py +4 -0
  10. gitlabcis/benchmarks/build_pipelines_2/build_environment_2_1.py +268 -0
  11. gitlabcis/benchmarks/build_pipelines_2/build_worker_2_2.py +129 -0
  12. gitlabcis/benchmarks/build_pipelines_2/pipeline_instructions_2_3.py +444 -0
  13. gitlabcis/benchmarks/build_pipelines_2/pipeline_integrity_2_4.py +146 -0
  14. gitlabcis/benchmarks/dependencies_3/__init__.py +2 -0
  15. gitlabcis/benchmarks/dependencies_3/third_party_packages_3_1.py +171 -0
  16. gitlabcis/benchmarks/dependencies_3/validate_packages_3_2.py +182 -0
  17. gitlabcis/benchmarks/deployment_5/__init__.py +2 -0
  18. gitlabcis/benchmarks/deployment_5/deployment_configuration_5_1.py +165 -0
  19. gitlabcis/benchmarks/deployment_5/deployment_environment_5_2.py +66 -0
  20. gitlabcis/benchmarks/source_code_1/__init__.py +6 -0
  21. gitlabcis/benchmarks/source_code_1/code_changes_1_1.py +665 -0
  22. gitlabcis/benchmarks/source_code_1/code_risks_1_5.py +506 -0
  23. gitlabcis/benchmarks/source_code_1/contribution_access_1_3.py +334 -0
  24. gitlabcis/benchmarks/source_code_1/repository_management_1_2.py +168 -0
  25. gitlabcis/benchmarks/source_code_1/third_party_1_4.py +139 -0
  26. gitlabcis/cli/__init__.py +0 -0
  27. gitlabcis/cli/log.py +30 -0
  28. gitlabcis/cli/main.py +541 -0
  29. gitlabcis/cli/output.py +151 -0
  30. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/external_auth_server.yml +51 -0
  31. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/limit_artifact_uploaders.yml +57 -0
  32. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/limit_certifying_artifacts.yml +53 -0
  33. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/minimum_package_registry_admins.yml +54 -0
  34. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/readme.md +14 -0
  35. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/require_mfa_to_package_registry.yml +52 -0
  36. gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/restrict_anonymous_access.yml +67 -0
  37. gitlabcis/recommendations/artifacts_4/origin_traceability_4_4/artifact_origin_info.yml +56 -0
  38. gitlabcis/recommendations/artifacts_4/origin_traceability_4_4/readme.md +7 -0
  39. gitlabcis/recommendations/artifacts_4/package_registries_4_3/all_artifact_versions_signed.yml +70 -0
  40. gitlabcis/recommendations/artifacts_4/package_registries_4_3/audit_package_registry_config.yml +46 -0
  41. gitlabcis/recommendations/artifacts_4/package_registries_4_3/readme.md +12 -0
  42. gitlabcis/recommendations/artifacts_4/package_registries_4_3/secure_repo_webhooks.yml +50 -0
  43. gitlabcis/recommendations/artifacts_4/package_registries_4_3/validate_signed_artifacts_on_upload.yml +72 -0
  44. gitlabcis/recommendations/artifacts_4/readme.md +12 -0
  45. gitlabcis/recommendations/artifacts_4/verification_4_1/encrypt_artifacts_before_distribution.yml +47 -0
  46. gitlabcis/recommendations/artifacts_4/verification_4_1/only_authorized_platforms_can_decrypt_artifacts.yml +59 -0
  47. gitlabcis/recommendations/artifacts_4/verification_4_1/readme.md +11 -0
  48. gitlabcis/recommendations/artifacts_4/verification_4_1/sign_artifacts_in_build_pipeline.yml +40 -0
  49. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/authenticate_build_access.yml +55 -0
  50. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_automation.yml +54 -0
  51. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_env_admins.yml +55 -0
  52. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_logging.yml +49 -0
  53. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/disable_build_tools_default_passwords.yml +54 -0
  54. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/immutable_pipeline_infrastructure.yml +60 -0
  55. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/limit_build_access.yml +64 -0
  56. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/limit_build_secrets_scope.yml +56 -0
  57. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/readme.md +19 -0
  58. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/secure_build_env_webhooks.yml +43 -0
  59. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/single_responsibility_pipeline.yml +58 -0
  60. gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/vuln_scanning.yml +64 -0
  61. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/build_worker_vuln_scanning.yml +58 -0
  62. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/monitor_worker_resource_consumption.yml +59 -0
  63. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/pass_worker_envs_and_commands.yml +48 -0
  64. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/readme.md +16 -0
  65. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/restrict_worker_connectivity.yml +61 -0
  66. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/segregate_worker_duties.yml +78 -0
  67. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/single_use_workers.yml +47 -0
  68. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/store_worker_config.yml +62 -0
  69. gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/worker_runtime_security.yml +37 -0
  70. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/build_stage_io.yml +49 -0
  71. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/build_steps_as_code.yml +42 -0
  72. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/limit_pipeline_triggers.yml +76 -0
  73. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_misconfiguration_scanning.yml +48 -0
  74. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_secret_scanning.yml +56 -0
  75. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_vuln_scanning.yml +44 -0
  76. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/readme.md +16 -0
  77. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/secure_pipeline_output.yml +52 -0
  78. gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/track_pipeline_files.yml +48 -0
  79. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/create_reproducible_artifacts.yml +52 -0
  80. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/lock_dependencies.yml +59 -0
  81. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/pipeline_produces_sbom.yml +81 -0
  82. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/pipeline_signs_sbom.yml +38 -0
  83. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/readme.md +14 -0
  84. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/sign_artifacts.yml +35 -0
  85. gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/validate_dependencies.yml +63 -0
  86. gitlabcis/recommendations/build_pipelines_2/readme.md +12 -0
  87. gitlabcis/recommendations/dependencies_3/readme.md +10 -0
  88. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/define_package_managers.yml +84 -0
  89. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/dependency_sbom.yml +84 -0
  90. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/monitor_dependencies.yml +61 -0
  91. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/packages_over_60_days_old.yml +95 -0
  92. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/pin_dependency_version.yml +48 -0
  93. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/readme.md +14 -0
  94. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/third_party_sbom_required.yml +70 -0
  95. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/verify_artifacts.yml +45 -0
  96. gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/verify_signed_metadata.yml +41 -0
  97. gitlabcis/recommendations/dependencies_3/validate_packages_3_2/org_wide_dependency_policy.yml +47 -0
  98. gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_license_scanning.yml +47 -0
  99. gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_ownership_change.yml +42 -0
  100. gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_vuln_scanning.yml +62 -0
  101. gitlabcis/recommendations/dependencies_3/validate_packages_3_2/readme.md +10 -0
  102. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/audit_deployment_config.yml +46 -0
  103. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/limit_deployment_config_access.yml +51 -0
  104. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/pin_deployment_config_manifests.yml +59 -0
  105. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/readme.md +13 -0
  106. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/scan_iac.yml +72 -0
  107. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/secret_scan_deployment_config.yml +45 -0
  108. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/separate_deployment_config.yml +50 -0
  109. gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/verify_deployment_config.yml +49 -0
  110. gitlabcis/recommendations/deployment_5/deployment_environment_5_2/automate_deployment.yml +47 -0
  111. gitlabcis/recommendations/deployment_5/deployment_environment_5_2/disable_default_passwords.yml +63 -0
  112. gitlabcis/recommendations/deployment_5/deployment_environment_5_2/limit_prod_access.yml +45 -0
  113. gitlabcis/recommendations/deployment_5/deployment_environment_5_2/readme.md +12 -0
  114. gitlabcis/recommendations/deployment_5/deployment_environment_5_2/reproducible_deployment.yml +50 -0
  115. gitlabcis/recommendations/deployment_5/readme.md +10 -0
  116. gitlabcis/recommendations/readme.md +24 -0
  117. gitlabcis/recommendations/source_code_1/code_changes_1_1/audit_branch_protections.yml +56 -0
  118. gitlabcis/recommendations/source_code_1/code_changes_1_1/auto_risk_scan_merges.yml +62 -0
  119. gitlabcis/recommendations/source_code_1/code_changes_1_1/branch_protections_for_admins.yml +60 -0
  120. gitlabcis/recommendations/source_code_1/code_changes_1_1/branches_updated_before_merging.yml +56 -0
  121. gitlabcis/recommendations/source_code_1/code_changes_1_1/checks_pass_before_merging.yml +57 -0
  122. gitlabcis/recommendations/source_code_1/code_changes_1_1/code_approval_dismissals.yml +62 -0
  123. gitlabcis/recommendations/source_code_1/code_changes_1_1/code_approvals.yml +65 -0
  124. gitlabcis/recommendations/source_code_1/code_changes_1_1/code_changes_require_code_owners.yml +68 -0
  125. gitlabcis/recommendations/source_code_1/code_changes_1_1/code_dismissal_restrictions.yml +69 -0
  126. gitlabcis/recommendations/source_code_1/code_changes_1_1/code_owners.yml +61 -0
  127. gitlabcis/recommendations/source_code_1/code_changes_1_1/code_tracing.yml +52 -0
  128. gitlabcis/recommendations/source_code_1/code_changes_1_1/comments_resolved_before_merging.yml +59 -0
  129. gitlabcis/recommendations/source_code_1/code_changes_1_1/commits_must_be_signed_before_merging.yml +63 -0
  130. gitlabcis/recommendations/source_code_1/code_changes_1_1/default_branch_protected.yml +85 -0
  131. gitlabcis/recommendations/source_code_1/code_changes_1_1/deny_branch_deletions.yml +76 -0
  132. gitlabcis/recommendations/source_code_1/code_changes_1_1/ensure_force_push_is_denied.yml +59 -0
  133. gitlabcis/recommendations/source_code_1/code_changes_1_1/linear_history_required.yml +56 -0
  134. gitlabcis/recommendations/source_code_1/code_changes_1_1/merging_restrictions.yml +65 -0
  135. gitlabcis/recommendations/source_code_1/code_changes_1_1/readme.md +26 -0
  136. gitlabcis/recommendations/source_code_1/code_changes_1_1/stale_branch_reviews.yml +72 -0
  137. gitlabcis/recommendations/source_code_1/code_changes_1_1/version_control.yml +45 -0
  138. gitlabcis/recommendations/source_code_1/code_risks_1_5/dast_api_scanning.yml +50 -0
  139. gitlabcis/recommendations/source_code_1/code_risks_1_5/dast_web_scanning.yml +51 -0
  140. gitlabcis/recommendations/source_code_1/code_risks_1_5/dependency_scanning.yml +84 -0
  141. gitlabcis/recommendations/source_code_1/code_risks_1_5/enable_secret_detection.yml +45 -0
  142. gitlabcis/recommendations/source_code_1/code_risks_1_5/license_scanning.yml +47 -0
  143. gitlabcis/recommendations/source_code_1/code_risks_1_5/readme.md +14 -0
  144. gitlabcis/recommendations/source_code_1/code_risks_1_5/secure_iac_instructions.yml +81 -0
  145. gitlabcis/recommendations/source_code_1/code_risks_1_5/secure_pipeline_instructions.yml +62 -0
  146. gitlabcis/recommendations/source_code_1/code_risks_1_5/vulnerability_scanning.yml +48 -0
  147. gitlabcis/recommendations/source_code_1/contribution_access_1_3/domain_verification.yml +65 -0
  148. gitlabcis/recommendations/source_code_1/contribution_access_1_3/ensure_2_admins_per_repo.yml +56 -0
  149. gitlabcis/recommendations/source_code_1/contribution_access_1_3/limit_top_level_group_creation.yml +61 -0
  150. gitlabcis/recommendations/source_code_1/contribution_access_1_3/limit_user_registration_domain.yml +58 -0
  151. gitlabcis/recommendations/source_code_1/contribution_access_1_3/minimum_number_of_admins.yml +56 -0
  152. gitlabcis/recommendations/source_code_1/contribution_access_1_3/org_provided_ssh_certs.yml +70 -0
  153. gitlabcis/recommendations/source_code_1/contribution_access_1_3/readme.md +21 -0
  154. gitlabcis/recommendations/source_code_1/contribution_access_1_3/require_mfa_at_org_level.yml +89 -0
  155. gitlabcis/recommendations/source_code_1/contribution_access_1_3/require_mfa_for_contributors.yml +76 -0
  156. gitlabcis/recommendations/source_code_1/contribution_access_1_3/restrict_ip_addresses.yml +84 -0
  157. gitlabcis/recommendations/source_code_1/contribution_access_1_3/review_and_remove_inactive_users.yml +62 -0
  158. gitlabcis/recommendations/source_code_1/contribution_access_1_3/scm_notification_restriction.yml +46 -0
  159. gitlabcis/recommendations/source_code_1/contribution_access_1_3/strict_permissions_for_repo.yml +62 -0
  160. gitlabcis/recommendations/source_code_1/contribution_access_1_3/track_code_anomalies.yml +43 -0
  161. gitlabcis/recommendations/source_code_1/readme.md +13 -0
  162. gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_issue_deletions.yml +57 -0
  163. gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_repo_creations.yml +64 -0
  164. gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_repo_deletions.yml +57 -0
  165. gitlabcis/recommendations/source_code_1/repository_management_1_2/public_repos_have_security_file.yml +59 -0
  166. gitlabcis/recommendations/source_code_1/repository_management_1_2/readme.md +15 -0
  167. gitlabcis/recommendations/source_code_1/repository_management_1_2/review_and_archive_stale_repos.yml +65 -0
  168. gitlabcis/recommendations/source_code_1/repository_management_1_2/track_forks.yml +74 -0
  169. gitlabcis/recommendations/source_code_1/repository_management_1_2/track_project_visibility_status.yml +74 -0
  170. gitlabcis/recommendations/source_code_1/third_party_1_4/README.md +12 -0
  171. gitlabcis/recommendations/source_code_1/third_party_1_4/admin_approval_for_app_installs.yml +83 -0
  172. gitlabcis/recommendations/source_code_1/third_party_1_4/least_privilge_app_permissions.yml +103 -0
  173. gitlabcis/recommendations/source_code_1/third_party_1_4/secure_webhooks.yml +73 -0
  174. gitlabcis/recommendations/source_code_1/third_party_1_4/stale_app_reviews.yml +66 -0
  175. gitlabcis/recommendations/template.yml +30 -0
  176. gitlabcis/tests/__init__.py +0 -0
  177. gitlabcis/tests/input/__init__.py +0 -0
  178. gitlabcis/tests/input/conftest.py +29 -0
  179. gitlabcis/tests/input/no_input_test.py +82 -0
  180. gitlabcis/tests/input/switch_test.py +19 -0
  181. gitlabcis/tests/input/version_test.py +7 -0
  182. gitlabcis/tests/unit/__init__.py +0 -0
  183. gitlabcis/tests/unit/benchmarks/artifacts_4/access_to_artifacts_4_2_test.py +131 -0
  184. gitlabcis/tests/unit/benchmarks/artifacts_4/origin_traceability_4_4_test.py +15 -0
  185. gitlabcis/tests/unit/benchmarks/artifacts_4/package_registries_4_3_test.py +102 -0
  186. gitlabcis/tests/unit/benchmarks/artifacts_4/verification_4_1_test.py +78 -0
  187. gitlabcis/tests/unit/benchmarks/build_pipelines_2/build_environment_2_1_test.py +239 -0
  188. gitlabcis/tests/unit/benchmarks/build_pipelines_2/build_worker_2_2_test.py +105 -0
  189. gitlabcis/tests/unit/benchmarks/build_pipelines_2/pipeline_instructions_2_3_test.py +340 -0
  190. gitlabcis/tests/unit/benchmarks/build_pipelines_2/pipeline_integrity_2_4_test.py +115 -0
  191. gitlabcis/tests/unit/benchmarks/conftest.py +47 -0
  192. gitlabcis/tests/unit/benchmarks/dependencies_3/third_party_packages_3_1_test.py +135 -0
  193. gitlabcis/tests/unit/benchmarks/dependencies_3/validate_packages_3_2_test.py +171 -0
  194. gitlabcis/tests/unit/benchmarks/deployment_5/deployment_configuration_5_1_test.py +140 -0
  195. gitlabcis/tests/unit/benchmarks/deployment_5/deployment_environment_5_2_test.py +60 -0
  196. gitlabcis/tests/unit/benchmarks/function_test.py +24 -0
  197. gitlabcis/tests/unit/benchmarks/source_code_1/code_changes_1_1_test.py +565 -0
  198. gitlabcis/tests/unit/benchmarks/source_code_1/code_risks_1_5_test.py +419 -0
  199. gitlabcis/tests/unit/benchmarks/source_code_1/contribution_access_1_3_test.py +265 -0
  200. gitlabcis/tests/unit/benchmarks/source_code_1/repository_management_1_2_test.py +142 -0
  201. gitlabcis/tests/unit/benchmarks/source_code_1/third_party_1_4_test.py +119 -0
  202. gitlabcis/tests/unit/conftest.py +94 -0
  203. gitlabcis/tests/unit/log/log_test.py +23 -0
  204. gitlabcis/tests/unit/utils/argfilters_test.py +9 -0
  205. gitlabcis/tests/unit/utils/ci_test.py +156 -0
  206. gitlabcis/tests/unit/utils/output_test.py +95 -0
  207. gitlabcis/tests/unit/utils/utils_general_test.py +149 -0
  208. gitlabcis/tests/unit/utils/version_test.py +11 -0
  209. gitlabcis/tests/unit/yaml/bad_file_test.py +15 -0
  210. gitlabcis/tests/unit/yaml/recommendation_test.py +123 -0
  211. gitlabcis/utils/__init__.py +146 -0
  212. gitlabcis/utils/ci.py +132 -0
  213. gitlabcis-1.3.2.dist-info/LICENSE +21 -0
  214. gitlabcis-1.3.2.dist-info/METADATA +241 -0
  215. gitlabcis-1.3.2.dist-info/RECORD +218 -0
  216. gitlabcis-1.3.2.dist-info/WHEEL +5 -0
  217. gitlabcis-1.3.2.dist-info/entry_points.txt +2 -0
  218. gitlabcis-1.3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,171 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ from unittest.mock import Mock
4
+
5
+ from conftest import run
6
+
7
+ from gitlabcis.benchmarks.dependencies_3 import validate_packages_3_2
8
+
9
+ # -----------------------------------------------------------------------------
10
+
11
+
12
+ def test_org_wide_dependency_policy(glEntity, glObject, gqlClient):
13
+
14
+ from gql.transport.exceptions import TransportServerError
15
+
16
+ test = validate_packages_3_2.org_wide_dependency_policy
17
+
18
+ glEntity.path_with_namespace = 'test/project'
19
+
20
+ kwargs = {
21
+ 'graphQLEndpoint': 'https://gitlab.com/api/graphql',
22
+ 'graphQLHeaders': {'Authorization': 'Bearer token'}
23
+ }
24
+
25
+ gqlClient.return_value.execute.return_value = {'project': {}}
26
+ run(glEntity, glObject, test, False, **kwargs)
27
+
28
+ mock_result = {
29
+ 'project': {
30
+ 'scanExecutionPolicies': {
31
+ 'nodes': [
32
+ {
33
+ 'enabled': True,
34
+ 'yaml': '''
35
+ actions:
36
+ - scan: secret_detection
37
+ - scan: dast
38
+ - scan: cluster_image_scanning
39
+ - scan: container_scanning
40
+ - scan: sast
41
+ - scan: sast_iac
42
+ - scan: dependency_scanning
43
+ rules:
44
+ - type: pipeline
45
+ branches: ['*']
46
+ '''
47
+ }
48
+ ]
49
+ }
50
+ }
51
+ }
52
+ gqlClient.return_value.execute.return_value = mock_result
53
+ run(glEntity, glObject, test, True, **kwargs)
54
+
55
+ mock_result = {
56
+ 'project': {
57
+ 'scanExecutionPolicies': {
58
+ 'nodes': [
59
+ {
60
+ 'enabled': True,
61
+ 'yaml': '''
62
+ actions:
63
+ - scan: dast
64
+ rules:
65
+ - type: pipeline
66
+ branches: ['*']
67
+ '''
68
+ }
69
+ ]
70
+ }
71
+ }
72
+ }
73
+ gqlClient.return_value.execute.return_value = mock_result
74
+ run(glEntity, glObject, test, False, **kwargs)
75
+
76
+ gqlClient.return_value.execute.side_effect = \
77
+ TransportServerError('GraphQL Error')
78
+ run(glEntity, glObject, test, None, **kwargs)
79
+
80
+ gqlClient.return_value.execute.side_effect = \
81
+ AttributeError()
82
+ run(glEntity, glObject, test, None, **kwargs)
83
+
84
+ # -----------------------------------------------------------------------------
85
+
86
+
87
+ def test_package_vuln_scanning(glEntity, glObject, unauthorised):
88
+
89
+ from gitlab.exceptions import GitlabGetError
90
+ from gitlab.v4.objects.files import ProjectFile
91
+
92
+ test = validate_packages_3_2.package_vuln_scanning
93
+
94
+ # throw an exception
95
+ unauthorised.settings.get.side_effect = Mock(side_effect=GitlabGetError(
96
+ response_code=401))
97
+ run(unauthorised, unauthorised, test, None)
98
+
99
+ # test success
100
+ settings = Mock(auto_devops_enabled=True)
101
+ glObject.settings.get.return_value = settings
102
+ run(glEntity, glObject, test, True)
103
+
104
+ # test success
105
+ settings = Mock(auto_devops_enabled=False)
106
+ glObject.settings.get.return_value = settings
107
+
108
+ glEntity.ci_config_path = ''
109
+ _projectFile = Mock(spec=ProjectFile)
110
+
111
+ # We need to fake "file contents" as base64 encoded str
112
+ # its value is: dependency_scanning
113
+ # this is passed to the ci.searchConfig() function
114
+
115
+ _projectFile.content = 'ZGVwZW5kZW5jeV9zY2FubmluZw=='
116
+ glEntity.files.get.return_value = _projectFile
117
+ run(glEntity, glObject, test, True)
118
+
119
+ # -----------------------------------------------------------------------------
120
+
121
+
122
+ def test_package_license_scanning(glEntity, glObject, unauthorised):
123
+
124
+ from gitlab.exceptions import GitlabGetError
125
+ from gitlab.v4.objects.files import ProjectFile
126
+
127
+ test = validate_packages_3_2.package_license_scanning
128
+
129
+ # throw an exception
130
+ unauthorised.settings.get.side_effect = Mock(side_effect=GitlabGetError(
131
+ response_code=401))
132
+ run(unauthorised, unauthorised, test, None)
133
+
134
+ # test success
135
+ settings = Mock(auto_devops_enabled=True)
136
+ glObject.settings.get.return_value = settings
137
+ run(glEntity, glObject, test, True)
138
+
139
+ # test fail
140
+ # we need to bypass the run function and call the test directly
141
+
142
+ settings = Mock(auto_devops_enabled=False)
143
+ glObject.settings.get.return_value = settings
144
+
145
+ glEntity.ci_config_path = 'https://gitlab.com/.gitlab-ci.yml'
146
+ assert next(iter(validate_packages_3_2.package_license_scanning(
147
+ glEntity, glObject))) is None
148
+
149
+ # test success
150
+ settings = Mock(auto_devops_enabled=False)
151
+ glObject.settings.get.return_value = settings
152
+
153
+ glEntity.ci_config_path = ''
154
+ _projectFile = Mock(spec=ProjectFile)
155
+
156
+ # We need to fake "file contents" as base64 encoded str
157
+ # its value is: dependency_scanning
158
+ # this is passed to the ci.searchConfig() function
159
+
160
+ _projectFile.content = 'ZGVwZW5kZW5jeV9zY2FubmluZw=='
161
+ glEntity.files.get.return_value = _projectFile
162
+ run(glEntity, glObject, test, True)
163
+
164
+ # -----------------------------------------------------------------------------
165
+
166
+
167
+ def test_package_ownership_change(glEntity, glObject):
168
+
169
+ test = validate_packages_3_2.package_ownership_change
170
+
171
+ run(glEntity, glObject, test, None)
@@ -0,0 +1,140 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ from unittest.mock import Mock, patch
4
+
5
+ import pytest # noqa: F401
6
+ from conftest import run
7
+ from gitlab.exceptions import GitlabHttpError
8
+
9
+ from gitlabcis.benchmarks.deployment_5 import deployment_configuration_5_1
10
+
11
+ # -----------------------------------------------------------------------------
12
+
13
+
14
+ @patch('gitlabcis.utils.ci.getConfig')
15
+ def test_separate_deployment_config(mockGetConfig, glEntity, glObject):
16
+
17
+ test = deployment_configuration_5_1.separate_deployment_config
18
+
19
+ mockGetConfig.return_value = {None: 'No CI file found'}
20
+ run(glEntity, glObject, test, None)
21
+
22
+ mockGetConfig.return_value = {False: 'Invalid CI file'}
23
+ run(glEntity, glObject, test, False)
24
+
25
+ mockGetConfig.return_value = {Mock(file_path=None): None}
26
+ run(glEntity, glObject, test, False)
27
+
28
+ mockGetConfig.return_value = {Mock(file_path='.gitlab-ci.yml'): None}
29
+ run(glEntity, glObject, test, False)
30
+
31
+ mockGetConfig.return_value = {
32
+ Mock(file_path='.gitlab/.gitlab-ci.yml'): None}
33
+ run(glEntity, glObject, test, True)
34
+
35
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=401)
36
+ run(glEntity, glObject, test, None)
37
+
38
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=418)
39
+ assert test(glEntity, glObject) is None
40
+
41
+ # -----------------------------------------------------------------------------
42
+
43
+
44
+ @patch('gitlabcis.utils.ci.getConfig')
45
+ def test_audit_deployment_config(mockGetConfig, glEntity, glObject):
46
+
47
+ test = deployment_configuration_5_1.audit_deployment_config
48
+
49
+ mockGetConfig.return_value = {None: 'No CI file found'}
50
+ run(glEntity, glObject, test, None)
51
+
52
+ mockGetConfig.return_value = {False: 'Invalid CI file'}
53
+ run(glEntity, glObject, test, False)
54
+
55
+ mockGetConfig.return_value = {'gitlab-ci.yml': None}
56
+ glEntity.approvalrules.list.return_value = [Mock(approvals_required=0)]
57
+ run(glEntity, glObject, test, False)
58
+
59
+ mockGetConfig.return_value = {'gitlab-ci.yml': None}
60
+ glEntity.approvalrules.list.return_value = [Mock(approvals_required=2)]
61
+ glObject.get_license.return_value = {'plan': 'GOLD PLATED PLATNUM'}
62
+ run(glEntity, glObject, test, False)
63
+
64
+ mockGetConfig.return_value = {'gitlab-ci.yml': None}
65
+ glEntity.approvalrules.list.return_value = [Mock(approvals_required=2)]
66
+ glObject.get_license.return_value = {'plan': 'ultimate'}
67
+ run(glEntity, glObject, test, True)
68
+
69
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=401)
70
+ run(glEntity, glObject, test, None)
71
+
72
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=418)
73
+ assert test(glEntity, glObject) is None
74
+
75
+ # -----------------------------------------------------------------------------
76
+
77
+
78
+ @patch('gitlabcis.utils.ci.searchConfig')
79
+ def test_secret_scan_deployment_config(mockSearchConfig, glEntity, glObject):
80
+
81
+ test = deployment_configuration_5_1.secret_scan_deployment_config
82
+
83
+ mockSearchConfig.return_value = {True: 'Secret-Detection found'}
84
+ run(glEntity, glObject, test, True)
85
+
86
+ mockSearchConfig.return_value = {False: 'Secret-Detection not found'}
87
+ run(glEntity, glObject, test, False)
88
+
89
+ mockSearchConfig.side_effect = GitlabHttpError(response_code=401)
90
+ run(glEntity, glObject, test, None)
91
+
92
+ mockSearchConfig.side_effect = GitlabHttpError(response_code=418)
93
+ assert test(glEntity, glObject) is None
94
+
95
+ # -----------------------------------------------------------------------------
96
+
97
+
98
+ def test_limit_deployment_config_access(glEntity, glObject):
99
+
100
+ test = deployment_configuration_5_1.limit_deployment_config_access
101
+
102
+ run(glEntity, glObject, test, None)
103
+
104
+ # -----------------------------------------------------------------------------
105
+
106
+
107
+ @patch('gitlabcis.utils.ci.searchConfig')
108
+ def test_scan_iac(mockSearchConfig, glEntity, glObject):
109
+
110
+ test = deployment_configuration_5_1.scan_iac
111
+
112
+ mockSearchConfig.return_value = {True: 'SAST-IaC found'}
113
+ run(glEntity, glObject, test, True)
114
+
115
+ mockSearchConfig.return_value = {False: 'SAST-IaC not found'}
116
+ run(glEntity, glObject, test, False)
117
+
118
+ mockSearchConfig.side_effect = GitlabHttpError(response_code=401)
119
+ run(glEntity, glObject, test, None)
120
+
121
+ mockSearchConfig.side_effect = GitlabHttpError(response_code=418)
122
+ assert test(glEntity, glObject) is None
123
+
124
+ # -----------------------------------------------------------------------------
125
+
126
+
127
+ def test_verify_deployment_config(glEntity, glObject):
128
+
129
+ test = deployment_configuration_5_1.verify_deployment_config
130
+
131
+ run(glEntity, glObject, test, None)
132
+
133
+ # -----------------------------------------------------------------------------
134
+
135
+
136
+ def test_pin_deployment_config_manifests(glEntity, glObject):
137
+
138
+ test = deployment_configuration_5_1.pin_deployment_config_manifests
139
+
140
+ run(glEntity, glObject, test, None)
@@ -0,0 +1,60 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ from unittest.mock import Mock, patch
4
+
5
+ import pytest # noqa: F401
6
+ from conftest import run
7
+ from gitlab.exceptions import GitlabHttpError
8
+
9
+ from gitlabcis.benchmarks.deployment_5 import deployment_environment_5_2
10
+
11
+ # -----------------------------------------------------------------------------
12
+
13
+
14
+ @patch('gitlabcis.utils.ci.getConfig')
15
+ def test_automate_deployment(mockGetConfig, glEntity, glObject):
16
+
17
+ test = deployment_environment_5_2.automate_deployment
18
+
19
+ mockGetConfig.return_value = {None: 'No CI file found'}
20
+ run(glEntity, glObject, test, None)
21
+
22
+ mockGetConfig.return_value = {False: 'Invalid CI file'}
23
+ run(glEntity, glObject, test, False)
24
+
25
+ mockGetConfig.return_value = {'gitlab-ci.yml': None}
26
+ glEntity.approvalrules.list.return_value = [Mock(approvals_required=0)]
27
+ run(glEntity, glObject, test, None)
28
+
29
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=401)
30
+ run(glEntity, glObject, test, None)
31
+
32
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=418)
33
+ assert test(glEntity, glObject) is None
34
+
35
+ # -----------------------------------------------------------------------------
36
+
37
+
38
+ def test_reproducible_deployment(glEntity, glObject):
39
+
40
+ test = deployment_environment_5_2.reproducible_deployment
41
+
42
+ run(glEntity, glObject, test, None)
43
+
44
+ # -----------------------------------------------------------------------------
45
+
46
+
47
+ def test_limit_prod_access(glEntity, glObject):
48
+
49
+ test = deployment_environment_5_2.limit_prod_access
50
+
51
+ run(glEntity, glObject, test, None)
52
+
53
+ # -----------------------------------------------------------------------------
54
+
55
+
56
+ def test_disable_default_passwords(glEntity, glObject):
57
+
58
+ test = deployment_environment_5_2.disable_default_passwords
59
+
60
+ run(glEntity, glObject, test, None)
@@ -0,0 +1,24 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+
4
+ def test_function_doc_strings(benchmarkFunctions):
5
+ """
6
+ Test that the function docstring contains id and title of the
7
+ recommendation.
8
+ """
9
+
10
+ for benchmark in benchmarkFunctions:
11
+ assert 'id:' in benchmark.__doc__ and 'title:' in benchmark.__doc__
12
+
13
+ # -----------------------------------------------------------------------------
14
+
15
+
16
+ def test_function_name(benchmarkFunctions, recommendations):
17
+ """
18
+ Test that the function name matches that of a yaml recommendation name.
19
+ """
20
+
21
+ _recNames = recommendations.keys()
22
+
23
+ for benchmark in benchmarkFunctions:
24
+ assert benchmark.__name__ in _recNames