Skip to content

Commit 1523246

Browse files
authored
Rewind body after checking request signature (#354)
1 parent c186a91 commit 1523246

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* [#348](https://github.com/slack-ruby/slack-ruby-client/pull/348): Added `admin_conversations_archive`, `admin_conversations_convertToPrivate`, `admin_conversations_create`, `admin_conversations_delete`, `admin_conversations_disconnectShared`, `admin_conversations_getConversationPrefs`, `admin_conversations_getTeams`, `admin_conversations_invite`, `admin_conversations_rename`, `admin_conversations_search`, `admin_conversations_setConversationPrefs`, `admin_conversations_unarchive`, `admin_conversations_ekm_listOriginalConnectedChannelInfo`, `admin_users_session_invalidate`, `apps_event_authorizations_list`, `conversations_mark`, `workflows_stepCompleted`, `workflows_stepFailed`, `workflows_updateStep` endpoints - [@wasabigeek](https://github.com/wasabigeek).
44
* [#350](https://github.com/slack-ruby/slack-ruby-client/pull/350): Handle server errors such as timouts & non-json responses (see [Upgrading to 0.16.0](UPGRADING.md#upgrading-to--0160)) - [@ojab](https://github.com/ojab).
5+
* [#354](https://github.com/slack-ruby/slack-ruby-client/pull/354): Rewind body after checking request signature - [@sunny](https://github.com/sunny).
56
* Your contribution here.
67

78
### 0.15.1 (2020/9/3)

lib/slack/events/request.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def version
3535

3636
# Request body.
3737
def body
38-
@body ||= http_request.body.read
38+
@body ||= begin
39+
body = http_request.body.read
40+
http_request.body.rewind
41+
body
42+
end
3943
end
4044

4145
# Returns true if the signature coming from Slack has expired.

spec/slack/events/request_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
'X-Slack-Request-Timestamp' => timestamp,
2727
'X-Slack-Signature' => signature
2828
},
29-
body: double(
30-
read: body
31-
)
29+
body: StringIO.new(body)
3230
)
3331
end
3432

@@ -42,6 +40,12 @@
4240
expect(request.timestamp).to eq timestamp
4341
expect(request.version).to eq 'v0'
4442
end
43+
44+
it 'rewinds the request body after reading it' do
45+
expect(request.body).to eq body
46+
expect(http_request.body.read).to eq body
47+
end
48+
4549
context 'time' do
4650
after do
4751
Timecop.return

0 commit comments

Comments
 (0)