mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-17 08:54:16 +00:00
fix: service tests
This commit is contained in:
3 files changed
+27
-11
No files matched your search
@@ -18,16 +18,19 @@ class Repository(GithubService):
|
||||
for client in self.clients:
|
||||
for repo in client.get_user().get_repos():
|
||||
default_branch = repo.default_branch
|
||||
securitymd_exists = False
|
||||
try:
|
||||
securitymd_exists = repo.get_contents("SECURITY.md") is not None
|
||||
except Exception:
|
||||
securitymd_exists = False
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Could not find SECURITY.md for repo {repo.name}: {e}"
|
||||
)
|
||||
|
||||
branch = repo.get_branch(default_branch)
|
||||
require_pr = False
|
||||
approval_cnt = 0
|
||||
if branch.protected:
|
||||
try:
|
||||
try:
|
||||
branch = repo.get_branch(default_branch)
|
||||
if branch.protected:
|
||||
protection = branch.get_protection()
|
||||
if protection:
|
||||
require_pr = (
|
||||
@@ -38,9 +41,10 @@ class Repository(GithubService):
|
||||
if require_pr
|
||||
else 0
|
||||
)
|
||||
except Exception:
|
||||
require_pr = False
|
||||
approval_cnt = 0
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Could not get branch protection for repo {repo.name}: {e}"
|
||||
)
|
||||
|
||||
repos[repo.id] = Repo(
|
||||
id=repo.id,
|
||||
@@ -52,6 +56,7 @@ class Repository(GithubService):
|
||||
require_pull_request=require_pr,
|
||||
approval_count=approval_cnt,
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||
|
||||
+6
@@ -32,8 +32,11 @@ class Test_repository_public_has_securitymd_file_test:
|
||||
id=1,
|
||||
name=repo_name,
|
||||
full_name="account-name/repo1",
|
||||
default_branch="main",
|
||||
private=False,
|
||||
securitymd=False,
|
||||
require_pull_request=False,
|
||||
approval_count=0,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -67,8 +70,11 @@ class Test_repository_public_has_securitymd_file_test:
|
||||
id=1,
|
||||
name=repo_name,
|
||||
full_name="account-name/repo1",
|
||||
default_branch="main",
|
||||
private=False,
|
||||
securitymd=True,
|
||||
require_pull_request=False,
|
||||
approval_count=0,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,11 @@ def mock_list_repositories(_):
|
||||
id=1,
|
||||
name="repo1",
|
||||
full_name="account-name/repo1",
|
||||
default_branch="main",
|
||||
private=False,
|
||||
securitymd=False,
|
||||
securitymd=True,
|
||||
require_pull_request=True,
|
||||
approval_count=2,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -26,7 +29,7 @@ def mock_list_repositories(_):
|
||||
class Test_Repository_Service:
|
||||
def test_get_client(self):
|
||||
repository_service = Repository(set_mocked_github_provider())
|
||||
assert repository_service.client.__class__.__name__ == "Github"
|
||||
assert repository_service.clients[0].__class__.__name__ == "Github"
|
||||
|
||||
def test_get_service(self):
|
||||
repository_service = Repository(set_mocked_github_provider())
|
||||
@@ -38,4 +41,6 @@ class Test_Repository_Service:
|
||||
assert repository_service.repositories[1].name == "repo1"
|
||||
assert repository_service.repositories[1].full_name == "account-name/repo1"
|
||||
assert repository_service.repositories[1].private is False
|
||||
assert repository_service.repositories[1].securitymd is False
|
||||
assert repository_service.repositories[1].securitymd
|
||||
assert repository_service.repositories[1].require_pull_request
|
||||
assert repository_service.repositories[1].approval_count == 2
|
||||
Reference in new issue
Block a user