Skip to content

Commit

Permalink
Fix user enum error and add tets. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnaneKhan authored Aug 5, 2024
1 parent 5beec71 commit 77d8d58
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gatox/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ def enumerate(args, parser):
args.target
)]
else:
# Otherwise, simply enumerate all repositories belonging to the user.
repos = gh_enumeration_runner.enumerate_repos([args.target])
# Otherwise, simply enumerate all repositories belonging to the user.
repos = gh_enumeration_runner.enumerate_user(args.target)
elif args.repositories:
try:
repo_list = util.read_file_and_validate_lines(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "gato-x"
version = "0.5.2"
version = "0.5.3"
description = "GitHub Actions Enumeration and Attack Framework"
readme = "README.md"
authors = [
Expand Down
31 changes: 31 additions & 0 deletions unit_test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,34 @@ def test_graphql_mergedat_query(mock_call_post, mock_call_get):
date = api.get_commit_merge_date('testOrg/testRepo', '9659fdc7ba35a9eba00c183bccc67083239383e8')

assert date == "2024-06-21T09:57:58Z"

@patch('gatox.github.api.requests.get')
def test_get_user_type(mock_call_get):

test_pat = "ghp_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
api = Api(test_pat, "2022-11-28")

mock_call_get.side_effect = [
MagicMock(status_code=200, json=MagicMock(return_value={'type': 'User'})),
]

user_type = api.get_user_type("someUser")

assert user_type == 'User'

@patch('gatox.github.api.requests.get')
def test_get_user_repos(mock_call_get):
test_pat = "ghp_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
api = Api(test_pat, "2022-11-28")

mock_call_get.side_effect = [
MagicMock(status_code=200, json=MagicMock(
return_value=[{'full_name': 'testRepo','archived': False},
{'full_name': 'testRepo2','archived': False}]
)),
]

repos = api.get_user_repos("someUser")

assert repos[0] == 'testRepo'
assert repos[1] == 'testRepo2'
6 changes: 2 additions & 4 deletions unit_test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,12 @@ def test_enum_org(mock_enumerate):

@mock.patch("gatox.cli.cli.Enumerator")
def test_enum_user(mock_enumerate):
"""Test enum command using the organization enumerattion.
"""Test enum command using the organization enumeration.
"""

mock_instance = mock_enumerate.return_value
mock_api = mock.MagicMock()

print(mock_instance)

mock_api.check_user.return_value = {
"user": 'testUser',
"scopes": ['repo', 'workflow']
Expand All @@ -314,7 +312,7 @@ def test_enum_user(mock_enumerate):

cli.cli(["enum", "-t", "testUser"])

mock_instance.enumerate_repos.assert_called_once()
mock_instance.enumerate_user.assert_called_once()



Expand Down

0 comments on commit 77d8d58

Please sign in to comment.