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.
- gitlabcis/__init__.py +12 -0
- gitlabcis/__main__.py +7 -0
- gitlabcis/benchmarks/__init__.py +8 -0
- gitlabcis/benchmarks/artifacts_4/__init__.py +4 -0
- gitlabcis/benchmarks/artifacts_4/access_to_artifacts_4_2.py +139 -0
- gitlabcis/benchmarks/artifacts_4/origin_traceability_4_4.py +11 -0
- gitlabcis/benchmarks/artifacts_4/package_registries_4_3.py +105 -0
- gitlabcis/benchmarks/artifacts_4/verification_4_1.py +83 -0
- gitlabcis/benchmarks/build_pipelines_2/__init__.py +4 -0
- gitlabcis/benchmarks/build_pipelines_2/build_environment_2_1.py +268 -0
- gitlabcis/benchmarks/build_pipelines_2/build_worker_2_2.py +129 -0
- gitlabcis/benchmarks/build_pipelines_2/pipeline_instructions_2_3.py +444 -0
- gitlabcis/benchmarks/build_pipelines_2/pipeline_integrity_2_4.py +146 -0
- gitlabcis/benchmarks/dependencies_3/__init__.py +2 -0
- gitlabcis/benchmarks/dependencies_3/third_party_packages_3_1.py +171 -0
- gitlabcis/benchmarks/dependencies_3/validate_packages_3_2.py +182 -0
- gitlabcis/benchmarks/deployment_5/__init__.py +2 -0
- gitlabcis/benchmarks/deployment_5/deployment_configuration_5_1.py +165 -0
- gitlabcis/benchmarks/deployment_5/deployment_environment_5_2.py +66 -0
- gitlabcis/benchmarks/source_code_1/__init__.py +6 -0
- gitlabcis/benchmarks/source_code_1/code_changes_1_1.py +665 -0
- gitlabcis/benchmarks/source_code_1/code_risks_1_5.py +506 -0
- gitlabcis/benchmarks/source_code_1/contribution_access_1_3.py +334 -0
- gitlabcis/benchmarks/source_code_1/repository_management_1_2.py +168 -0
- gitlabcis/benchmarks/source_code_1/third_party_1_4.py +139 -0
- gitlabcis/cli/__init__.py +0 -0
- gitlabcis/cli/log.py +30 -0
- gitlabcis/cli/main.py +541 -0
- gitlabcis/cli/output.py +151 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/external_auth_server.yml +51 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/limit_artifact_uploaders.yml +57 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/limit_certifying_artifacts.yml +53 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/minimum_package_registry_admins.yml +54 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/readme.md +14 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/require_mfa_to_package_registry.yml +52 -0
- gitlabcis/recommendations/artifacts_4/access_to_artifacts_4_2/restrict_anonymous_access.yml +67 -0
- gitlabcis/recommendations/artifacts_4/origin_traceability_4_4/artifact_origin_info.yml +56 -0
- gitlabcis/recommendations/artifacts_4/origin_traceability_4_4/readme.md +7 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/all_artifact_versions_signed.yml +70 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/audit_package_registry_config.yml +46 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/readme.md +12 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/secure_repo_webhooks.yml +50 -0
- gitlabcis/recommendations/artifacts_4/package_registries_4_3/validate_signed_artifacts_on_upload.yml +72 -0
- gitlabcis/recommendations/artifacts_4/readme.md +12 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/encrypt_artifacts_before_distribution.yml +47 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/only_authorized_platforms_can_decrypt_artifacts.yml +59 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/readme.md +11 -0
- gitlabcis/recommendations/artifacts_4/verification_4_1/sign_artifacts_in_build_pipeline.yml +40 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/authenticate_build_access.yml +55 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_automation.yml +54 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_env_admins.yml +55 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/build_logging.yml +49 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/disable_build_tools_default_passwords.yml +54 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/immutable_pipeline_infrastructure.yml +60 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/limit_build_access.yml +64 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/limit_build_secrets_scope.yml +56 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/readme.md +19 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/secure_build_env_webhooks.yml +43 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/single_responsibility_pipeline.yml +58 -0
- gitlabcis/recommendations/build_pipelines_2/build_environment_2_1/vuln_scanning.yml +64 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/build_worker_vuln_scanning.yml +58 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/monitor_worker_resource_consumption.yml +59 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/pass_worker_envs_and_commands.yml +48 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/readme.md +16 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/restrict_worker_connectivity.yml +61 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/segregate_worker_duties.yml +78 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/single_use_workers.yml +47 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/store_worker_config.yml +62 -0
- gitlabcis/recommendations/build_pipelines_2/build_worker_2_2/worker_runtime_security.yml +37 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/build_stage_io.yml +49 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/build_steps_as_code.yml +42 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/limit_pipeline_triggers.yml +76 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_misconfiguration_scanning.yml +48 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_secret_scanning.yml +56 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/pipeline_vuln_scanning.yml +44 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/readme.md +16 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/secure_pipeline_output.yml +52 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_instructions_2_3/track_pipeline_files.yml +48 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/create_reproducible_artifacts.yml +52 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/lock_dependencies.yml +59 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/pipeline_produces_sbom.yml +81 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/pipeline_signs_sbom.yml +38 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/readme.md +14 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/sign_artifacts.yml +35 -0
- gitlabcis/recommendations/build_pipelines_2/pipeline_integrity_2_4/validate_dependencies.yml +63 -0
- gitlabcis/recommendations/build_pipelines_2/readme.md +12 -0
- gitlabcis/recommendations/dependencies_3/readme.md +10 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/define_package_managers.yml +84 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/dependency_sbom.yml +84 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/monitor_dependencies.yml +61 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/packages_over_60_days_old.yml +95 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/pin_dependency_version.yml +48 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/readme.md +14 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/third_party_sbom_required.yml +70 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/verify_artifacts.yml +45 -0
- gitlabcis/recommendations/dependencies_3/third_party_packages_3_1/verify_signed_metadata.yml +41 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/org_wide_dependency_policy.yml +47 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_license_scanning.yml +47 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_ownership_change.yml +42 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/package_vuln_scanning.yml +62 -0
- gitlabcis/recommendations/dependencies_3/validate_packages_3_2/readme.md +10 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/audit_deployment_config.yml +46 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/limit_deployment_config_access.yml +51 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/pin_deployment_config_manifests.yml +59 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/readme.md +13 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/scan_iac.yml +72 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/secret_scan_deployment_config.yml +45 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/separate_deployment_config.yml +50 -0
- gitlabcis/recommendations/deployment_5/deployment_configuration_5_1/verify_deployment_config.yml +49 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/automate_deployment.yml +47 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/disable_default_passwords.yml +63 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/limit_prod_access.yml +45 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/readme.md +12 -0
- gitlabcis/recommendations/deployment_5/deployment_environment_5_2/reproducible_deployment.yml +50 -0
- gitlabcis/recommendations/deployment_5/readme.md +10 -0
- gitlabcis/recommendations/readme.md +24 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/audit_branch_protections.yml +56 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/auto_risk_scan_merges.yml +62 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/branch_protections_for_admins.yml +60 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/branches_updated_before_merging.yml +56 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/checks_pass_before_merging.yml +57 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_approval_dismissals.yml +62 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_approvals.yml +65 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_changes_require_code_owners.yml +68 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_dismissal_restrictions.yml +69 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_owners.yml +61 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/code_tracing.yml +52 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/comments_resolved_before_merging.yml +59 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/commits_must_be_signed_before_merging.yml +63 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/default_branch_protected.yml +85 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/deny_branch_deletions.yml +76 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/ensure_force_push_is_denied.yml +59 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/linear_history_required.yml +56 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/merging_restrictions.yml +65 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/readme.md +26 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/stale_branch_reviews.yml +72 -0
- gitlabcis/recommendations/source_code_1/code_changes_1_1/version_control.yml +45 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/dast_api_scanning.yml +50 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/dast_web_scanning.yml +51 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/dependency_scanning.yml +84 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/enable_secret_detection.yml +45 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/license_scanning.yml +47 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/readme.md +14 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/secure_iac_instructions.yml +81 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/secure_pipeline_instructions.yml +62 -0
- gitlabcis/recommendations/source_code_1/code_risks_1_5/vulnerability_scanning.yml +48 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/domain_verification.yml +65 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/ensure_2_admins_per_repo.yml +56 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/limit_top_level_group_creation.yml +61 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/limit_user_registration_domain.yml +58 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/minimum_number_of_admins.yml +56 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/org_provided_ssh_certs.yml +70 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/readme.md +21 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/require_mfa_at_org_level.yml +89 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/require_mfa_for_contributors.yml +76 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/restrict_ip_addresses.yml +84 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/review_and_remove_inactive_users.yml +62 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/scm_notification_restriction.yml +46 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/strict_permissions_for_repo.yml +62 -0
- gitlabcis/recommendations/source_code_1/contribution_access_1_3/track_code_anomalies.yml +43 -0
- gitlabcis/recommendations/source_code_1/readme.md +13 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_issue_deletions.yml +57 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_repo_creations.yml +64 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/limit_repo_deletions.yml +57 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/public_repos_have_security_file.yml +59 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/readme.md +15 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/review_and_archive_stale_repos.yml +65 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/track_forks.yml +74 -0
- gitlabcis/recommendations/source_code_1/repository_management_1_2/track_project_visibility_status.yml +74 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/README.md +12 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/admin_approval_for_app_installs.yml +83 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/least_privilge_app_permissions.yml +103 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/secure_webhooks.yml +73 -0
- gitlabcis/recommendations/source_code_1/third_party_1_4/stale_app_reviews.yml +66 -0
- gitlabcis/recommendations/template.yml +30 -0
- gitlabcis/tests/__init__.py +0 -0
- gitlabcis/tests/input/__init__.py +0 -0
- gitlabcis/tests/input/conftest.py +29 -0
- gitlabcis/tests/input/no_input_test.py +82 -0
- gitlabcis/tests/input/switch_test.py +19 -0
- gitlabcis/tests/input/version_test.py +7 -0
- gitlabcis/tests/unit/__init__.py +0 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/access_to_artifacts_4_2_test.py +131 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/origin_traceability_4_4_test.py +15 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/package_registries_4_3_test.py +102 -0
- gitlabcis/tests/unit/benchmarks/artifacts_4/verification_4_1_test.py +78 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/build_environment_2_1_test.py +239 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/build_worker_2_2_test.py +105 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/pipeline_instructions_2_3_test.py +340 -0
- gitlabcis/tests/unit/benchmarks/build_pipelines_2/pipeline_integrity_2_4_test.py +115 -0
- gitlabcis/tests/unit/benchmarks/conftest.py +47 -0
- gitlabcis/tests/unit/benchmarks/dependencies_3/third_party_packages_3_1_test.py +135 -0
- gitlabcis/tests/unit/benchmarks/dependencies_3/validate_packages_3_2_test.py +171 -0
- gitlabcis/tests/unit/benchmarks/deployment_5/deployment_configuration_5_1_test.py +140 -0
- gitlabcis/tests/unit/benchmarks/deployment_5/deployment_environment_5_2_test.py +60 -0
- gitlabcis/tests/unit/benchmarks/function_test.py +24 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/code_changes_1_1_test.py +565 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/code_risks_1_5_test.py +419 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/contribution_access_1_3_test.py +265 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/repository_management_1_2_test.py +142 -0
- gitlabcis/tests/unit/benchmarks/source_code_1/third_party_1_4_test.py +119 -0
- gitlabcis/tests/unit/conftest.py +94 -0
- gitlabcis/tests/unit/log/log_test.py +23 -0
- gitlabcis/tests/unit/utils/argfilters_test.py +9 -0
- gitlabcis/tests/unit/utils/ci_test.py +156 -0
- gitlabcis/tests/unit/utils/output_test.py +95 -0
- gitlabcis/tests/unit/utils/utils_general_test.py +149 -0
- gitlabcis/tests/unit/utils/version_test.py +11 -0
- gitlabcis/tests/unit/yaml/bad_file_test.py +15 -0
- gitlabcis/tests/unit/yaml/recommendation_test.py +123 -0
- gitlabcis/utils/__init__.py +146 -0
- gitlabcis/utils/ci.py +132 -0
- gitlabcis-1.3.2.dist-info/LICENSE +21 -0
- gitlabcis-1.3.2.dist-info/METADATA +241 -0
- gitlabcis-1.3.2.dist-info/RECORD +218 -0
- gitlabcis-1.3.2.dist-info/WHEEL +5 -0
- gitlabcis-1.3.2.dist-info/entry_points.txt +2 -0
- gitlabcis-1.3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
from unittest.mock import Mock
|
|
4
|
+
|
|
5
|
+
from conftest import run
|
|
6
|
+
|
|
7
|
+
from gitlabcis.benchmarks.source_code_1 import code_changes_1_1
|
|
8
|
+
|
|
9
|
+
# -----------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_version_control(glEntity, glObject):
|
|
13
|
+
|
|
14
|
+
test = code_changes_1_1.version_control
|
|
15
|
+
|
|
16
|
+
run(None, glObject, test, False)
|
|
17
|
+
run(glEntity, glObject, test, True)
|
|
18
|
+
|
|
19
|
+
# -----------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_code_tracing(glEntity, glObject):
|
|
23
|
+
from gitlab.exceptions import GitlabHttpError
|
|
24
|
+
|
|
25
|
+
test = code_changes_1_1.code_tracing
|
|
26
|
+
|
|
27
|
+
glEntity.issues.list.return_value = []
|
|
28
|
+
run(glEntity, glObject, test, False)
|
|
29
|
+
|
|
30
|
+
glEntity.issues.list.return_value = [Mock()]
|
|
31
|
+
run(glEntity, glObject, test, True)
|
|
32
|
+
|
|
33
|
+
glEntity.issues.list.side_effect = GitlabHttpError(
|
|
34
|
+
response_code=401)
|
|
35
|
+
run(glEntity, glObject, test, None)
|
|
36
|
+
|
|
37
|
+
glEntity.issues.list.side_effect = GitlabHttpError(
|
|
38
|
+
'Error', response_code=418)
|
|
39
|
+
assert test(glEntity, glObject) is None
|
|
40
|
+
|
|
41
|
+
# -----------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_code_approvals(glEntity, glObject):
|
|
45
|
+
from gitlab.exceptions import GitlabHttpError
|
|
46
|
+
|
|
47
|
+
test = code_changes_1_1.code_approvals
|
|
48
|
+
|
|
49
|
+
approvalRule = Mock()
|
|
50
|
+
approvalRule.approvals_required = 2
|
|
51
|
+
glEntity.approvalrules.list.return_value = [approvalRule]
|
|
52
|
+
run(glEntity, glObject, test, True)
|
|
53
|
+
|
|
54
|
+
approvalRule.approvals_required = 1
|
|
55
|
+
glEntity.approvalrules.list.return_value = [approvalRule]
|
|
56
|
+
run(glEntity, glObject, test, False)
|
|
57
|
+
|
|
58
|
+
glEntity.approvalrules.list.side_effect = GitlabHttpError(
|
|
59
|
+
response_code=401)
|
|
60
|
+
run(glEntity, glObject, test, None)
|
|
61
|
+
|
|
62
|
+
glEntity.approvalrules.list.side_effect = GitlabHttpError(
|
|
63
|
+
'Error', response_code=418)
|
|
64
|
+
assert test(glEntity, glObject) is None
|
|
65
|
+
|
|
66
|
+
# -----------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_code_approval_dismissals(glEntity, glObject):
|
|
70
|
+
from gitlab.exceptions import GitlabHttpError
|
|
71
|
+
|
|
72
|
+
test = code_changes_1_1.code_approval_dismissals
|
|
73
|
+
|
|
74
|
+
mrApprovalSettings = Mock()
|
|
75
|
+
mrApprovalSettings.reset_approvals_on_push = True
|
|
76
|
+
glEntity.approvals.get.return_value = mrApprovalSettings
|
|
77
|
+
run(glEntity, glObject, test, True)
|
|
78
|
+
|
|
79
|
+
mrApprovalSettings.reset_approvals_on_push = False
|
|
80
|
+
glEntity.approvals.get.return_value = mrApprovalSettings
|
|
81
|
+
run(glEntity, glObject, test, False)
|
|
82
|
+
|
|
83
|
+
glEntity.approvals.get.side_effect = GitlabHttpError(
|
|
84
|
+
response_code=401)
|
|
85
|
+
run(glEntity, glObject, test, None)
|
|
86
|
+
|
|
87
|
+
glEntity.approvals.get.side_effect = GitlabHttpError(
|
|
88
|
+
'Error', response_code=418)
|
|
89
|
+
assert test(glEntity, glObject) is None
|
|
90
|
+
|
|
91
|
+
# -----------------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_code_dismissal_restrictions(glEntity, glObject):
|
|
95
|
+
from gitlab.exceptions import GitlabHttpError
|
|
96
|
+
|
|
97
|
+
test = code_changes_1_1.code_dismissal_restrictions
|
|
98
|
+
|
|
99
|
+
protectedBranches = Mock()
|
|
100
|
+
|
|
101
|
+
branch = Mock()
|
|
102
|
+
branch.merge_access_levels = [
|
|
103
|
+
{"access_level_description": "Maintainers"},
|
|
104
|
+
{"access_level_description": "Developers"}
|
|
105
|
+
]
|
|
106
|
+
branch.push_access_levels = [
|
|
107
|
+
{"access_level_description": "Maintainers"}
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
protectedBranches.list.return_value = [branch]
|
|
111
|
+
glEntity.protectedbranches = protectedBranches
|
|
112
|
+
run(glEntity, glObject, test, True)
|
|
113
|
+
|
|
114
|
+
branch.merge_access_levels = [
|
|
115
|
+
{"access_level_description": "Maintainers"},
|
|
116
|
+
# {"access_level_description": "Developers"}
|
|
117
|
+
]
|
|
118
|
+
branch.push_access_levels = [
|
|
119
|
+
{"access_level_description": "Maintainers"}
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
protectedBranches.list.return_value = [branch]
|
|
123
|
+
glEntity.protectedbranches = protectedBranches
|
|
124
|
+
run(glEntity, glObject, test, False)
|
|
125
|
+
|
|
126
|
+
branch.merge_access_levels = []
|
|
127
|
+
branch.push_access_levels = []
|
|
128
|
+
|
|
129
|
+
protectedBranches.list.return_value = [branch]
|
|
130
|
+
glEntity.protectedbranches = protectedBranches
|
|
131
|
+
run(glEntity, glObject, test, False)
|
|
132
|
+
|
|
133
|
+
protectedBranches.list.return_value = []
|
|
134
|
+
glEntity.protectedbranches.list.side_effect = GitlabHttpError(
|
|
135
|
+
response_code=401)
|
|
136
|
+
run(glEntity, glObject, test, None)
|
|
137
|
+
|
|
138
|
+
glEntity.protectedbranches.list.side_effect = GitlabHttpError(
|
|
139
|
+
'Error', response_code=418)
|
|
140
|
+
assert test(glEntity, glObject) is None
|
|
141
|
+
|
|
142
|
+
# -----------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_code_owners(glEntity, glObject):
|
|
146
|
+
from gitlab.exceptions import GitlabGetError, GitlabHttpError
|
|
147
|
+
|
|
148
|
+
test = code_changes_1_1.code_owners
|
|
149
|
+
|
|
150
|
+
_files = Mock()
|
|
151
|
+
_files = [{
|
|
152
|
+
'name': 'CODEOWNERS'
|
|
153
|
+
}]
|
|
154
|
+
glEntity.repository_tree.return_value = _files
|
|
155
|
+
run(glEntity, glObject, test, True)
|
|
156
|
+
|
|
157
|
+
_files = [{
|
|
158
|
+
'name': 'notfound'
|
|
159
|
+
}]
|
|
160
|
+
glEntity.repository_tree.return_value = _files
|
|
161
|
+
run(glEntity, glObject, test, False)
|
|
162
|
+
|
|
163
|
+
glEntity.repository_tree.side_effect = GitlabHttpError(
|
|
164
|
+
response_code=401)
|
|
165
|
+
run(glEntity, glObject, test, None)
|
|
166
|
+
|
|
167
|
+
glEntity.repository_tree.side_effect = GitlabGetError(
|
|
168
|
+
response_code=404)
|
|
169
|
+
run(glEntity, glObject, test, False)
|
|
170
|
+
|
|
171
|
+
glEntity.repository_tree.side_effect = GitlabGetError(
|
|
172
|
+
response_code=418)
|
|
173
|
+
run(glEntity, glObject, test, None)
|
|
174
|
+
|
|
175
|
+
glEntity.repository_tree.side_effect = GitlabHttpError(
|
|
176
|
+
'Error', response_code=418)
|
|
177
|
+
assert test(glEntity, glObject) == {None: 'Unknown error'}
|
|
178
|
+
|
|
179
|
+
# -----------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_code_changes_require_code_owners(glEntity, glObject):
|
|
183
|
+
from gitlab.exceptions import GitlabHttpError
|
|
184
|
+
|
|
185
|
+
test = code_changes_1_1.code_changes_require_code_owners
|
|
186
|
+
|
|
187
|
+
defaultBranch = Mock()
|
|
188
|
+
defaultBranch.code_owner_approval_required = True
|
|
189
|
+
glEntity.default_branch = defaultBranch
|
|
190
|
+
glEntity.protectedbranches.get.return_value = defaultBranch
|
|
191
|
+
run(glEntity, glObject, test, True)
|
|
192
|
+
|
|
193
|
+
glEntity.protectedbranches.get.return_value = None
|
|
194
|
+
run(glEntity, glObject, test, False)
|
|
195
|
+
|
|
196
|
+
defaultBranch.code_owner_approval_required = False
|
|
197
|
+
glEntity.default_branch = defaultBranch
|
|
198
|
+
glEntity.protectedbranches.get.return_value = defaultBranch
|
|
199
|
+
run(glEntity, glObject, test, False)
|
|
200
|
+
|
|
201
|
+
glEntity.protectedbranches.get.side_effect = GitlabHttpError(
|
|
202
|
+
response_code=403, error_message='403 Forbidden')
|
|
203
|
+
run(glEntity, glObject, test, None)
|
|
204
|
+
|
|
205
|
+
glEntity.protectedbranches.get.side_effect = GitlabHttpError(
|
|
206
|
+
response_code=404)
|
|
207
|
+
run(glEntity, glObject, test, False)
|
|
208
|
+
|
|
209
|
+
glEntity.protectedbranches.get.side_effect = GitlabHttpError(
|
|
210
|
+
'Error', response_code=418)
|
|
211
|
+
assert test(glEntity, glObject) is None
|
|
212
|
+
|
|
213
|
+
# -----------------------------------------------------------------------------
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_stale_branch_reviews(glEntity, glObject):
|
|
217
|
+
from datetime import datetime, timezone
|
|
218
|
+
|
|
219
|
+
from dateutil.relativedelta import relativedelta
|
|
220
|
+
from gitlab.exceptions import GitlabHttpError
|
|
221
|
+
|
|
222
|
+
test = code_changes_1_1.stale_branch_reviews
|
|
223
|
+
|
|
224
|
+
branch = Mock()
|
|
225
|
+
now = datetime.now(timezone.utc)
|
|
226
|
+
nowts = f"{now.strftime('%Y-%m-%dT%H:%M:%S.%f%z')}"
|
|
227
|
+
branch.commit = {"committed_date": nowts}
|
|
228
|
+
branch.name = 'not-stale'
|
|
229
|
+
glEntity.branches.list.return_value = [branch]
|
|
230
|
+
run(glEntity, glObject, test, True)
|
|
231
|
+
|
|
232
|
+
thendt = now - relativedelta(months=5)
|
|
233
|
+
branch.commit = {
|
|
234
|
+
'committed_date': thendt.strftime('%Y-%m-%dT%H:%M:%S.%f%z')}
|
|
235
|
+
branch.name = 'stale'
|
|
236
|
+
glEntity.branches.list.return_value = [branch]
|
|
237
|
+
run(glEntity, glObject, test, False)
|
|
238
|
+
|
|
239
|
+
glEntity.branches.list.side_effect = GitlabHttpError(
|
|
240
|
+
response_code=401)
|
|
241
|
+
run(glEntity, glObject, test, None)
|
|
242
|
+
|
|
243
|
+
glEntity.branches.list.side_effect = GitlabHttpError(
|
|
244
|
+
'Error', response_code=418)
|
|
245
|
+
assert test(glEntity, glObject) is None
|
|
246
|
+
|
|
247
|
+
# -----------------------------------------------------------------------------
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def test_checks_pass_before_merging(glEntity, glObject):
|
|
251
|
+
# from gitlab.exceptions import GitlabGetError
|
|
252
|
+
|
|
253
|
+
test = code_changes_1_1.checks_pass_before_merging
|
|
254
|
+
|
|
255
|
+
glEntity.only_allow_merge_if_all_status_checks_passed = True
|
|
256
|
+
run(glEntity, glObject, test, True)
|
|
257
|
+
|
|
258
|
+
glEntity.only_allow_merge_if_all_status_checks_passed = False
|
|
259
|
+
run(glEntity, glObject, test, False)
|
|
260
|
+
|
|
261
|
+
# -----------------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def test_branches_updated_before_merging(glEntity, glObject):
|
|
265
|
+
# from gitlab.exceptions import GitlabGetError
|
|
266
|
+
|
|
267
|
+
test = code_changes_1_1.branches_updated_before_merging
|
|
268
|
+
|
|
269
|
+
# unauthorised.merge_method.side_effect = GitlabGetError(response_code=401)
|
|
270
|
+
# run(unauthorised, glObject, test, None)
|
|
271
|
+
|
|
272
|
+
del glEntity.merge_method
|
|
273
|
+
run(glEntity, glObject, test, None)
|
|
274
|
+
|
|
275
|
+
glEntity.merge_method = 'ff'
|
|
276
|
+
run(glEntity, glObject, test, True)
|
|
277
|
+
|
|
278
|
+
glEntity.merge_method = 'no'
|
|
279
|
+
run(glEntity, glObject, test, False)
|
|
280
|
+
|
|
281
|
+
# -----------------------------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def test_comments_resolved_before_merging(glEntity, glObject):
|
|
285
|
+
|
|
286
|
+
test = code_changes_1_1.comments_resolved_before_merging
|
|
287
|
+
|
|
288
|
+
del glEntity.only_allow_merge_if_all_discussions_are_resolved
|
|
289
|
+
run(glEntity, glObject, test, None)
|
|
290
|
+
|
|
291
|
+
glEntity.only_allow_merge_if_all_discussions_are_resolved = True
|
|
292
|
+
run(glEntity, glObject, test, True)
|
|
293
|
+
|
|
294
|
+
glEntity.only_allow_merge_if_all_discussions_are_resolved = False
|
|
295
|
+
run(glEntity, glObject, test, False)
|
|
296
|
+
|
|
297
|
+
# -----------------------------------------------------------------------------
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def test_commits_must_be_signed_before_merging(glEntity, glObject):
|
|
301
|
+
|
|
302
|
+
test = code_changes_1_1.commits_must_be_signed_before_merging
|
|
303
|
+
|
|
304
|
+
push = Mock()
|
|
305
|
+
push.reject_unsigned_commits = True
|
|
306
|
+
glEntity.pushrules.get.return_value = push
|
|
307
|
+
run(glEntity, glObject, test, True)
|
|
308
|
+
|
|
309
|
+
push.reject_unsigned_commits = False
|
|
310
|
+
glEntity.pushrules.get.return_value = push
|
|
311
|
+
run(glEntity, glObject, test, False)
|
|
312
|
+
|
|
313
|
+
# -----------------------------------------------------------------------------
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def test_linear_history_required(glEntity, glObject):
|
|
317
|
+
from gitlab.exceptions import GitlabGetError
|
|
318
|
+
|
|
319
|
+
test = code_changes_1_1.linear_history_required
|
|
320
|
+
|
|
321
|
+
glEntity.merge_method = 'dont-merge'
|
|
322
|
+
run(glEntity, glObject, test, True)
|
|
323
|
+
|
|
324
|
+
glEntity.merge_method = 'merge'
|
|
325
|
+
run(glEntity, glObject, test, False)
|
|
326
|
+
|
|
327
|
+
mergeFail = Mock()
|
|
328
|
+
del mergeFail.merge_method
|
|
329
|
+
mergeFail.side_effect = GitlabGetError(
|
|
330
|
+
response_code=401)
|
|
331
|
+
run(mergeFail, glObject, test, None)
|
|
332
|
+
|
|
333
|
+
mergeNone = Mock()
|
|
334
|
+
del mergeNone.merge_method
|
|
335
|
+
mergeNone.side_effect = AttributeError()
|
|
336
|
+
run(mergeNone, glObject, test, None)
|
|
337
|
+
|
|
338
|
+
# -----------------------------------------------------------------------------
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def test_branch_protections_for_admins(glEntity, glObject, unauthorised):
|
|
342
|
+
from gitlab.exceptions import GitlabGetError
|
|
343
|
+
|
|
344
|
+
test = code_changes_1_1.branch_protections_for_admins
|
|
345
|
+
|
|
346
|
+
settings = Mock()
|
|
347
|
+
settings.group_owners_can_manage_default_branch_protection = False
|
|
348
|
+
glObject.settings.get.return_value = settings
|
|
349
|
+
run(glEntity, glObject, test, True)
|
|
350
|
+
|
|
351
|
+
settings.group_owners_can_manage_default_branch_protection = True
|
|
352
|
+
glObject.settings.get.return_value = settings
|
|
353
|
+
run(glEntity, glObject, test, False)
|
|
354
|
+
|
|
355
|
+
unauthorised.group_owners_can_manage_default_branch_protection.side_effect\
|
|
356
|
+
= GitlabGetError(response_code=401)
|
|
357
|
+
unauthorised.settings.get.side_effect = GitlabGetError(response_code=401)
|
|
358
|
+
run(glEntity, unauthorised, test, None)
|
|
359
|
+
|
|
360
|
+
unauthorised.group_owners_can_manage_default_branch_protection.side_effect\
|
|
361
|
+
= GitlabGetError(response_code=418)
|
|
362
|
+
unauthorised.settings.get.side_effect = GitlabGetError(response_code=418)
|
|
363
|
+
assert test(glEntity, unauthorised) is None
|
|
364
|
+
|
|
365
|
+
# -----------------------------------------------------------------------------
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def test_merging_restrictions(glEntity, glObject, unauthorised):
|
|
369
|
+
from gitlab.exceptions import GitlabGetError
|
|
370
|
+
|
|
371
|
+
test = code_changes_1_1.merging_restrictions
|
|
372
|
+
|
|
373
|
+
glEntity.protectedbranches.list.return_value = []
|
|
374
|
+
run(glEntity, glObject, test, False)
|
|
375
|
+
|
|
376
|
+
branch = Mock()
|
|
377
|
+
branch.allow_force_push = True
|
|
378
|
+
protectedBranches = [branch]
|
|
379
|
+
glEntity.protectedbranches.list.return_value = protectedBranches
|
|
380
|
+
run(glEntity, glObject, test, False)
|
|
381
|
+
|
|
382
|
+
branch.allow_force_push = False
|
|
383
|
+
protectedBranches = [branch]
|
|
384
|
+
glEntity.protectedbranches.list.return_value = protectedBranches
|
|
385
|
+
run(glEntity, glObject, test, True)
|
|
386
|
+
|
|
387
|
+
unauthorised.protectedbranches.list.side_effect \
|
|
388
|
+
= GitlabGetError(response_code=401)
|
|
389
|
+
run(unauthorised, glObject, test, None)
|
|
390
|
+
|
|
391
|
+
# -----------------------------------------------------------------------------
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def test_ensure_force_push_is_denied(glEntity, glObject, unauthorised):
|
|
395
|
+
from gitlab.exceptions import GitlabGetError
|
|
396
|
+
|
|
397
|
+
test = code_changes_1_1.ensure_force_push_is_denied
|
|
398
|
+
|
|
399
|
+
glEntity.protectedbranches.get.return_value = None
|
|
400
|
+
run(glEntity, glObject, test, False)
|
|
401
|
+
|
|
402
|
+
branch = Mock()
|
|
403
|
+
branch.allow_force_push = False
|
|
404
|
+
glEntity.protectedbranches.get.return_value = branch
|
|
405
|
+
run(glEntity, glObject, test, True)
|
|
406
|
+
|
|
407
|
+
branch.side_effect = GitlabGetError(response_code=401)
|
|
408
|
+
glEntity.protectedbranches.get.return_value = branch
|
|
409
|
+
unauthorised.protectedbranches.get.side_effect \
|
|
410
|
+
= GitlabGetError(response_code=401)
|
|
411
|
+
run(unauthorised, glObject, test, None)
|
|
412
|
+
|
|
413
|
+
# -----------------------------------------------------------------------------
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def test_deny_branch_deletions(glEntity, glObject, unauthorised):
|
|
417
|
+
from gitlab.exceptions import GitlabGetError
|
|
418
|
+
|
|
419
|
+
test = code_changes_1_1.deny_branch_deletions
|
|
420
|
+
|
|
421
|
+
glEntity.protectedbranches.list.return_value = []
|
|
422
|
+
run(glEntity, glObject, test, False)
|
|
423
|
+
|
|
424
|
+
glEntity.protectedbranches.list.return_value = ['main']
|
|
425
|
+
run(glEntity, glObject, test, True)
|
|
426
|
+
|
|
427
|
+
unauthorised.protectedbranches.list.side_effect \
|
|
428
|
+
= GitlabGetError(response_code=401)
|
|
429
|
+
run(unauthorised, glObject, test, None)
|
|
430
|
+
|
|
431
|
+
# -----------------------------------------------------------------------------
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def test_auto_risk_scan_merges(glEntity, glObject, gqlClient):
|
|
435
|
+
|
|
436
|
+
from gql.transport.exceptions import TransportServerError
|
|
437
|
+
|
|
438
|
+
glEntity.path_with_namespace = 'test/project'
|
|
439
|
+
|
|
440
|
+
kwargs = {
|
|
441
|
+
'graphQLEndpoint': 'https://gitlab.com/api/graphql',
|
|
442
|
+
'graphQLHeaders': {'Authorization': 'Bearer token'}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
test = code_changes_1_1.auto_risk_scan_merges
|
|
446
|
+
|
|
447
|
+
gqlClient.return_value.execute.return_value = {'project': {}}
|
|
448
|
+
run(glEntity, glObject, test, False, **kwargs)
|
|
449
|
+
|
|
450
|
+
mock_result = {
|
|
451
|
+
'project': {
|
|
452
|
+
'scanExecutionPolicies': {
|
|
453
|
+
'nodes': [
|
|
454
|
+
{
|
|
455
|
+
'enabled': True,
|
|
456
|
+
'yaml': '''
|
|
457
|
+
actions:
|
|
458
|
+
- scan: secret_detection
|
|
459
|
+
- scan: dast
|
|
460
|
+
- scan: cluster_image_scanning
|
|
461
|
+
- scan: container_scanning
|
|
462
|
+
- scan: sast
|
|
463
|
+
- scan: sast_iac
|
|
464
|
+
- scan: dependency_scanning
|
|
465
|
+
rules:
|
|
466
|
+
- type: pipeline
|
|
467
|
+
branches: ['*']
|
|
468
|
+
'''
|
|
469
|
+
}
|
|
470
|
+
]
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
gqlClient.return_value.execute.return_value = mock_result
|
|
475
|
+
run(glEntity, glObject, test, True, **kwargs)
|
|
476
|
+
|
|
477
|
+
mock_result = {
|
|
478
|
+
'project': {
|
|
479
|
+
'scanExecutionPolicies': {
|
|
480
|
+
'nodes': [
|
|
481
|
+
{
|
|
482
|
+
'enabled': True,
|
|
483
|
+
'yaml': '''
|
|
484
|
+
actions:
|
|
485
|
+
- scan: secret_detection
|
|
486
|
+
- scan: dast
|
|
487
|
+
rules:
|
|
488
|
+
- type: pipeline
|
|
489
|
+
branches: ['*']
|
|
490
|
+
'''
|
|
491
|
+
}
|
|
492
|
+
]
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
gqlClient.return_value.execute.return_value = mock_result
|
|
498
|
+
run(glEntity, glObject, test, True, **kwargs)
|
|
499
|
+
|
|
500
|
+
mock_result = {
|
|
501
|
+
'project': {
|
|
502
|
+
'scanExecutionPolicies': {
|
|
503
|
+
'nodes': [
|
|
504
|
+
{
|
|
505
|
+
'enabled': True,
|
|
506
|
+
'yaml': '''
|
|
507
|
+
actions:
|
|
508
|
+
- scan: dast
|
|
509
|
+
rules:
|
|
510
|
+
- type: pipeline
|
|
511
|
+
branches: ['*']
|
|
512
|
+
'''
|
|
513
|
+
}
|
|
514
|
+
]
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
gqlClient.return_value.execute.return_value = mock_result
|
|
519
|
+
run(glEntity, glObject, test, False, **kwargs)
|
|
520
|
+
|
|
521
|
+
gqlClient.return_value.execute.side_effect = \
|
|
522
|
+
TransportServerError("Error")
|
|
523
|
+
run(glEntity, glObject, test, None, **kwargs)
|
|
524
|
+
|
|
525
|
+
# -----------------------------------------------------------------------------
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def test_audit_branch_protections(glEntity, glObject, unauthorised):
|
|
529
|
+
from gitlab.exceptions import GitlabAuthenticationError, GitlabGetError
|
|
530
|
+
|
|
531
|
+
test = code_changes_1_1.audit_branch_protections
|
|
532
|
+
|
|
533
|
+
unauthorised.get_license.side_effect = GitlabGetError(
|
|
534
|
+
response_code=403, error_message='403 Forbidden')
|
|
535
|
+
run(glEntity, unauthorised, test, None)
|
|
536
|
+
|
|
537
|
+
glObject.get_license.return_value = {'plan': 'premium'}
|
|
538
|
+
run(glEntity, glObject, test, True)
|
|
539
|
+
|
|
540
|
+
glObject.get_license.return_value = {'plan': 'free'}
|
|
541
|
+
run(glEntity, glObject, test, False)
|
|
542
|
+
|
|
543
|
+
unauthorised.get_license.side_effect = GitlabAuthenticationError()
|
|
544
|
+
run(glEntity, unauthorised, test, None)
|
|
545
|
+
|
|
546
|
+
# -----------------------------------------------------------------------------
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def test_default_branch_protected(glEntity, glObject, unauthorised):
|
|
550
|
+
from gitlab.exceptions import GitlabGetError
|
|
551
|
+
|
|
552
|
+
test = code_changes_1_1.default_branch_protected
|
|
553
|
+
|
|
554
|
+
branch = Mock()
|
|
555
|
+
branch.protected = False
|
|
556
|
+
glEntity.branches.get.return_value = branch
|
|
557
|
+
run(glEntity, glObject, test, False)
|
|
558
|
+
|
|
559
|
+
branch.protected = True
|
|
560
|
+
glEntity.branches.get.return_value = branch
|
|
561
|
+
run(glEntity, glObject, test, True)
|
|
562
|
+
|
|
563
|
+
unauthorised.branches.get.side_effect \
|
|
564
|
+
= GitlabGetError(response_code=401)
|
|
565
|
+
run(unauthorised, glObject, test, None)
|