sendgrid-ruby 6.2.1 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +0 -1
- data/Makefile +2 -1
- data/examples/helpers/eventwebhook/example.rb +16 -0
- data/lib/rack/sendgrid_webhook_verification.rb +52 -0
- data/lib/sendgrid-ruby.rb +2 -0
- data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +52 -0
- data/lib/sendgrid/version.rb +1 -1
- data/sendgrid-ruby.gemspec +1 -0
- data/spec/fixtures/event_webhook.rb +16 -0
- data/spec/rack/sendgrid_webhook_verification_spec.rb +116 -0
- data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +103 -0
- data/test/sendgrid/test_sendgrid-ruby.rb +1 -1
- metadata +27 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34e9f9d2222a7a622d3a92b44006854f282296230b5e08958bdc0c3983ce1bf0
|
4
|
+
data.tar.gz: d2d1daecf34261120b150a4c3d64fb48b90816e18dd3b053478751365e0ae426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce14fa4b6341a6dac4c09aa83f999463f1c07849b05e47e5c9a596c009ba39a6ca733193c6f8543adc5aa1c989d6651a48f21223c608bda1a95d61b6e0af42a0
|
7
|
+
data.tar.gz: 77b872b63c84354a2f01d4a1b2717e23212f5a59a1ef8b6ae427491aabd43bc165cbbf1657383786187751b6db372ac1358e818c2f4ebe7a29e3cb17fbebce48
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
[2020-06-25] Version 6.3.1
|
5
|
+
--------------------------
|
6
|
+
|
7
|
+
|
8
|
+
[2020-06-24] Version 6.3.0
|
9
|
+
--------------------------
|
10
|
+
**Library - Feature**
|
11
|
+
- [PR #428](https://github.com/sendgrid/sendgrid-ruby/pull/428): adds rack middleware to make request verification easier in rack apps. Thanks to [@philnash](https://github.com/philnash)!
|
12
|
+
- [PR #425](https://github.com/sendgrid/sendgrid-ruby/pull/425): verify signature from event webhook. Thanks to [@eshanholtz](https://github.com/eshanholtz)!
|
13
|
+
|
14
|
+
**Library - Fix**
|
15
|
+
- [PR #427](https://github.com/sendgrid/sendgrid-ruby/pull/427): drop the starkbank dependency. Thanks to [@childish-sambino](https://github.com/childish-sambino)!
|
16
|
+
|
17
|
+
|
4
18
|
[2020-05-13] Version 6.2.1
|
5
19
|
--------------------------
|
6
20
|
**Library - Fix**
|
data/CONTRIBUTING.md
CHANGED
@@ -47,7 +47,7 @@ Before you decide to create a new issue, please try the following:
|
|
47
47
|
|
48
48
|
### Please use our Bug Report Template
|
49
49
|
|
50
|
-
In order to make the process easier, we've included a [sample bug report template](
|
50
|
+
In order to make the process easier, we've included a [sample bug report template](ISSUE_TEMPLATE.md).
|
51
51
|
|
52
52
|
<a name="improvements-to-the-codebase"></a>
|
53
53
|
## Improvements to the Codebase
|
data/Gemfile
CHANGED
data/Makefile
CHANGED
@@ -10,4 +10,5 @@ test-integ: test
|
|
10
10
|
|
11
11
|
version ?= ruby:latest
|
12
12
|
test-docker:
|
13
|
-
curl -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/prism/prism.sh
|
13
|
+
curl -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/prism/prism.sh -o prism.sh
|
14
|
+
version=$(version) bash ./prism.sh
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sengrid-ruby'
|
2
|
+
include SendGrid
|
3
|
+
|
4
|
+
def is_valid_signature(request)
|
5
|
+
public_key = 'base64-encoded public key'
|
6
|
+
|
7
|
+
event_webhook = SendGrid::EventWebhook.new
|
8
|
+
ec_public_key = event_webhook.convert_public_key_to_ecdsa(public_key)
|
9
|
+
|
10
|
+
event_webhook.verify_signature(
|
11
|
+
ec_public_key,
|
12
|
+
request.body.read,
|
13
|
+
request.env[SendGrid::EventWebhookHeader::SIGNATURE],
|
14
|
+
request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
|
15
|
+
)
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
# Middleware that verifies webhooks from SendGrid using the EventWebhook
|
5
|
+
# verifier.
|
6
|
+
#
|
7
|
+
# The middleware takes a public key with which to set up the request
|
8
|
+
# validator and any number of paths. When a path matches the incoming request
|
9
|
+
# path, the request will be verified using the signature and timestamp of the
|
10
|
+
# request.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# require 'rack'
|
15
|
+
# use Rack::SendGridWebhookVerification, ENV['PUBLIC_KEY'], /\/emails/
|
16
|
+
#
|
17
|
+
# The above appends this middleware to the stack, using a public key saved in
|
18
|
+
# the ENV and only against paths that match /\/emails/. If the request
|
19
|
+
# validates then it gets passed on to the action as normal. If the request
|
20
|
+
# doesn't validate then the middleware responds immediately with a 403 status.
|
21
|
+
class SendGridWebhookVerification
|
22
|
+
def initialize(app, public_key, *paths)
|
23
|
+
@app = app
|
24
|
+
@public_key = public_key
|
25
|
+
@path_regex = Regexp.union(paths)
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(env)
|
29
|
+
return @app.call(env) unless env['PATH_INFO'].match(@path_regex)
|
30
|
+
request = Rack::Request.new(env)
|
31
|
+
|
32
|
+
event_webhook = SendGrid::EventWebhook.new
|
33
|
+
ec_public_key = event_webhook.convert_public_key_to_ecdsa(@public_key)
|
34
|
+
verified = event_webhook.verify_signature(
|
35
|
+
ec_public_key,
|
36
|
+
request.body.read,
|
37
|
+
request.env[SendGrid::EventWebhookHeader::SIGNATURE],
|
38
|
+
request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
|
39
|
+
)
|
40
|
+
|
41
|
+
if verified
|
42
|
+
return @app.call(env)
|
43
|
+
else
|
44
|
+
return [
|
45
|
+
403,
|
46
|
+
{ 'Content-Type' => 'text/plain' },
|
47
|
+
['SendGrid Request Verification Failed.']
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/sendgrid-ruby.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative 'sendgrid/base_interface'
|
|
2
2
|
require_relative 'sendgrid/sendgrid'
|
3
3
|
require_relative 'sendgrid/twilio_email'
|
4
4
|
require_relative 'sendgrid/version'
|
5
|
+
require_relative 'sendgrid/helpers/eventwebhook/eventwebhook'
|
5
6
|
require_relative 'sendgrid/helpers/ip_management/ip_management'
|
6
7
|
require_relative 'sendgrid/helpers/mail/asm'
|
7
8
|
require_relative 'sendgrid/helpers/mail/attachment'
|
@@ -29,3 +30,4 @@ require_relative 'sendgrid/helpers/stats/email_stats'
|
|
29
30
|
require_relative 'sendgrid/helpers/stats/stats_response'
|
30
31
|
require_relative 'sendgrid/helpers/stats/metrics'
|
31
32
|
require_relative 'sendgrid/helpers/permissions/scope'
|
33
|
+
require_relative 'rack/sendgrid_webhook_verification'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'digest'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module SendGrid
|
6
|
+
# This class allows you to use the Event Webhook feature. Read the docs for
|
7
|
+
# more details: https://sendgrid.com/docs/for-developers/tracking-events/event
|
8
|
+
class EventWebhook
|
9
|
+
# * *Args* :
|
10
|
+
# - +public_key+ -> verification key under Mail Settings
|
11
|
+
#
|
12
|
+
def convert_public_key_to_ecdsa(public_key)
|
13
|
+
verify_engine
|
14
|
+
OpenSSL::PKey::EC.new(Base64.decode64(public_key))
|
15
|
+
end
|
16
|
+
|
17
|
+
# * *Args* :
|
18
|
+
# - +public_key+ -> elliptic curve public key
|
19
|
+
# - +payload+ -> event payload in the request body
|
20
|
+
# - +signature+ -> signature value obtained from the 'X-Twilio-Email-Event-Webhook-Signature' header
|
21
|
+
# - +timestamp+ -> timestamp value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header
|
22
|
+
def verify_signature(public_key, payload, signature, timestamp)
|
23
|
+
verify_engine
|
24
|
+
timestamped_playload = "#{timestamp}#{payload}"
|
25
|
+
payload_digest = Digest::SHA256.digest(timestamped_playload)
|
26
|
+
decoded_signature = Base64.decode64(signature)
|
27
|
+
public_key.dsa_verify_asn1(payload_digest, decoded_signature)
|
28
|
+
rescue
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify_engine
|
33
|
+
# JRuby does not fully support ECDSA: https://github.com/jruby/jruby-openssl/issues/193
|
34
|
+
if RUBY_PLATFORM == "java"
|
35
|
+
raise NotSupportedError, "Event Webhook verification is not supported by JRuby"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Error < ::RuntimeError
|
40
|
+
end
|
41
|
+
|
42
|
+
class NotSupportedError < Error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# This class lists headers that get posted to the webhook. Read the docs for
|
47
|
+
# more details: https://sendgrid.com/docs/for-developers/tracking-events/event
|
48
|
+
class EventWebhookHeader
|
49
|
+
SIGNATURE = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_SIGNATURE"
|
50
|
+
TIMESTAMP = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_TIMESTAMP"
|
51
|
+
end
|
52
|
+
end
|
data/lib/sendgrid/version.rb
CHANGED
data/sendgrid-ruby.gemspec
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Fixtures
|
4
|
+
module EventWebhook
|
5
|
+
PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEDr2LjtURuePQzplybdC+u4CwrqDqBaWjcMMsTbhdbcwHBcepxo7yAQGhHPTnlvFYPAZFceEu/1FwCM/QmGUhA=='
|
6
|
+
FAILING_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqTxd43gyp8IOEto2LdIfjRQrIbsd4SXZkLW6jDutdhXSJCWHw8REntlo7aNDthvj+y7GjUuFDb/R1NGe1OPzpA=='
|
7
|
+
SIGNATURE = 'MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH2j/0='
|
8
|
+
FAILING_SIGNATURE = 'MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH3j/0='
|
9
|
+
TIMESTAMP = '1588788367'
|
10
|
+
PAYLOAD = {
|
11
|
+
'category'=>'example_payload',
|
12
|
+
'event'=>'test_event',
|
13
|
+
'message_id'=>'message_id',
|
14
|
+
}.to_json
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
require './spec/fixtures/event_webhook'
|
4
|
+
|
5
|
+
unless RUBY_PLATFORM == 'java'
|
6
|
+
describe Rack::SendGridWebhookVerification do
|
7
|
+
let(:public_key) { Fixtures::EventWebhook::PUBLIC_KEY }
|
8
|
+
before do
|
9
|
+
@app = ->(_env) { [200, { 'Content-Type' => 'text/plain' }, ['Hello']] }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'new' do
|
13
|
+
it 'should initialize with an app, public key and a path' do
|
14
|
+
expect do
|
15
|
+
Rack::SendGridWebhookVerification.new(@app, 'ABC', /\/email/)
|
16
|
+
end.not_to raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should initialize with an app, public key and paths' do
|
20
|
+
expect do
|
21
|
+
Rack::SendGridWebhookVerification.new(@app, 'ABC', /\/email/, /\/event/)
|
22
|
+
end.not_to raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'calling against one path' do
|
27
|
+
let(:middleware) { Rack::SendGridWebhookVerification.new(@app, public_key, /\/email/) }
|
28
|
+
|
29
|
+
it "should not intercept when the path doesn't match" do
|
30
|
+
expect(SendGrid::EventWebhook).to_not receive(:new)
|
31
|
+
request = Rack::MockRequest.env_for('/login')
|
32
|
+
status, headers, body = middleware.call(request)
|
33
|
+
expect(status).to eq(200)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow a request through if it is verified' do
|
37
|
+
options = {
|
38
|
+
:input => Fixtures::EventWebhook::PAYLOAD,
|
39
|
+
'Content-Type' => "application/json"
|
40
|
+
}
|
41
|
+
options[SendGrid::EventWebhookHeader::SIGNATURE] = Fixtures::EventWebhook::SIGNATURE
|
42
|
+
options[SendGrid::EventWebhookHeader::TIMESTAMP] = Fixtures::EventWebhook::TIMESTAMP
|
43
|
+
request = Rack::MockRequest.env_for('/email', options)
|
44
|
+
status, headers, body = middleware.call(request)
|
45
|
+
expect(status).to eq(200)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should short circuit a request to 403 if there is no signature or timestamp' do
|
49
|
+
options = {
|
50
|
+
:input => Fixtures::EventWebhook::PAYLOAD,
|
51
|
+
'Content-Type' => "application/json"
|
52
|
+
}
|
53
|
+
request = Rack::MockRequest.env_for('/email', options)
|
54
|
+
status, headers, body = middleware.call(request)
|
55
|
+
expect(status).to eq(403)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should short circuit a request to 403 if the signature is incorrect' do
|
59
|
+
options = {
|
60
|
+
:input => Fixtures::EventWebhook::PAYLOAD,
|
61
|
+
'Content-Type' => "application/json"
|
62
|
+
}
|
63
|
+
options[SendGrid::EventWebhookHeader::SIGNATURE] = Fixtures::EventWebhook::FAILING_SIGNATURE
|
64
|
+
options[SendGrid::EventWebhookHeader::TIMESTAMP] = Fixtures::EventWebhook::TIMESTAMP
|
65
|
+
request = Rack::MockRequest.env_for('/email', options)
|
66
|
+
status, headers, body = middleware.call(request)
|
67
|
+
expect(status).to eq(403)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should short circuit a request to 403 if the payload is incorrect' do
|
71
|
+
options = {
|
72
|
+
:input => 'payload',
|
73
|
+
'Content-Type' => "application/json"
|
74
|
+
}
|
75
|
+
options[SendGrid::EventWebhookHeader::SIGNATURE] = Fixtures::EventWebhook::SIGNATURE
|
76
|
+
options[SendGrid::EventWebhookHeader::TIMESTAMP] = Fixtures::EventWebhook::TIMESTAMP
|
77
|
+
request = Rack::MockRequest.env_for('/email', options)
|
78
|
+
status, headers, body = middleware.call(request)
|
79
|
+
expect(status).to eq(403)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'calling with multiple paths' do
|
84
|
+
let(:middleware) { Rack::SendGridWebhookVerification.new(@app, public_key, /\/email/, /\/events/) }
|
85
|
+
|
86
|
+
it "should not intercept when the path doesn't match" do
|
87
|
+
expect(SendGrid::EventWebhook).to_not receive(:new)
|
88
|
+
request = Rack::MockRequest.env_for('/sms_events')
|
89
|
+
status, headers, body = middleware.call(request)
|
90
|
+
expect(status).to eq(200)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should allow a request through if it is verified' do
|
94
|
+
options = {
|
95
|
+
:input => Fixtures::EventWebhook::PAYLOAD,
|
96
|
+
'Content-Type' => "application/json"
|
97
|
+
}
|
98
|
+
options[SendGrid::EventWebhookHeader::SIGNATURE] = Fixtures::EventWebhook::SIGNATURE
|
99
|
+
options[SendGrid::EventWebhookHeader::TIMESTAMP] = Fixtures::EventWebhook::TIMESTAMP
|
100
|
+
request = Rack::MockRequest.env_for('/events', options)
|
101
|
+
status, headers, body = middleware.call(request)
|
102
|
+
expect(status).to eq(200)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should short circuit a request to 403 if there is no signature or timestamp' do
|
106
|
+
options = {
|
107
|
+
:input => Fixtures::EventWebhook::PAYLOAD,
|
108
|
+
'Content-Type' => "application/json"
|
109
|
+
}
|
110
|
+
request = Rack::MockRequest.env_for('/events', options)
|
111
|
+
status, headers, body = middleware.call(request)
|
112
|
+
expect(status).to eq(403)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require './spec/fixtures/event_webhook'
|
3
|
+
|
4
|
+
describe SendGrid::EventWebhook do
|
5
|
+
describe '.verify_signature' do
|
6
|
+
it 'verifies a valid signature' do
|
7
|
+
unless skip_jruby
|
8
|
+
expect(verify(
|
9
|
+
Fixtures::EventWebhook::PUBLIC_KEY,
|
10
|
+
Fixtures::EventWebhook::PAYLOAD,
|
11
|
+
Fixtures::EventWebhook::SIGNATURE,
|
12
|
+
Fixtures::EventWebhook::TIMESTAMP
|
13
|
+
)).to be true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'rejects a bad key' do
|
18
|
+
unless skip_jruby
|
19
|
+
expect(verify(
|
20
|
+
Fixtures::EventWebhook::FAILING_PUBLIC_KEY,
|
21
|
+
Fixtures::EventWebhook::PAYLOAD,
|
22
|
+
Fixtures::EventWebhook::SIGNATURE,
|
23
|
+
Fixtures::EventWebhook::TIMESTAMP
|
24
|
+
)).to be false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'rejects a bad payload' do
|
29
|
+
unless skip_jruby
|
30
|
+
expect(verify(
|
31
|
+
Fixtures::EventWebhook::PUBLIC_KEY,
|
32
|
+
'payload',
|
33
|
+
Fixtures::EventWebhook::SIGNATURE,
|
34
|
+
Fixtures::EventWebhook::TIMESTAMP
|
35
|
+
)).to be false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'rejects a bad signature' do
|
40
|
+
unless skip_jruby
|
41
|
+
expect(verify(
|
42
|
+
Fixtures::EventWebhook::PUBLIC_KEY,
|
43
|
+
Fixtures::EventWebhook::PAYLOAD,
|
44
|
+
Fixtures::EventWebhook::FAILING_SIGNATURE,
|
45
|
+
Fixtures::EventWebhook::TIMESTAMP
|
46
|
+
)).to be false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'rejects a bad timestamp' do
|
51
|
+
unless skip_jruby
|
52
|
+
expect(verify(
|
53
|
+
Fixtures::EventWebhook::PUBLIC_KEY,
|
54
|
+
Fixtures::EventWebhook::PAYLOAD,
|
55
|
+
Fixtures::EventWebhook::SIGNATURE,
|
56
|
+
'timestamp'
|
57
|
+
)).to be false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'rejects a missing signature' do
|
62
|
+
unless skip_jruby
|
63
|
+
expect(verify(
|
64
|
+
Fixtures::EventWebhook::PUBLIC_KEY,
|
65
|
+
Fixtures::EventWebhook::PAYLOAD,
|
66
|
+
nil,
|
67
|
+
Fixtures::EventWebhook::TIMESTAMP
|
68
|
+
)).to be false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'throws an error when using jruby' do
|
73
|
+
if skip_jruby
|
74
|
+
expect{ verify(
|
75
|
+
Fixtures::EventWebhook::PUBLIC_KEY,
|
76
|
+
Fixtures::EventWebhook::PAYLOAD,
|
77
|
+
Fixtures::EventWebhook::SIGNATURE,
|
78
|
+
Fixtures::EventWebhook::TIMESTAMP
|
79
|
+
)}.to raise_error(SendGrid::EventWebhook::NotSupportedError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe SendGrid::EventWebhookHeader do
|
86
|
+
it 'sets the signature header constant' do
|
87
|
+
expect(SendGrid::EventWebhookHeader::SIGNATURE).to eq("HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_SIGNATURE")
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'sets the timestamp header constant' do
|
91
|
+
expect(SendGrid::EventWebhookHeader::TIMESTAMP).to eq("HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_TIMESTAMP")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def verify(public_key, payload, signature, timestamp)
|
96
|
+
ew = SendGrid::EventWebhook.new
|
97
|
+
ec_public_key = ew.convert_public_key_to_ecdsa(public_key)
|
98
|
+
ew.verify_signature(ec_public_key, payload, signature, timestamp)
|
99
|
+
end
|
100
|
+
|
101
|
+
def skip_jruby
|
102
|
+
RUBY_PLATFORM == 'java'
|
103
|
+
end
|
@@ -32,7 +32,7 @@ class TestAPI < MiniTest::Test
|
|
32
32
|
assert_equal(test_headers, sg.request_headers)
|
33
33
|
assert_equal("v3", sg.version)
|
34
34
|
assert_equal(subuser, sg.impersonate_subuser)
|
35
|
-
assert_equal("6.
|
35
|
+
assert_equal("6.3.1", SendGrid::VERSION)
|
36
36
|
assert_instance_of(SendGrid::Client, sg.client)
|
37
37
|
end
|
38
38
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elmer Thomas
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-06-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_http_client
|
@@ -130,6 +130,20 @@ dependencies:
|
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '5.9'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: rack
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
133
147
|
description: Official Twilio SendGrid Gem to Interact with Twilio SendGrids API in
|
134
148
|
native Ruby
|
135
149
|
email: help@twilio.com
|
@@ -170,6 +184,7 @@ files:
|
|
170
184
|
- examples/contactdb/contactdb.rb
|
171
185
|
- examples/devices/devices.rb
|
172
186
|
- examples/geo/geo.rb
|
187
|
+
- examples/helpers/eventwebhook/example.rb
|
173
188
|
- examples/helpers/mail/example.rb
|
174
189
|
- examples/helpers/settings/example.rb
|
175
190
|
- examples/helpers/stats/example.rb
|
@@ -189,8 +204,10 @@ files:
|
|
189
204
|
- examples/user/user.rb
|
190
205
|
- gemfiles/Sinatra_1.gemfile
|
191
206
|
- gemfiles/Sinatra_2.gemfile
|
207
|
+
- lib/rack/sendgrid_webhook_verification.rb
|
192
208
|
- lib/sendgrid-ruby.rb
|
193
209
|
- lib/sendgrid/base_interface.rb
|
210
|
+
- lib/sendgrid/helpers/eventwebhook/eventwebhook.rb
|
194
211
|
- lib/sendgrid/helpers/inbound/README.md
|
195
212
|
- lib/sendgrid/helpers/inbound/app.rb
|
196
213
|
- lib/sendgrid/helpers/inbound/config.yml
|
@@ -238,6 +255,9 @@ files:
|
|
238
255
|
- lib/sendgrid/version.rb
|
239
256
|
- mail_helper_v3.md
|
240
257
|
- sendgrid-ruby.gemspec
|
258
|
+
- spec/fixtures/event_webhook.rb
|
259
|
+
- spec/rack/sendgrid_webhook_verification_spec.rb
|
260
|
+
- spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb
|
241
261
|
- spec/sendgrid/helpers/ip_management/ip_management_spec.rb
|
242
262
|
- spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb
|
243
263
|
- spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb
|
@@ -276,11 +296,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
296
|
- !ruby/object:Gem::Version
|
277
297
|
version: '0'
|
278
298
|
requirements: []
|
279
|
-
|
299
|
+
rubyforge_project:
|
300
|
+
rubygems_version: 2.7.7
|
280
301
|
signing_key:
|
281
302
|
specification_version: 4
|
282
303
|
summary: Official Twilio SendGrid Gem
|
283
304
|
test_files:
|
305
|
+
- spec/fixtures/event_webhook.rb
|
306
|
+
- spec/rack/sendgrid_webhook_verification_spec.rb
|
307
|
+
- spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb
|
284
308
|
- spec/sendgrid/helpers/ip_management/ip_management_spec.rb
|
285
309
|
- spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb
|
286
310
|
- spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb
|