MCPcopy Index your code
hub / github.com/slackapi/python-slack-sdk / is_valid

Method is_valid

slack/signature/verifier.py:40–56  ·  view source on GitHub ↗

Verifies if the given signature is valid

(
        self,
        body: Union[str, bytes],
        timestamp: str,
        signature: str,
    )

Source from the content-addressed store, hash-verified

38 )
39
40 def is_valid(
41 self,
42 body: Union[str, bytes],
43 timestamp: str,
44 signature: str,
45 ) -> bool:
46 """Verifies if the given signature is valid"""
47 if timestamp is None or signature is None:
48 return False
49
50 if abs(self.clock.now() - int(timestamp)) > 60 * 5:
51 return False
52
53 calculated_signature = self.generate_signature(timestamp=timestamp, body=body)
54 if calculated_signature is None:
55 return False
56 return hmac.compare_digest(calculated_signature, signature)
57
58 def generate_signature(self, *, timestamp: str, body: Union[str, bytes]) -> Optional[str]:
59 """Generates a signature"""

Callers 11

test_is_validMethod · 0.95
test_is_valid_noneMethod · 0.95
test_is_validMethod · 0.95
test_is_valid_noneMethod · 0.95
is_valid_requestMethod · 0.95
slack_appFunction · 0.45
slack_appFunction · 0.45
slack_appFunction · 0.45
slack_appFunction · 0.45
slack_appFunction · 0.45
slack_appFunction · 0.45

Calls 2

generate_signatureMethod · 0.95
nowMethod · 0.45

Tested by 4

test_is_validMethod · 0.76
test_is_valid_noneMethod · 0.76
test_is_validMethod · 0.76
test_is_valid_noneMethod · 0.76