From 7052257d58fda9b2e11298abdf9adeb088d9f752 Mon Sep 17 00:00:00 2001 From: Pankaj Patil Date: Wed, 28 Aug 2019 22:46:02 +0530 Subject: [PATCH 1/2] Added Verifiability Slack --- detect_secrets/plugins/slack.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/detect_secrets/plugins/slack.py b/detect_secrets/plugins/slack.py index 3a1805e03..71ae5a96b 100644 --- a/detect_secrets/plugins/slack.py +++ b/detect_secrets/plugins/slack.py @@ -27,13 +27,26 @@ class SlackDetector(RegexBasedDetector): ), ) - def verify(self, token, **kwargs): # pragma: no cover - response = requests.post( - 'https://slack.com/api/auth.test', - data={ - 'token': token, - }, - ).json() - - return VerifiedResult.VERIFIED_TRUE if response['ok'] \ + def verify(self, token, **kwargs): # pragma: no cover + if token.startswith('https://hooks.slack.com/services/T'): + response = requests.post( + token, + json={ + 'text': '', + }, + ) + valid = response.text == "missing_text_or_fallback_or_attachments" + else: + response = requests.post( + 'https://slack.com/api/auth.test', + data={ + 'token': token, + }, + ).json() + valid = response['ok'] + + return ( + VerifiedResult.VERIFIED_TRUE + if valid else VerifiedResult.VERIFIED_FALSE + ) \ No newline at end of file From 2dd2735b6abc465d0578d77f5bdae8e6158c3b53 Mon Sep 17 00:00:00 2001 From: Pankaj Patil Date: Thu, 29 Aug 2019 01:03:37 +0530 Subject: [PATCH 2/2] Fixed Test Case Issue --- detect_secrets/plugins/slack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect_secrets/plugins/slack.py b/detect_secrets/plugins/slack.py index 71ae5a96b..abd9b9bdc 100644 --- a/detect_secrets/plugins/slack.py +++ b/detect_secrets/plugins/slack.py @@ -47,6 +47,6 @@ def verify(self, token, **kwargs): # pragma: no cover return ( VerifiedResult.VERIFIED_TRUE - if valid + if valid else VerifiedResult.VERIFIED_FALSE ) \ No newline at end of file