FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sendgrid-python/test/test_eventwebhook.py at main · SkillfactoryCoding/sendgrid-python · GitHub
SkillfactoryCoding
/
sendgrid-python
Public
forked from
sendgrid/sendgrid-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sendgrid-python
/
test
/
test_eventwebhook.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (42 loc) · 2.26 KB
Breadcrumbs
sendgrid-python
/
test
/
test_eventwebhook.py
Copy path
File metadata and controls
50 lines (42 loc) · 2.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import
json
import
unittest
from
sendgrid
import
EventWebhook
class
UnitTests
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
PUBLIC_KEY
=
'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=='
cls
.
SIGNATURE
=
'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM='
cls
.
TIMESTAMP
=
'1600112502'
cls
.
PAYLOAD
=
json
.
dumps
(
[
{
'email'
:
'hello@world.com'
,
'event'
:
'dropped'
,
'reason'
:
'Bounced Address'
,
'sg_event_id'
:
'ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA'
,
'sg_message_id'
:
'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0'
,
'smtp-id'
:
'<LRzXl_NHStOGhQ4kofSm_A@ismtpd0039p1iad1.sendgrid.net>'
,
'timestamp'
:
1600112492
,
}
],
sort_keys
=
True
,
separators
=
(
','
,
':'
)
)
+
'
\r
\n
'
# Be sure to include the trailing carriage return and newline!
def
test_verify_valid_signature
(
self
):
ew
=
EventWebhook
()
key
=
ew
.
convert_public_key_to_ecdsa
(
self
.
PUBLIC_KEY
)
self
.
assertTrue
(
ew
.
verify_signature
(
self
.
PAYLOAD
,
self
.
SIGNATURE
,
self
.
TIMESTAMP
,
key
))
def
test_verify_bad_key
(
self
):
ew
=
EventWebhook
(
'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqTxd43gyp8IOEto2LdIfjRQrIbsd4SXZkLW6jDutdhXSJCWHw8REntlo7aNDthvj+y7GjUuFDb/R1NGe1OPzpA=='
)
self
.
assertFalse
(
ew
.
verify_signature
(
self
.
PAYLOAD
,
self
.
SIGNATURE
,
self
.
TIMESTAMP
))
def
test_verify_bad_payload
(
self
):
ew
=
EventWebhook
(
self
.
PUBLIC_KEY
)
self
.
assertFalse
(
ew
.
verify_signature
(
'payload'
,
self
.
SIGNATURE
,
self
.
TIMESTAMP
))
def
test_verify_bad_signature
(
self
):
ew
=
EventWebhook
(
self
.
PUBLIC_KEY
)
self
.
assertFalse
(
ew
.
verify_signature
(
self
.
PAYLOAD
,
'MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH3j/0='
,
self
.
TIMESTAMP
))
def
test_verify_bad_timestamp
(
self
):
ew
=
EventWebhook
(
self
.
PUBLIC_KEY
)
self
.
assertFalse
(
ew
.
verify_signature
(
self
.
PAYLOAD
,
self
.
SIGNATURE
,
'timestamp'
))
Back
|
FazBrowse Home
|
New Git URL