Skip to content

Commit

Permalink
↪️ Merge pull request #122 from killuazhu/slack
Browse files Browse the repository at this point in the history
Add Slack token detector
  • Loading branch information
KevinHock committed Feb 1, 2019
2 parents 4cf087b + 2dd3ef8 commit 24d29d4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions detect_secrets/core/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ class PluginOptions(object):
disable_flag_text='--no-aws-key-scan',
disable_help_text='Disables scanning for AWS keys.',
),
PluginDescriptor(
classname='SlackDetector',
disable_flag_text='--no-slack-scan',
disable_help_text='Disables scanning for Slack tokens.',
),
]

def __init__(self, parser):
Expand Down
1 change: 1 addition & 0 deletions detect_secrets/plugins/common/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..high_entropy_strings import HexHighEntropyString # noqa: F401
from ..keyword import KeywordDetector # noqa: F401
from ..private_key import PrivateKeyDetector # noqa: F401
from ..slack import SlackDetector # noqa: F401
from detect_secrets.core.log import log


Expand Down
15 changes: 15 additions & 0 deletions detect_secrets/plugins/slack.py
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),
)
1 change: 1 addition & 0 deletions tests/core/usage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_consolidates_output_basic(self):
'KeywordDetector': {},
'PrivateKeyDetector': {},
'AWSKeyDetector': {},
'SlackDetector': {},
}
assert not hasattr(args, 'no_private_key_scan')

Expand Down
2 changes: 2 additions & 0 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_scan_string_basic(self, mock_baseline_initialize):
HexHighEntropyString : True (3.459)
KeywordDetector : False
PrivateKeyDetector : False
SlackDetector : False
""")[1:]

mock_baseline_initialize.assert_not_called()
Expand All @@ -85,6 +86,7 @@ def test_scan_string_cli_overrides_stdin(self):
HexHighEntropyString : False (2.121)
KeywordDetector : False
PrivateKeyDetector : False
SlackDetector : False
""")[1:]

def test_scan_with_all_files_flag(self, mock_baseline_initialize):
Expand Down
45 changes: 45 additions & 0 deletions tests/plugins/slack_test.py
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
3 changes: 3 additions & 0 deletions tests/pre_commit_hook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def test_that_baseline_gets_updated(
{
'name': 'PrivateKeyDetector',
},
{
'name': 'SlackDetector',
},
]

def test_writes_new_baseline_if_modified(self):
Expand Down

0 comments on commit 24d29d4

Please sign in to comment.