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,131 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ from unittest.mock import Mock
4
+
5
+ import pytest # noqa: F401
6
+ from conftest import run
7
+ from gitlab.exceptions import GitlabHttpError
8
+
9
+ from gitlabcis.benchmarks.artifacts_4 import access_to_artifacts_4_2
10
+
11
+ # -----------------------------------------------------------------------------
12
+
13
+
14
+ def test_limit_certifying_artifacts(glEntity, glObject):
15
+
16
+ test = access_to_artifacts_4_2.limit_certifying_artifacts
17
+
18
+ run(glEntity, glObject, test, None)
19
+
20
+ # -----------------------------------------------------------------------------
21
+
22
+
23
+ def test_limit_artifact_uploaders(glEntity, glObject):
24
+
25
+ test = access_to_artifacts_4_2.limit_artifact_uploaders
26
+
27
+ glEntity.members.list.return_value = [
28
+ Mock(access_level=40),
29
+ Mock(access_level=30),
30
+ Mock(access_level=20),
31
+ Mock(access_level=10),
32
+ Mock(access_level=10)
33
+ ]
34
+ run(glEntity, glObject, test, True)
35
+
36
+ glEntity.members.list.return_value = [
37
+ Mock(access_level=40),
38
+ Mock(access_level=40),
39
+ Mock(access_level=40),
40
+ Mock(access_level=30),
41
+ Mock(access_level=20)
42
+ ]
43
+ run(glEntity, glObject, test, False)
44
+
45
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=403)
46
+ run(glEntity, glObject, test, None)
47
+
48
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=418)
49
+ assert test(glEntity, glObject) is None
50
+
51
+ # -----------------------------------------------------------------------------
52
+
53
+
54
+ def test_require_mfa_to_package_registry(glEntity, glObject):
55
+
56
+ test = access_to_artifacts_4_2.require_mfa_to_package_registry
57
+
58
+ glObject.settings.get.return_value = Mock(
59
+ require_two_factor_authentication=True)
60
+ run(glEntity, glObject, test, True)
61
+
62
+ glObject.settings.get.return_value = Mock(
63
+ require_two_factor_authentication=False)
64
+ run(glEntity, glObject, test, False)
65
+
66
+ glObject.settings.get.side_effect = GitlabHttpError(response_code=403)
67
+ run(glEntity, glObject, test, None)
68
+
69
+ glObject.settings.get.side_effect = GitlabHttpError(response_code=418)
70
+ assert test(glEntity, glObject) is None
71
+
72
+ # -----------------------------------------------------------------------------
73
+
74
+
75
+ def test_external_auth_server(glEntity, glObject):
76
+
77
+ test = access_to_artifacts_4_2.external_auth_server
78
+
79
+ run(glEntity, glObject, test, None)
80
+
81
+ # -----------------------------------------------------------------------------
82
+
83
+
84
+ def test_restrict_anonymous_access(glEntity, glObject):
85
+
86
+ test = access_to_artifacts_4_2.restrict_anonymous_access
87
+
88
+ glObject.settings.get.return_value = Mock(
89
+ default_project_visibility='public')
90
+ run(glEntity, glObject, test, False)
91
+
92
+ glObject.settings.get.return_value = Mock(
93
+ default_project_visibility='not-public')
94
+ run(glEntity, glObject, test, True)
95
+
96
+ glObject.settings.get.side_effect = GitlabHttpError(response_code=403)
97
+ run(glEntity, glObject, test, None)
98
+
99
+ glObject.settings.get.side_effect = GitlabHttpError(response_code=418)
100
+ assert test(glEntity, glObject) is None
101
+
102
+ # -----------------------------------------------------------------------------
103
+
104
+
105
+ def test_minimum_package_registry_admins(glEntity, glObject):
106
+
107
+ test = access_to_artifacts_4_2.minimum_package_registry_admins
108
+
109
+ glEntity.members.list.return_value = [
110
+ Mock(access_level=40),
111
+ Mock(access_level=10),
112
+ Mock(access_level=10),
113
+ Mock(access_level=10),
114
+ Mock(access_level=10)
115
+ ]
116
+ run(glEntity, glObject, test, True)
117
+
118
+ glEntity.members.list.return_value = [
119
+ Mock(access_level=40),
120
+ Mock(access_level=40),
121
+ Mock(access_level=40),
122
+ Mock(access_level=40),
123
+ Mock(access_level=20)
124
+ ]
125
+ run(glEntity, glObject, test, False)
126
+
127
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=403)
128
+ run(glEntity, glObject, test, None)
129
+
130
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=418)
131
+ assert test(glEntity, glObject) is None
@@ -0,0 +1,15 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ import pytest # noqa: F401
4
+ from conftest import run
5
+
6
+ from gitlabcis.benchmarks.artifacts_4 import origin_traceability_4_4
7
+
8
+ # -----------------------------------------------------------------------------
9
+
10
+
11
+ def test_artifact_origin_info(glEntity, glObject):
12
+
13
+ test = origin_traceability_4_4.artifact_origin_info
14
+
15
+ run(glEntity, glObject, test, None)
@@ -0,0 +1,102 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ from unittest.mock import Mock
4
+
5
+ import pytest # noqa: F401
6
+ from conftest import run
7
+ from gitlab.exceptions import GitlabHttpError
8
+
9
+ from gitlabcis.benchmarks.artifacts_4 import package_registries_4_3
10
+
11
+ # -----------------------------------------------------------------------------
12
+
13
+
14
+ def test_validate_signed_artifacts_on_upload(glEntity, glObject):
15
+
16
+ test = package_registries_4_3.validate_signed_artifacts_on_upload
17
+
18
+ glEntity.commits.list.return_value = [Mock(id='1'), Mock(id='2')]
19
+
20
+ glEntity.commits.get.return_value = Mock(status='verified')
21
+ run(glEntity, glObject, test, True)
22
+
23
+ glEntity.commits.get.return_value = Mock(status=None)
24
+ run(glEntity, glObject, test, False)
25
+
26
+ glEntity.commits.get.side_effect = [
27
+ Mock(status='verified'), Mock(status='unverified')]
28
+ run(glEntity, glObject, test, False)
29
+
30
+ glEntity.commits.list.side_effect = GitlabHttpError(response_code=403)
31
+ run(glEntity, glObject, test, None)
32
+
33
+ glEntity.commits.list.side_effect = GitlabHttpError(response_code=418)
34
+ assert test(glEntity, glObject) is None
35
+
36
+ # -----------------------------------------------------------------------------
37
+
38
+
39
+ def test_all_artifact_versions_signed(glEntity, glObject):
40
+
41
+ test = package_registries_4_3.all_artifact_versions_signed
42
+
43
+ glEntity.commits.list.return_value = [Mock(id='1'), Mock(id='2')]
44
+
45
+ glEntity.commits.get.return_value = Mock(status=None)
46
+ run(glEntity, glObject, test, False)
47
+
48
+ glEntity.commits.get.return_value = Mock(status='verified')
49
+ run(glEntity, glObject, test, True)
50
+
51
+ glEntity.commits.get.return_value = Mock(status='unverified')
52
+ run(glEntity, glObject, test, False)
53
+
54
+ glEntity.commits.list.side_effect = GitlabHttpError(response_code=403)
55
+ run(glEntity, glObject, test, None)
56
+
57
+ glEntity.commits.list.side_effect = GitlabHttpError(response_code=418)
58
+ assert test(glEntity, glObject) is None
59
+
60
+ # -----------------------------------------------------------------------------
61
+
62
+
63
+ def test_audit_package_registry_config(glEntity, glObject):
64
+
65
+ test = package_registries_4_3.audit_package_registry_config
66
+
67
+ run(glEntity, glObject, test, None)
68
+
69
+ # -----------------------------------------------------------------------------
70
+
71
+
72
+ def test_secure_repo_webhooks(glEntity, glObject):
73
+
74
+ test = package_registries_4_3.secure_repo_webhooks
75
+
76
+ secHookSSLVerify = Mock(url='https://example.com',
77
+ enable_ssl_verification=True)
78
+ secHookNoSSLVerify = Mock(url='https://example.com',
79
+ enable_ssl_verification=False)
80
+ unsecureHook = Mock(url='http://example.com',
81
+ enable_ssl_verification=False)
82
+
83
+ glEntity.hooks.list.return_value = []
84
+ run(glEntity, glObject, test, True)
85
+
86
+ glEntity.hooks.list.return_value = [
87
+ secHookSSLVerify]
88
+ run(glEntity, glObject, test, True)
89
+
90
+ glEntity.hooks.list.return_value = [
91
+ secHookNoSSLVerify]
92
+ run(glEntity, glObject, test, False)
93
+
94
+ glEntity.hooks.list.return_value = [
95
+ unsecureHook]
96
+ run(glEntity, glObject, test, False)
97
+
98
+ glEntity.hooks.list.side_effect = GitlabHttpError(response_code=403)
99
+ run(glEntity, glObject, test, None)
100
+
101
+ glEntity.hooks.list.side_effect = GitlabHttpError(response_code=418)
102
+ assert test(glEntity, glObject) is None
@@ -0,0 +1,78 @@
1
+ # -----------------------------------------------------------------------------
2
+
3
+ from unittest.mock import Mock, patch
4
+
5
+ import pytest # noqa: F401
6
+ from conftest import run
7
+
8
+ from gitlabcis.benchmarks.artifacts_4 import verification_4_1
9
+
10
+ # -----------------------------------------------------------------------------
11
+
12
+
13
+ @patch('zipfile.ZipFile')
14
+ def test_sign_artifacts_in_build_pipeline(mock_zipfile, glEntity, glObject):
15
+
16
+ from gitlab.exceptions import GitlabHttpError
17
+ test = verification_4_1.sign_artifacts_in_build_pipeline
18
+
19
+ glEntity.pipelines.list.return_value = []
20
+ run(glEntity, glObject, test, False)
21
+
22
+ mockPipeline = Mock()
23
+ mockJob = Mock()
24
+ mockJob.stage = 'test'
25
+ mockPipeline.jobs.list.return_value = [mockJob]
26
+ glEntity.pipelines.list.return_value = [mockPipeline]
27
+ run(glEntity, glObject, test, False)
28
+
29
+ mockJob.stage = 'build'
30
+ mockJob.id = 1
31
+ mockPipeline.jobs.list.return_value = [mockJob]
32
+ glEntity.pipelines.list.return_value = [mockPipeline]
33
+ glEntity.jobs.get.return_value.artifacts.return_value = b'fake_artifact'
34
+
35
+ mock_zipfile.return_value.__enter__.return_value.namelist.return_value \
36
+ = ['file1.txt', 'file2.txt']
37
+
38
+ run(glEntity, glObject, test, False)
39
+
40
+ mockPipeline = Mock()
41
+ mockJob = Mock()
42
+ mockJob.stage = 'build'
43
+ mockJob.id = 1
44
+ mockPipeline.jobs.list.return_value = [mockJob]
45
+ glEntity.pipelines.list.return_value = [mockPipeline]
46
+ glEntity.jobs.get.return_value.artifacts.return_value = b'fake_artifact'
47
+
48
+ mock_zipfile.return_value.__enter__.return_value.namelist.return_value \
49
+ = ['file1.txt', 'file1.sig', 'file2.txt', 'file2.sig']
50
+
51
+ run(glEntity, glObject, test, True)
52
+
53
+ glEntity.pipelines.list.side_effect \
54
+ = GitlabHttpError('', response_code=403)
55
+
56
+ run(glEntity, glObject, test, None)
57
+
58
+ glEntity.pipelines.list.side_effect = GitlabHttpError(response_code=418)
59
+ assert test(glEntity, glObject) is None # noqa: E501
60
+
61
+
62
+ # -----------------------------------------------------------------------------
63
+
64
+
65
+ def test_encrypt_artifacts_before_distribution(glEntity, glObject):
66
+
67
+ test = verification_4_1.encrypt_artifacts_before_distribution
68
+
69
+ run(glEntity, glObject, test, None)
70
+
71
+ # -----------------------------------------------------------------------------
72
+
73
+
74
+ def test_only_authorized_platforms_can_decrypt_artifacts(glEntity, glObject):
75
+
76
+ test = verification_4_1.only_authorized_platforms_can_decrypt_artifacts
77
+
78
+ run(glEntity, glObject, test, None)
@@ -0,0 +1,239 @@
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.build_pipelines_2 import build_environment_2_1
10
+
11
+ # -----------------------------------------------------------------------------
12
+
13
+
14
+ def test_single_responsibility_pipeline(glEntity, glObject):
15
+
16
+ test = build_environment_2_1.single_responsibility_pipeline
17
+
18
+ def setup_pipeline_jobs(*job_stages):
19
+ mock_pipeline = Mock()
20
+ mock_pipeline.jobs.list.return_value = [
21
+ Mock(stage=stage) for stage in job_stages]
22
+ glEntity.pipelines.list.return_value = [mock_pipeline]
23
+
24
+ glEntity.pipelines.list.return_value = []
25
+ run(glEntity, glObject, test, True)
26
+
27
+ setup_pipeline_jobs('test')
28
+ run(glEntity, glObject, test, None)
29
+
30
+ setup_pipeline_jobs('build')
31
+ run(glEntity, glObject, test, True)
32
+
33
+ setup_pipeline_jobs('build', 'build')
34
+ run(glEntity, glObject, test, False)
35
+
36
+ glEntity.pipelines.list.side_effect = GitlabHttpError(response_code=401)
37
+ run(glEntity, glObject, test, None)
38
+
39
+ glEntity.pipelines.list.side_effect = GitlabHttpError(response_code=418)
40
+ assert test(glEntity, glObject) is None
41
+
42
+ # -----------------------------------------------------------------------------
43
+
44
+
45
+ def test_immutable_pipeline_infrastructure(glEntity, glObject):
46
+
47
+ test = build_environment_2_1.immutable_pipeline_infrastructure
48
+
49
+ run(glEntity, glObject, test, None)
50
+
51
+ # -----------------------------------------------------------------------------
52
+
53
+
54
+ def test_build_logging(glEntity, glObject):
55
+
56
+ test = build_environment_2_1.build_logging
57
+
58
+ run(glEntity, glObject, test, None)
59
+
60
+ # -----------------------------------------------------------------------------
61
+
62
+
63
+ @patch('gitlabcis.utils.ci.getConfig')
64
+ def test_build_automation(mockGetConfig, glEntity, glObject):
65
+
66
+ test = build_environment_2_1.build_automation
67
+
68
+ mockGetConfig.return_value = {'gitlab-ci.yml': 'content'}
69
+ run(glEntity, glObject, test, True)
70
+
71
+ mockGetConfig.return_value = {None: 'No CI file found'}
72
+ run(glEntity, glObject, test, None)
73
+
74
+ mockGetConfig.return_value = {False: 'Invalid CI file'}
75
+ run(glEntity, glObject, test, False)
76
+
77
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=401)
78
+ run(glEntity, glObject, test, None)
79
+
80
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=418)
81
+ assert test(glEntity, glObject) is None
82
+
83
+ # -----------------------------------------------------------------------------
84
+
85
+
86
+ def test_limit_build_access(glEntity, glObject):
87
+
88
+ test = build_environment_2_1.limit_build_access
89
+
90
+ glEntity.members.list.return_value = [
91
+ Mock(access_level=40),
92
+ Mock(access_level=20),
93
+ Mock(access_level=10),
94
+ Mock(access_level=10),
95
+ Mock(access_level=10),
96
+ Mock(access_level=10)
97
+ ]
98
+ run(glEntity, glObject, test, True)
99
+
100
+ glEntity.members.list.return_value = [
101
+ Mock(access_level=40),
102
+ Mock(access_level=40),
103
+ Mock(access_level=40),
104
+ Mock(access_level=30),
105
+ Mock(access_level=20)
106
+ ]
107
+ run(glEntity, glObject, test, False)
108
+
109
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=403)
110
+ run(glEntity, glObject, test, None)
111
+
112
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=418)
113
+ assert test(glEntity, glObject) is None
114
+
115
+ # -----------------------------------------------------------------------------
116
+
117
+
118
+ def test_authenticate_build_access(glEntity, glObject):
119
+
120
+ test = build_environment_2_1.authenticate_build_access
121
+
122
+ glEntity.members.list.return_value = [
123
+ Mock(access_level=40),
124
+ Mock(access_level=20),
125
+ Mock(access_level=10),
126
+ Mock(access_level=10),
127
+ Mock(access_level=10),
128
+ Mock(access_level=10)
129
+ ]
130
+ run(glEntity, glObject, test, True)
131
+
132
+ glEntity.members.list.return_value = [
133
+ Mock(access_level=40),
134
+ Mock(access_level=40),
135
+ Mock(access_level=40),
136
+ Mock(access_level=30),
137
+ Mock(access_level=20)
138
+ ]
139
+ run(glEntity, glObject, test, False)
140
+
141
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=403)
142
+ run(glEntity, glObject, test, None)
143
+
144
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=418)
145
+ assert test(glEntity, glObject) is None
146
+
147
+ # -----------------------------------------------------------------------------
148
+
149
+
150
+ def test_limit_build_secrets_scope(glEntity, glObject):
151
+
152
+ test = build_environment_2_1.limit_build_secrets_scope
153
+
154
+ run(glEntity, glObject, test, None)
155
+
156
+ # -----------------------------------------------------------------------------
157
+
158
+
159
+ def test_vuln_scanning(glEntity, glObject):
160
+
161
+ test = build_environment_2_1.vuln_scanning
162
+
163
+ run(glEntity, glObject, test, None)
164
+
165
+ # -----------------------------------------------------------------------------
166
+
167
+
168
+ def test_disable_build_tools_default_passwords(glEntity, glObject):
169
+
170
+ test = build_environment_2_1.disable_build_tools_default_passwords
171
+
172
+ run(glEntity, glObject, test, None)
173
+
174
+ # -----------------------------------------------------------------------------
175
+
176
+
177
+ def test_secure_build_env_webhooks(glEntity, glObject):
178
+
179
+ test = build_environment_2_1.secure_build_env_webhooks
180
+
181
+ secHookSSLVerify = Mock(url='https://example.com',
182
+ enable_ssl_verification=True)
183
+ secHookNoSSLVerify = Mock(url='https://example.com',
184
+ enable_ssl_verification=False)
185
+ unsecureHook = Mock(url='http://example.com',
186
+ enable_ssl_verification=False)
187
+
188
+ glEntity.hooks.list.return_value = []
189
+ run(glEntity, glObject, test, True)
190
+
191
+ glEntity.hooks.list.return_value = [
192
+ secHookSSLVerify]
193
+ run(glEntity, glObject, test, True)
194
+
195
+ glEntity.hooks.list.return_value = [
196
+ secHookNoSSLVerify]
197
+ run(glEntity, glObject, test, False)
198
+
199
+ glEntity.hooks.list.return_value = [
200
+ unsecureHook]
201
+ run(glEntity, glObject, test, False)
202
+
203
+ glEntity.hooks.list.side_effect = GitlabHttpError(response_code=403)
204
+ run(glEntity, glObject, test, None)
205
+
206
+ glEntity.hooks.list.side_effect = GitlabHttpError(response_code=418)
207
+ assert test(glEntity, glObject) is None
208
+
209
+ # -----------------------------------------------------------------------------
210
+
211
+
212
+ def test_build_env_admins(glEntity, glObject):
213
+
214
+ test = build_environment_2_1.build_env_admins
215
+
216
+ glEntity.members.list.return_value = [
217
+ Mock(access_level=40),
218
+ Mock(access_level=20),
219
+ Mock(access_level=10),
220
+ Mock(access_level=10),
221
+ Mock(access_level=10),
222
+ Mock(access_level=10)
223
+ ]
224
+ run(glEntity, glObject, test, True)
225
+
226
+ glEntity.members.list.return_value = [
227
+ Mock(access_level=40),
228
+ Mock(access_level=40),
229
+ Mock(access_level=40),
230
+ Mock(access_level=30),
231
+ Mock(access_level=20)
232
+ ]
233
+ run(glEntity, glObject, test, False)
234
+
235
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=403)
236
+ run(glEntity, glObject, test, None)
237
+
238
+ glEntity.members.list.side_effect = GitlabHttpError(response_code=418)
239
+ assert test(glEntity, glObject) is None
@@ -0,0 +1,105 @@
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.build_pipelines_2 import build_worker_2_2
10
+
11
+ # -----------------------------------------------------------------------------
12
+
13
+
14
+ def test_single_use_workers(glEntity, glObject):
15
+
16
+ test = build_worker_2_2.single_use_workers
17
+
18
+ run(glEntity, glObject, test, None)
19
+
20
+ # -----------------------------------------------------------------------------
21
+
22
+
23
+ def test_pass_worker_envs_and_commands(glEntity, glObject):
24
+
25
+ test = build_worker_2_2.pass_worker_envs_and_commands
26
+
27
+ run(glEntity, glObject, test, None)
28
+
29
+ # -----------------------------------------------------------------------------
30
+
31
+
32
+ def test_segregate_worker_duties(glEntity, glObject):
33
+
34
+ test = build_worker_2_2.segregate_worker_duties
35
+
36
+ glEntity.runners.list.return_value = [Mock(is_shared=False)]
37
+ run(glEntity, glObject, test, True)
38
+
39
+ glEntity.runners.list.return_value = [Mock(is_shared=True)]
40
+ run(glEntity, glObject, test, False)
41
+
42
+ glEntity.runners.list.side_effect = GitlabHttpError(response_code=401)
43
+ run(glEntity, glObject, test, None)
44
+
45
+ glEntity.runners.list.side_effect = GitlabHttpError(response_code=418)
46
+ assert test(glEntity, glObject) is None
47
+
48
+ # -----------------------------------------------------------------------------
49
+
50
+
51
+ def test_restrict_worker_connectivity(glEntity, glObject):
52
+
53
+ test = build_worker_2_2.restrict_worker_connectivity
54
+
55
+ run(glEntity, glObject, test, None)
56
+
57
+ # -----------------------------------------------------------------------------
58
+
59
+
60
+ def test_worker_runtime_security(glEntity, glObject):
61
+
62
+ test = build_worker_2_2.worker_runtime_security
63
+
64
+ run(glEntity, glObject, test, None)
65
+
66
+ # -----------------------------------------------------------------------------
67
+
68
+
69
+ def test_build_worker_vuln_scanning(glEntity, glObject):
70
+
71
+ test = build_worker_2_2.build_worker_vuln_scanning
72
+
73
+ run(glEntity, glObject, test, None)
74
+
75
+ # -----------------------------------------------------------------------------
76
+
77
+
78
+ @patch('gitlabcis.utils.ci.getConfig')
79
+ def test_store_worker_config(mockGetConfig, glEntity, glObject):
80
+
81
+ test = build_worker_2_2.store_worker_config
82
+
83
+ mockGetConfig.return_value = {'gitlab-ci.yml': 'content'}
84
+ run(glEntity, glObject, test, True)
85
+
86
+ mockGetConfig.return_value = {None: 'No CI file found'}
87
+ run(glEntity, glObject, test, None)
88
+
89
+ mockGetConfig.return_value = {False: 'Invalid CI file'}
90
+ run(glEntity, glObject, test, False)
91
+
92
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=401)
93
+ run(glEntity, glObject, test, None)
94
+
95
+ mockGetConfig.side_effect = GitlabHttpError('Error', response_code=418)
96
+ assert test(glEntity, glObject) is None
97
+
98
+ # -----------------------------------------------------------------------------
99
+
100
+
101
+ def test_monitor_worker_resource_consumption(glEntity, glObject):
102
+
103
+ test = build_worker_2_2.monitor_worker_resource_consumption
104
+
105
+ run(glEntity, glObject, test, None)