def test_load_baseline_from_string_with_point_twelve_point_seven_and_later_string(
        self,
        mock_gmtime,
    ):
        """
        We use load_baseline_from_string as a proxy to testing load_baseline_from_dict,
        because it's the most entry into the private function.
        """
        original = self.get_point_twelve_point_seven_and_later_baseline_dict(
            mock_gmtime)

        word_list = """
            roller\n
        """
        with mock_open_base(
                data=word_list,
                namespace='detect_secrets.util.open',
        ):
            secrets = SecretsCollection.load_baseline_from_string(
                json.dumps(original), ).format_for_baseline_output()

        # v0.12.7+ assertions
        assert original['word_list']['file'] == secrets['word_list']['file']
        # Original hash is thrown out and replaced with new word list hash
        assert (secrets['word_list']['hash'] == hashlib.sha1(
            'roller'.encode('utf-8')).hexdigest() !=
                original['word_list']['hash'])

        # Regular assertions
        assert original['exclude']['files'] == secrets['exclude']['files']
        assert secrets['exclude']['lines'] is None
        assert original['results'] == secrets['results']
Пример #2
0
 def mock_open(
     self,
     start_line=10,
     secret_line=15,
     end_line=20,
     line_containing_secret='BEGIN PRIVATE KEY',
 ):
     data = '{}{}{}{}'.format(
         '\n' * (start_line - 1),
         self._make_string_into_individual_lines(
             string.ascii_letters[:(secret_line - start_line)], ),
         line_containing_secret + '\n',
         self._make_string_into_individual_lines(
             string.ascii_letters[:(end_line - secret_line)][::-1], ),
     )
     return mock_open_base(data, 'detect_secrets.core.audit.codecs.open')
def mock_open(data):
    return mock_open_base(
        data, 'detect_secrets.core.secrets_collection.codecs.open')
def mock_open(data):
    return mock_open_base(data, 'detect_secrets.core.secrets_collection.codecs.open')