@@ -10,8 +10,7 @@ function toNormalizedJsonString(payload: object) {
10
10
11
11
const eventPayload = toNormalizedJsonString ( { foo : "bar" } ) ;
12
12
const secret = "mysecret" ;
13
- const signatureSHA1 = "sha1=640c0ea7402a3f74e1767338fa2dba243b1f2d9c" ;
14
- const signatureSHA256 =
13
+ const signature =
15
14
"sha256=e3eccac34c43c7dc1cbb905488b1b81347fcc700a7b025697a9d07862256023f" ;
16
15
17
16
describe ( "verify" , ( ) => {
@@ -51,69 +50,40 @@ describe("verify", () => {
51
50
) ;
52
51
} ) ;
53
52
54
- test ( "verify(secret, eventPayload, signatureSHA1 ) returns true for correct signature" , async ( ) => {
55
- const signatureMatches = await verify ( secret , eventPayload , signatureSHA1 ) ;
53
+ test ( "verify(secret, eventPayload, signature ) returns true for correct signature" , async ( ) => {
54
+ const signatureMatches = await verify ( secret , eventPayload , signature ) ;
56
55
expect ( signatureMatches ) . toBe ( true ) ;
57
56
} ) ;
58
57
59
- test ( "verify(secret, eventPayload, signatureSHA1) returns false for incorrect signature" , async ( ) => {
60
- const signatureMatches = await verify ( secret , eventPayload , "foo" ) ;
61
- expect ( signatureMatches ) . toBe ( false ) ;
62
- } ) ;
63
-
64
- test ( "verify(secret, eventPayload, signatureSHA1) returns false for correct secret" , async ( ) => {
65
- const signatureMatches = await verify ( "foo" , eventPayload , signatureSHA1 ) ;
66
- expect ( signatureMatches ) . toBe ( false ) ;
67
- } ) ;
68
-
69
- test ( "verify(secret, eventPayload, signatureSHA1) returns true if eventPayload contains special characters (#71)" , async ( ) => {
70
- // https://github.com/octokit/webhooks.js/issues/71
71
- const signatureMatchesLowerCaseSequence = await verify (
72
- "development" ,
73
- toNormalizedJsonString ( {
74
- foo : "Foo\n\u001b[34mbar: ♥♥♥♥♥♥♥♥\nthis-is-lost\u001b[0m\u001b[2K" ,
75
- } ) ,
76
- "sha1=82a91c5aacc9cdc2eea893bc828bd03d218df79c" ,
77
- ) ;
78
- expect ( signatureMatchesLowerCaseSequence ) . toBe ( true ) ;
79
- const signatureMatchesUpperCaseSequence = await verify (
80
- "development" ,
81
- toNormalizedJsonString ( {
82
- foo : "Foo\n\u001B[34mbar: ♥♥♥♥♥♥♥♥\nthis-is-lost\u001B[0m\u001B[2K" ,
83
- } ) ,
84
- "sha1=82a91c5aacc9cdc2eea893bc828bd03d218df79c" ,
85
- ) ;
86
- expect ( signatureMatchesUpperCaseSequence ) . toBe ( true ) ;
87
- const signatureMatchesEscapedSequence = await verify (
88
- "development" ,
89
- toNormalizedJsonString ( {
90
- foo : "\\u001b" ,
91
- } ) ,
92
- "sha1=bdae4705bdd827d026bb227817ca025b5b3a6756" ,
58
+ test ( "verify(secret, eventPayload, signature) returns true for secret provided as Buffer" , async ( ) => {
59
+ const signatureMatches = await verify (
60
+ Buffer . from ( secret ) ,
61
+ eventPayload ,
62
+ signature ,
93
63
) ;
94
- expect ( signatureMatchesEscapedSequence ) . toBe ( true ) ;
64
+ expect ( signatureMatches ) . toBe ( true ) ;
95
65
} ) ;
96
66
97
- test ( "verify(secret, eventPayload, signatureSHA256 ) returns true for correct signature" , async ( ) => {
67
+ test ( "verify(secret, eventPayload, signature ) returns false for incorrect signature" , async ( ) => {
98
68
const signatureMatches = await verify (
99
69
secret ,
100
70
eventPayload ,
101
- signatureSHA256 ,
71
+ "sha256=xxxccac34c43c7dc1cbb905488b1b81347fcc700a7b025697a9d07862256023f" ,
102
72
) ;
103
- expect ( signatureMatches ) . toBe ( true ) ;
73
+ expect ( signatureMatches ) . toBe ( false ) ;
104
74
} ) ;
105
75
106
- test ( "verify(secret, eventPayload, signatureSHA256 ) returns false for incorrect signature" , async ( ) => {
76
+ test ( "verify(secret, eventPayload, signature ) returns false for incorrect signature" , async ( ) => {
107
77
const signatureMatches = await verify ( secret , eventPayload , "foo" ) ;
108
78
expect ( signatureMatches ) . toBe ( false ) ;
109
79
} ) ;
110
80
111
- test ( "verify(secret, eventPayload, signatureSHA256 ) returns false for incorrect secret" , async ( ) => {
112
- const signatureMatches = await verify ( "foo" , eventPayload , signatureSHA256 ) ;
81
+ test ( "verify(secret, eventPayload, signature ) returns false for incorrect secret" , async ( ) => {
82
+ const signatureMatches = await verify ( "foo" , eventPayload , signature ) ;
113
83
expect ( signatureMatches ) . toBe ( false ) ;
114
84
} ) ;
115
85
116
- test ( "verify(secret, eventPayload, signatureSHA256 ) returns true if eventPayload contains special characters (#71)" , async ( ) => {
86
+ test ( "verify(secret, eventPayload, signature ) returns true if eventPayload contains special characters (#71)" , async ( ) => {
117
87
// https://github.com/octokit/webhooks.js/issues/71
118
88
const signatureMatchesLowerCaseSequence = await verify (
119
89
"development" ,
@@ -147,31 +117,31 @@ describe("verifyWithFallback", () => {
147
117
expect ( verifyWithFallback ) . toBeInstanceOf ( Function ) ;
148
118
} ) ;
149
119
150
- test ( "verifyWithFallback(secret, eventPayload, signatureSHA256 , [bogus]) returns true" , async ( ) => {
120
+ test ( "verifyWithFallback(secret, eventPayload, signature , [bogus]) returns true" , async ( ) => {
151
121
const signatureMatches = await verifyWithFallback (
152
122
secret ,
153
123
eventPayload ,
154
- signatureSHA256 ,
124
+ signature ,
155
125
[ "foo" ] ,
156
126
) ;
157
127
expect ( signatureMatches ) . toBe ( true ) ;
158
128
} ) ;
159
129
160
- test ( "verifyWithFallback(bogus, eventPayload, signatureSHA256 , [secret]) returns true" , async ( ) => {
130
+ test ( "verifyWithFallback(bogus, eventPayload, signature , [secret]) returns true" , async ( ) => {
161
131
const signatureMatches = await verifyWithFallback (
162
132
"foo" ,
163
133
eventPayload ,
164
- signatureSHA256 ,
134
+ signature ,
165
135
[ secret ] ,
166
136
) ;
167
137
expect ( signatureMatches ) . toBe ( true ) ;
168
138
} ) ;
169
139
170
- test ( "verify(bogus, eventPayload, signatureSHA256 , [bogus]) returns false" , async ( ) => {
140
+ test ( "verify(bogus, eventPayload, signature , [bogus]) returns false" , async ( ) => {
171
141
const signatureMatches = await verifyWithFallback (
172
142
"foo" ,
173
143
eventPayload ,
174
- signatureSHA256 ,
144
+ signature ,
175
145
[ "foo" ] ,
176
146
) ;
177
147
expect ( signatureMatches ) . toBe ( false ) ;
0 commit comments