def test_basic(original_hex_detector):
        value = '0123456789'
        assert (HexHighEntropyString().calculate_shannon_entropy(value) <
                original_hex_detector().calculate_shannon_entropy(value))

        # This is the goal.
        assert HexHighEntropyString().calculate_shannon_entropy(value) < 3
    def test_yaml_file(self):
        plugin = HexHighEntropyString(3)
        with open('test_data/config2.yaml') as f:
            secrets = plugin.analyze(f, 'test_data/config2.yaml')

        assert len(secrets.values()) == 1
        for secret in secrets.values():
            location = str(secret).splitlines()[1]
            assert location in ('Location:    test_data/config2.yaml:2', )
 def setup(self):
     super(TestHexHighEntropyStrings, self).setup(
         # Testing default limit, as suggested by truffleHog.
         HexHighEntropyString(3),
         'aaaaaa',
         '2b00042f7481c7b056c4b410d28f33cf',
     )
 def setup(self):
     self.logic = secrets_collection_factory(
         secrets=[
             {
                 'type_': 'A',
                 'lineno': 3,
                 'filename': 'fileA',
             },
             {
                 'type_': 'B',
                 'lineno': 2,
                 'filename': 'fileA',
             },
             {
                 'type_': 'C',
                 'lineno': 1,
                 'filename': 'fileB',
             },
         ],
         plugins=(
             HexHighEntropyString(3),
             PrivateKeyDetector(),
         ),
         exclude_files_regex='foo',
         word_list_file='will_be_mocked.txt',
         word_list_hash='5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8',
     )
 def setup(self):
     self.logic = secrets_collection_factory(
         secrets=[
             {
                 'type_': 'A',
                 'lineno': 3,
                 'filename': 'fileA',
             },
             {
                 'type_': 'B',
                 'lineno': 2,
                 'filename': 'fileA',
             },
             {
                 'type_': 'C',
                 'lineno': 1,
                 'filename': 'fileB',
             },
         ],
         plugins=(
             HexHighEntropyString(3),
             PrivateKeyDetector(),
         ),
         exclude_files_regex='foo',
     )
 def setup(self):
     super(TestHexHighEntropyStrings, self).setup(
         # Testing default limit, as suggested by truffleHog.
         logic=HexHighEntropyString(
             hex_limit=3,
             exclude_lines_regex='CanonicalUser',
         ),
         non_secret_string='aaaaaa',
         secret_string='2b00042f7481c7b056c4b410d28f33cf',
     )
Ejemplo n.º 7
0
    def load_from_diff(self, existing_secrets=None, baseline_filename='', exclude_regex=''):
        collection = secrets_collection_factory(
            secrets=existing_secrets,
            plugins=(HexHighEntropyString(3),),
            exclude_regex=exclude_regex,
        )

        with open('test_data/sample.diff') as f:
            collection.scan_diff(f.read(), baseline_filename=baseline_filename)

        return collection
Ejemplo n.º 8
0
 def setup(self):
     self.plugins = (
         Base64HighEntropyString(4.5),
         HexHighEntropyString(3),
     )
 def __init__(self, limit: float) -> None:
     self.high_entropy_scanners = (Base64HighEntropyString(limit=limit),
                                   HexHighEntropyString(limit=limit))
     self.keyword_scanner = KeywordDetector()
 def test_single_case(original_hex_detector):
     value = '0'
     assert (HexHighEntropyString().calculate_shannon_entropy(value) ==
             original_hex_detector().calculate_shannon_entropy(value))
 def test_only_with_numbers(original_hex_detector):
     value = '12345a'
     assert (HexHighEntropyString().calculate_shannon_entropy(value) ==
             original_hex_detector().calculate_shannon_entropy(value))
 def test_length_dependency(original_hex_detector):
     assert (HexHighEntropyString().calculate_shannon_entropy('0123456789')
             < HexHighEntropyString().calculate_shannon_entropy(
                 '01234567890123456789'))