Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update artifactory.py #136

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions detect_secrets/plugins/artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ArtifactoryDetector(RegexBasedDetector):
re.compile(r'(?:(?<==|:|")|(?<=\s)|(?<=^))AKC[a-zA-Z0-9]{10,}'), # api token
# artifactory encrypted passwords begin with AP[A-Z]
re.compile(r'(?:(?<==|:|")|(?<=\s)|(?<=^))AP[\dABCDEF][a-zA-Z0-9]{8,}'), # password
# artifactory identity tokens are different (base64 encoded reftkn:) and 64 chars
re.compile(r'(?:(?<==|:|")|(?<=\s)|(?<=^))cmVmdGtu[\da-zA-Z]{56}'),
]

artifactory_url = 'na.artifactory.swg-devops.com/artifactory'
Expand Down
23 changes: 23 additions & 0 deletions tests/plugins/artifactory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,61 @@

ARTIFACTORY_TOKEN = 'AKCxxxxxxxxxx'
ARTIFACTORY_TOKEN_BYTES = b'AKCxxxxxxxxxx'
ARTIFACTORY_IDENTITY_TOKEN = b'cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'


class TestArtifactoryDetector(object):

@pytest.mark.parametrize(
'token, payload, should_flag',
[
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'Authorization: Bearer cmVmdGtu'
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('AP6xxxxxxxxxx', 'AP6xxxxxxxxxx', True),
('AP2xxxxxxxxxx', 'AP2xxxxxxxxxx', True),
('AP3xxxxxxxxxx', 'AP3xxxxxxxxxx', True),
('AP5xxxxxxxxxx', 'AP5xxxxxxxxxx', True),
('APAxxxxxxxxxx', 'APAxxxxxxxxxx', True),
('APBxxxxxxxxxx', 'APBxxxxxxxxxx', True),
('AKCxxxxxxxxxx', 'AKCxxxxxxxxxx', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('AP6xxxxxxxxxx', ' AP6xxxxxxxxxx', True),
('AKCxxxxxxxxxx', ' AKCxxxxxxxxxx', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
' cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('AP6xxxxxxxxxx', '=AP6xxxxxxxxxx', True),
('AKCxxxxxxxxxx', '=AKCxxxxxxxxxx', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'=cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('AP6xxxxxxxxxx', '\"AP6xxxxxxxxxx\"', True),
('AKCxxxxxxxxxx', '\"AKCxxxxxxxxxx\"', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'\"cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"', True),
('AP6xxxxxxxxxx', 'artif-key:AP6xxxxxxxxxx', True),
('AKCxxxxxxxxxx', 'artif-key:AKCxxxxxxxxxx', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'artif-key:cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('AKCxxxxxxxxxx', 'X-JFrog-Art-Api: AKCxxxxxxxxxx', True),
('AP6xxxxxxxxxx', 'X-JFrog-Art-Api: AP6xxxxxxxxxx', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'X-JFrog-Art-Api: cmVmdGtu'
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('AKCxxxxxxxxxx', 'artifactoryx:_password=AKCxxxxxxxxxx', True),
('AP6xxxxxxxxxx', 'artifactoryx:_password=AP6xxxxxxxxxx', True),
('cmVmdGtuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'artifactoryx:_password=cmVmdGtu'
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', True),
('', 'testAKCwithinsomeirrelevantstring', False),
('', 'testAP6withinsomeirrelevantstring', False),
('', 'testcmVmdGtuwithinsomeirrelevantstring', False),
('', 'X-JFrog-Art-Api: $API_KEY', False),
('', 'X-JFrog-Art-Api: $PASSWORD', False),
('', 'artifactory:_password=AP6xxxxxx', False),
('', 'artifactory:_password=AKCxxxxxxxx', False),
('', 'artifactory:_password=cmVmdGtu'
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', False),
],
)
def test_analyze_line(self, token, payload, should_flag):
Expand Down