mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-09 21:14:22 +00:00
chore: add provider-uid flag for iac provider (#10233)
Co-authored-by: Pepe Fagoaga <pepe@prowler.com>
This commit is contained in:
co-authored by
Pepe Fagoaga
parent
8f3e69f571
commit
012fd84cb0
@@ -689,6 +689,7 @@ class TestFinding:
|
||||
provider.type = "iac"
|
||||
provider.scan_repository_url = "https://github.com/user/repo"
|
||||
provider.auth_method = "No auth"
|
||||
provider.provider_uid = None
|
||||
|
||||
# Mock check result
|
||||
check_output = MagicMock()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import types
|
||||
|
||||
from prowler.providers.iac.lib.arguments import arguments as iac_arguments
|
||||
|
||||
Args = types.SimpleNamespace
|
||||
|
||||
|
||||
def test_validate_arguments_mutual_exclusion():
|
||||
from prowler.providers.iac.lib.arguments import arguments as iac_arguments
|
||||
|
||||
Args = types.SimpleNamespace
|
||||
|
||||
# Only scan_path (default)
|
||||
args = Args(scan_path=".", scan_repository_url=None)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
@@ -31,3 +31,90 @@ def test_validate_arguments_mutual_exclusion():
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
|
||||
def test_validate_arguments_export_ocsf_requires_provider_uid():
|
||||
# --export-ocsf without provider_uid should fail
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
export_ocsf=True,
|
||||
provider_uid=None,
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert not valid
|
||||
assert "--provider-uid is required" in msg
|
||||
|
||||
|
||||
def test_validate_arguments_export_ocsf_with_provider_uid_passes():
|
||||
# --export-ocsf with valid provider_uid should pass
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
export_ocsf=True,
|
||||
provider_uid="https://github.com/user/repo.git",
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
|
||||
def test_validate_arguments_no_export_ocsf_without_provider_uid_passes():
|
||||
# No --export-ocsf, no provider_uid — should pass
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
export_ocsf=False,
|
||||
provider_uid=None,
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
# No export_ocsf attr at all — should pass
|
||||
args = Args(scan_path=".", scan_repository_url=None)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
|
||||
def test_validate_arguments_provider_uid_must_be_valid_url():
|
||||
# Invalid provider_uid should fail
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
provider_uid="not-a-url",
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert not valid
|
||||
assert "valid repository URL" in msg
|
||||
|
||||
# HTTPS URL without .git should pass
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
provider_uid="https://github.com/user/repo",
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
# HTTPS URL with .git should pass
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
provider_uid="https://github.com/user/repo.git",
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
# SSH URL should pass
|
||||
args = Args(
|
||||
scan_path=".",
|
||||
scan_repository_url=None,
|
||||
provider_uid="git@github.com:user/repo.git",
|
||||
)
|
||||
valid, msg = iac_arguments.validate_arguments(args)
|
||||
assert valid
|
||||
assert msg == ""
|
||||
|
||||
Reference in New Issue
Block a user