-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Loo
committed
Sep 7, 2018
1 parent
c393454
commit 57d3224
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import absolute_import | ||
|
||
import re | ||
|
||
from .base import BasePlugin | ||
from detect_secrets.core.potential_secret import PotentialSecret | ||
|
||
|
||
BASIC_AUTH_REGEX = re.compile( | ||
r'.*?://[^:]+:([^@]+)@', | ||
) | ||
|
||
|
||
class BasicAuthDetector(BasePlugin): | ||
|
||
secret_type = 'Basic Auth Credentials' | ||
|
||
def analyze_string(self, string, line_num, filename): | ||
output = {} | ||
|
||
results = BASIC_AUTH_REGEX.findall(string) | ||
for result in results: | ||
print(result) | ||
secret = PotentialSecret( | ||
self.secret_type, | ||
filename, | ||
line_num, | ||
result, | ||
) | ||
output[secret] = secret | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from __future__ import absolute_import | ||
|
||
import pytest | ||
|
||
from detect_secrets.plugins.basic_auth import BasicAuthDetector | ||
|
||
|
||
class TestBasicAuthDetector(object): | ||
|
||
@pytest.mark.parametrize( | ||
'payload, should_flag', | ||
[ | ||
('https://username:password@yelp.com', True,), | ||
], | ||
) | ||
def test_analyze_string(self, payload, should_flag): | ||
logic = BasicAuthDetector() | ||
|
||
output = logic.analyze_string(payload, 1, 'mock_filename') | ||
assert len(output) == int(should_flag) |