Skip to content

Commit 5d6a04c

Browse files
XIANJUN ZHUjustineyster
XIANJUN ZHU
authored andcommitted
Properly print out exclude keyword (Yelp#315)
* Properly print out exclude keyword * Add tests * Format * One more test case for regex * Fix build
1 parent 778dc1f commit 5d6a04c

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ matrix:
5151
# python: pypy
5252
install:
5353
- pip install tox
54+
# add public DNS name for public.dhe.ibm.com. The 9.x one is not serving traffic now
55+
# public.dhe.ibm.com access is required for ibm-db pip package
56+
- echo "$(dig @8.8.8.8 public.dhe.ibm.com +short | tail -n1) public.dhe.ibm.com" | sudo tee -a /etc/hosts
5457
# normal script supports multiple line syntax
5558
script: |
5659
set -e

detect_secrets/plugins/keyword.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def default_options(cls):
269269
@property
270270
def __dict__(self):
271271
output = {
272-
'keyword_exclude': self.keyword_exclude,
272+
'keyword_exclude': self.keyword_exclude and self.keyword_exclude.pattern or None,
273273
}
274274
output.update(super(KeywordDetector, self).__dict__)
275275

tests/plugins/keyword_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from __future__ import absolute_import
2+
from __future__ import unicode_literals
3+
4+
import json
5+
16
import ahocorasick
27
import pytest
38

@@ -398,3 +403,32 @@ def test_analyze_example_negatives(self, file_content):
398403
'mock_filename.example',
399404
)
400405
assert len(output) == 0
406+
407+
@pytest.mark.parametrize(
408+
'keyword_exclude, dict_content',
409+
(
410+
(
411+
None,
412+
{'keyword_exclude': None, 'name': 'KeywordDetector'},
413+
),
414+
(
415+
'keyword',
416+
{'keyword_exclude': 'keyword', 'name': 'KeywordDetector'},
417+
),
418+
(
419+
'a.*|b.*',
420+
{'keyword_exclude': 'a.*|b.*', 'name': 'KeywordDetector'},
421+
),
422+
),
423+
)
424+
def test_dict_output(self, keyword_exclude, dict_content):
425+
detector = KeywordDetector(keyword_exclude)
426+
actual = json.dumps(
427+
detector.__dict__,
428+
sort_keys=True,
429+
)
430+
expected = json.dumps(
431+
dict_content,
432+
sort_keys=True,
433+
)
434+
assert actual == expected

0 commit comments

Comments
 (0)