-
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.
Merge pull request #122 from killuazhu/slack
Add Slack token detector
- Loading branch information
Showing
7 changed files
with
72 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
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,15 @@ | ||
""" | ||
This plugin searches for Slack tokens | ||
""" | ||
from __future__ import absolute_import | ||
|
||
import re | ||
|
||
from .base import RegexBasedDetector | ||
|
||
|
||
class SlackDetector(RegexBasedDetector): | ||
secret_type = 'Slack Token' | ||
blacklist = ( | ||
re.compile(r'xox(?:a|b|p|o|s|r)-(?:\d+-)+[a-z0-9]+', flags=re.IGNORECASE), | ||
) |
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
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,45 @@ | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import pytest | ||
|
||
from detect_secrets.plugins.slack import SlackDetector | ||
from testing.mocks import mock_file_object | ||
|
||
|
||
class TestSlackDetector(object): | ||
|
||
@pytest.mark.parametrize( | ||
'file_content', | ||
[ | ||
( | ||
'xoxp-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxo-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxs-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxa-511111111-31111111111-3111111111111-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxa-2-511111111-31111111111-3111111111111-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxr-523423-234243-234233-e039d02840a0b9379c' | ||
), | ||
( | ||
'xoxb-34532454-e039d02840a0b9379c' | ||
), | ||
], | ||
) | ||
def test_analyze(self, file_content): | ||
logic = SlackDetector() | ||
|
||
f = mock_file_object(file_content) | ||
output = logic.analyze(f, 'mock_filename') | ||
assert len(output) == 1 | ||
for potential_secret in output: | ||
assert 'mock_filename' == potential_secret.filename |
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