Пример #1
0
    def test_add_local_repo(self, mock_file_operations, mock_rootdir):
        # This just needs to exist; no actual operations will be done to this.
        repo = 'examples'

        git_calls = [
            # repo.update
            SubprocessMock(
                expected_input='git rev-parse HEAD',
                mocked_output='mocked_sha',
            ),
        ]

        with mock_git_calls(*git_calls):
            args = self.parse_args(
                'add {} --baseline .secrets.baseline --local --root-dir {}'.
                format(
                    repo,
                    mock_rootdir,
                ))

            add_repo(args)

        mock_file_operations.write.assert_called_with(
            metadata_factory(
                sha='mocked_sha',
                repo=os.path.abspath(
                    os.path.join(
                        os.path.dirname(__file__),
                        '../../examples',
                    ), ),
                baseline_filename='.secrets.baseline',
                json=True,
            ), )
Пример #2
0
def main(argv=None):
    if argv is None:  # pragma: no cover
        argv = sys.argv[1:]

    if len(argv) == 0:  # pragma: no cover
        argv.append('-h')

    args = parse_args(argv)
    if args.verbose:  # pragma: no cover
        log.set_debug_level(args.verbose)

    if args.action == 'add':
        if getattr(args, 'config', False):
            actions.initialize(args)
        else:
            actions.add_repo(args)

    elif args.action == 'install':
        actions.install_mapper(args)

    elif args.action == 'list':
        actions.display_tracked_repositories(args)

    elif args.action == 'scan':
        return actions.scan_repo(args)

    return 0
Пример #3
0
    def add_non_local_repo(self, mock_rootdir):
        repo = '[email protected]:yelp/detect-secrets'
        directory = '{}/repos/{}'.format(
            mock_rootdir,
            BaseStorage.hash_filename('yelp/detect-secrets'),
        )

        git_calls = [
            SubprocessMock(expected_input='git clone {} {} --bare'.format(
                repo, directory), ),
            SubprocessMock(
                expected_input='git rev-parse HEAD',
                mocked_output='mocked_sha',
            ),
        ]

        with mock_git_calls(*git_calls):
            args = self.parse_args('add {} --root-dir {}'.format(
                repo, mock_rootdir))
            add_repo(args)
Пример #4
0
    def test_add_s3_backend_repo(self, mock_file_operations, mocked_boto):
        args = self.parse_args(
            'add {} '
            '--local '
            '--storage s3 '
            '--s3-credentials-file examples/aws_credentials.json '
            '--s3-bucket pail'.format('examples'),
            has_s3=True,
        )

        git_calls = [
            # repo.update
            SubprocessMock(
                expected_input='git rev-parse HEAD',
                mocked_output='mocked_sha',
            ),
        ]

        with mock_git_calls(*git_calls):
            mocked_boto.list_objects_v2.return_value = {}
            add_repo(args)