def test_process_gitlab_projects_with_ignore_project(
         self, mock_gptp, mock_commitmanager):
     # given
     scanner = GitLabScanner('url',
                             'token',
                             None, [], [1],
                             annotate_latest_commit_id=True)
     projects = assemble_projects()
     self.prepare_gitlab_commitlist_mock(mock_gptp, mock_commitmanager)
     # when
     findings = scanner._process_projects(projects)
     # then
     self.assertEqual(2,
                      len(findings),
                      msg='There should be exactly 2 findings')
     self.assertEqual(findings[0]['attributes']['web_url'],
                      'url2',
                      msg=self.wrong_output_msg)
     self.assertEqual(findings[1]['attributes']['web_url'],
                      'url3',
                      msg=self.wrong_output_msg)
     self.assertEqual(findings[0]['attributes']["last_commit_id"],
                      "deadbeef")
     mock_gptp.assert_called()
     mock_commitmanager.assert_called()
 def test_process_gitlab_projects_without_annotating_commit_id(
         self, mock_gptp, mock_commitmanager):
     # given
     scanner = GitLabScanner('url',
                             'token',
                             None, [], [],
                             annotate_latest_commit_id=False)
     projects = assemble_projects()
     self.prepare_gitlab_commitlist_mock(mock_gptp, mock_commitmanager)
     # when
     findings = scanner._process_projects(projects)
     # then
     self.assertEqual(3,
                      len(findings),
                      msg='There should be exactly 3 findings')
     self.assertEqual(findings[0]['name'],
                      'GitLab Repo',
                      msg=self.wrong_output_msg)
     self.assertEqual(findings[0]['attributes']['web_url'],
                      'url1',
                      msg=self.wrong_output_msg)
     self.assertEqual(findings[1]['attributes']['web_url'],
                      'url2',
                      msg=self.wrong_output_msg)
     self.assertEqual(findings[2]['attributes']['web_url'],
                      'url3',
                      msg=self.wrong_output_msg)
     self.assertFalse("last_commit_id" in findings[0]['attributes'])
     mock_gptp.assert_not_called()
     mock_commitmanager.assert_not_called()
Beispiel #3
0
 def test_process_gitlab_projects_with_ignore_project(self):
     # given
     scanner = GitLabScanner('url', 'token', None, [], [1])
     projects = assemble_projects()
     # when
     findings = scanner._process_projects(projects)
     # then
     self.assertEqual(2, len(findings), msg='There should be exactly 2 findings')
     self.assertEqual(findings[0]['attributes']['web_url'], 'url2', msg=self.wrong_output_msg)
     self.assertEqual(findings[1]['attributes']['web_url'], 'url3', msg=self.wrong_output_msg)
Beispiel #4
0
def process(args):
    scanner: AbstractScanner

    if args.git_type == 'gitlab':
        scanner = GitLabScanner(
            url=args.url,
            access_token=args.access_token,
            group=args.group,
            ignored_groups=args.ignore_groups,
            ignore_repos=args.ignore_repos,
            obey_rate_limit=args.obey_rate_limit
        )
    elif args.git_type == 'github':
        scanner = GitHubScanner(
            url=args.url,
            access_token=args.access_token,
            organization=args.organization,
            ignore_repos=args.ignore_repos,
            obey_rate_limit=args.obey_rate_limit
        )
    else:
        logger.info('Argument error: Unknown git type')
        sys.exit(1)

    try:
        return scanner.process(
            args.activity_since_duration,
            args.activity_until_duration
        )
    except argparse.ArgumentError as e:
        logger.error(f'Argument error: {e}')
        sys.exit(1)
    except gitlab.exceptions.GitlabAuthenticationError:
        logger.info('No permission. Check your access token.')
        sys.exit(1)
    except github.GithubException as e:
        logger.error(f'Github API Exception: {e.status} -> {e.data["message"]}')
        sys.exit(2)
    except gitlab.GitlabError as e:
        logger.error(f'Gitlab API Exception: {e}')
        sys.exit(2)
    except Exception as e:
        logger.error(f'Unexpected error: {e}')
        sys.exit(3)