-
Notifications
You must be signed in to change notification settings - Fork 130
Allow to skip signature verification #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+103
−8
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8684935
Allow to skip signature verification
habara-k 9f8c385
Update comments
habara-k b391460
Fix proc type
habara-k 3ecd82a
Fix comment
habara-k 6e8264b
Fix comment
habara-k ce43590
Make WebhookParser#verify_signature public
habara-k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require 'spec_helper' | ||
|
||
describe Line::Bot::V2::WebhookParser do | ||
let(:channel_secret) { 'dummy_channel_secret' } | ||
let(:signature) { 'invalid_signature' } | ||
let(:webhook) do | ||
<<~JSON | ||
{ | ||
"destination": "xxxxxxxxxx", | ||
"events": [ | ||
{ | ||
"type": "message", | ||
"message": { | ||
"type": "text", | ||
"id": "123456789", | ||
"quoteToken": "q3Plxr4AgKd...", | ||
"text": "Hello, world" | ||
}, | ||
"timestamp": 1462629479859, | ||
"source": { | ||
"type": "user", | ||
"userId": "U4af4980629..." | ||
}, | ||
"webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR", | ||
"deliveryContext": { | ||
"isRedelivery": false | ||
}, | ||
"replyToken": "fbf94e269485410da6b7e3a5e33283e8", | ||
"mode": "active" | ||
} | ||
] | ||
} | ||
JSON | ||
end | ||
|
||
describe '#parse with skip_signature_verification' do | ||
context 'when skip_signature_verification is not provided' do | ||
let(:parser) { Line::Bot::V2::WebhookParser.new(channel_secret: channel_secret) } | ||
|
||
it 'verifies the signature' do | ||
expect(parser).to receive(:verify_signature).and_return(false) | ||
expect { parser.parse(body: webhook, signature: signature) }.to raise_error(Line::Bot::V2::WebhookParser::InvalidSignatureError) | ||
end | ||
end | ||
|
||
context 'when skip_signature_verification returns false' do | ||
let(:parser) { Line::Bot::V2::WebhookParser.new(channel_secret: channel_secret, skip_signature_verification: -> { false }) } | ||
|
||
it 'verifies the signature' do | ||
expect(parser).to receive(:verify_signature).and_return(false) | ||
expect { parser.parse(body: webhook, signature: signature) }.to raise_error(Line::Bot::V2::WebhookParser::InvalidSignatureError) | ||
end | ||
end | ||
|
||
context 'when skip_signature_verification returns true' do | ||
let(:parser) { Line::Bot::V2::WebhookParser.new(channel_secret: channel_secret, skip_signature_verification: -> { true }) } | ||
|
||
it 'skips signature verification and parses the webhook' do | ||
expect(parser).not_to receive(:verify_signature) | ||
events = parser.parse(body: webhook, signature: signature) | ||
expect(events).not_to be_empty | ||
expect(events.first).to be_a(Line::Bot::V2::Webhook::MessageEvent) | ||
end | ||
end | ||
|
||
context 'when skip_signature_verification is nil' do | ||
let(:parser) { Line::Bot::V2::WebhookParser.new(channel_secret: channel_secret, skip_signature_verification: nil) } | ||
|
||
it 'verifies the signature' do | ||
expect(parser).to receive(:verify_signature).and_return(false) | ||
expect { parser.parse(body: webhook, signature: signature) }.to raise_error(Line::Bot::V2::WebhookParser::InvalidSignatureError) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if
skip_signature_verification
accepts not onlyProc
s but also boolean values. It is possible to passProc
s like-> { true }
or-> { false }
but just checking boolean (without calling) would be more efficient.for example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your suggestion. Allowing boolean values could certainly be convenient in some cases. However, having both
()-> bool
andbool
in the same field would increase type complexity.This feature is primarily intended for use cases where the decision to skip signature verification may change dynamically—for example, when controlled by environment variables.
Since the same behavior can be achieved by passing a function that simply returns a fixed true or false, we have decided not to adopt direct boolean support at this time.