File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -89,15 +89,15 @@ def event():
8989 # Each request comes with request timestamp and request signature
9090 # emit an error if the timestamp is out of range
9191 req_timestamp = request .headers .get ('X-Slack-Request-Timestamp' )
92- if abs (time () - int (req_timestamp )) > 60 * 5 :
92+ if req_timestamp is None or abs (time () - int (req_timestamp )) > 60 * 5 :
9393 slack_exception = SlackEventAdapterException ('Invalid request timestamp' )
9494 self .emitter .emit ('error' , slack_exception )
9595 return make_response ("" , 403 )
9696
9797 # Verify the request signature using the app's signing secret
9898 # emit an error if the signature can't be verified
9999 req_signature = request .headers .get ('X-Slack-Signature' )
100- if not self .verify_signature (req_timestamp , req_signature ):
100+ if req_signature is None or not self .verify_signature (req_timestamp , req_signature ):
101101 slack_exception = SlackEventAdapterException ('Invalid request signature' )
102102 self .emitter .emit ('error' , slack_exception )
103103 return make_response ("" , 403 )
Original file line number Diff line number Diff line change @@ -56,6 +56,32 @@ def test_url_challenge(client):
5656 assert bytes .decode (res .data ) == "valid_challenge_token"
5757
5858
59+ def test_no_request_timestamp_header (client ):
60+ data = pytest .reaction_event_fixture
61+ with pytest .raises (SlackEventAdapterException ) as excinfo :
62+ res = client .post (
63+ '/slack/events' ,
64+ data = data ,
65+ content_type = 'application/json' ,
66+ headers = {}
67+ )
68+ assert str (excinfo .value ) == 'Invalid request timestamp'
69+
70+ def test_no_request_signature_header (client ):
71+ data = pytest .reaction_event_fixture
72+ timestamp = int (time .time ())
73+ with pytest .raises (SlackEventAdapterException ) as excinfo :
74+ res = client .post (
75+ '/slack/events' ,
76+ data = data ,
77+ content_type = 'application/json' ,
78+ headers = {
79+ 'X-Slack-Request-Timestamp' : timestamp , # valid
80+ }
81+ )
82+ assert str (excinfo .value ) == 'Invalid request signature'
83+
84+
5985def test_invalid_request_signature (client ):
6086 # Verify [package metadata header is set
6187 slack_adapter = SlackEventAdapter ("SIGNING_SECRET" )
You can’t perform that action at this time.
0 commit comments