@@ -48,6 +48,7 @@ describe("createNodeMiddleware(webhooks)", () => {
48
48
{
49
49
method : "POST" ,
50
50
headers : {
51
+ "Content-Type" : "application/json" ,
51
52
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
52
53
"X-GitHub-Event" : "push" ,
53
54
"X-Hub-Signature-256" : signatureSha256 ,
@@ -92,6 +93,7 @@ describe("createNodeMiddleware(webhooks)", () => {
92
93
{
93
94
method : "POST" ,
94
95
headers : {
96
+ "Content-Type" : "application/json" ,
95
97
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
96
98
"X-GitHub-Event" : "push" ,
97
99
"X-Hub-Signature-256" : signatureSha256 ,
@@ -106,6 +108,37 @@ describe("createNodeMiddleware(webhooks)", () => {
106
108
server . close ( ) ;
107
109
} ) ;
108
110
111
+ test ( "Handles invalid Content-Type" , async ( ) => {
112
+ const webhooks = new Webhooks ( {
113
+ secret : "mySecret" ,
114
+ } ) ;
115
+
116
+ const server = createServer ( createNodeMiddleware ( webhooks ) ) . listen ( ) ;
117
+
118
+ // @ts -expect-error complains about { port } although it's included in returned AddressInfo interface
119
+ const { port } = server . address ( ) ;
120
+ const response = await fetch (
121
+ `http://localhost:${ port } /api/github/webhooks` ,
122
+ {
123
+ method : "POST" ,
124
+ headers : {
125
+ "Content-Type" : "text/plain" ,
126
+ "X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
127
+ "X-GitHub-Event" : "push" ,
128
+ "X-Hub-Signature-256" : signatureSha256 ,
129
+ } ,
130
+ body : pushEventPayload ,
131
+ }
132
+ ) ;
133
+
134
+ await expect ( response . text ( ) ) . resolves . toBe (
135
+ '{"error":"Unsupported \\"Content-Type\\" header value. Must be \\"application/json\\""}'
136
+ ) ;
137
+ expect ( response . status ) . toEqual ( 415 ) ;
138
+
139
+ server . close ( ) ;
140
+ } ) ;
141
+
109
142
test ( "Handles invalid JSON" , async ( ) => {
110
143
const webhooks = new Webhooks ( {
111
144
secret : "mySecret" ,
@@ -121,6 +154,7 @@ describe("createNodeMiddleware(webhooks)", () => {
121
154
{
122
155
method : "POST" ,
123
156
headers : {
157
+ "Content-Type" : "application/json" ,
124
158
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
125
159
"X-GitHub-Event" : "push" ,
126
160
"X-Hub-Signature-256" : signatureSha256 ,
@@ -151,6 +185,7 @@ describe("createNodeMiddleware(webhooks)", () => {
151
185
{
152
186
method : "PUT" ,
153
187
headers : {
188
+ "Content-Type" : "application/json" ,
154
189
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
155
190
"X-GitHub-Event" : "push" ,
156
191
"X-Hub-Signature-256" : signatureSha256 ,
@@ -183,6 +218,7 @@ describe("createNodeMiddleware(webhooks)", () => {
183
218
{
184
219
method : "POST" ,
185
220
headers : {
221
+ "Content-Type" : "application/json" ,
186
222
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
187
223
// "X-GitHub-Event": "push",
188
224
"X-Hub-Signature-256" : signatureSha256 ,
@@ -219,6 +255,7 @@ describe("createNodeMiddleware(webhooks)", () => {
219
255
{
220
256
method : "POST" ,
221
257
headers : {
258
+ "Content-Type" : "application/json" ,
222
259
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
223
260
"X-GitHub-Event" : "push" ,
224
261
"X-Hub-Signature-256" : signatureSha256 ,
@@ -252,6 +289,7 @@ describe("createNodeMiddleware(webhooks)", () => {
252
289
{
253
290
method : "POST" ,
254
291
headers : {
292
+ "Content-Type" : "application/json" ,
255
293
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
256
294
"X-GitHub-Event" : "push" ,
257
295
"X-Hub-Signature-256" : signatureSha256 ,
@@ -290,6 +328,7 @@ describe("createNodeMiddleware(webhooks)", () => {
290
328
{
291
329
method : "POST" ,
292
330
headers : {
331
+ "Content-Type" : "application/json" ,
293
332
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
294
333
"X-GitHub-Event" : "push" ,
295
334
"X-Hub-Signature-256" : signatureSha256 ,
@@ -325,6 +364,7 @@ describe("createNodeMiddleware(webhooks)", () => {
325
364
{
326
365
method : "POST" ,
327
366
headers : {
367
+ "Content-Type" : "application/json" ,
328
368
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
329
369
"X-GitHub-Event" : "push" ,
330
370
"X-Hub-Signature-256" : signatureSha256 ,
@@ -413,6 +453,7 @@ describe("createNodeMiddleware(webhooks)", () => {
413
453
const response = await fetch ( `http://localhost:${ port } /test` , {
414
454
method : "POST" ,
415
455
headers : {
456
+ "Content-Type" : "application/json" ,
416
457
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
417
458
"X-GitHub-Event" : "push" ,
418
459
"X-Hub-Signature-256" : signatureSha256 ,
@@ -444,6 +485,7 @@ describe("createNodeMiddleware(webhooks)", () => {
444
485
const response = await fetch ( `http://localhost:${ port } /test` , {
445
486
method : "POST" ,
446
487
headers : {
488
+ "Content-Type" : "application/json" ,
447
489
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
448
490
"X-GitHub-Event" : "push" ,
449
491
"X-Hub-Signature-256" : signatureSha256 ,
@@ -484,6 +526,7 @@ describe("createNodeMiddleware(webhooks)", () => {
484
526
{
485
527
method : "POST" ,
486
528
headers : {
529
+ "Content-Type" : "application/json" ,
487
530
"X-GitHub-Delivery" : "123e4567-e89b-12d3-a456-426655440000" ,
488
531
"X-GitHub-Event" : "push" ,
489
532
"X-Hub-Signature-256" : signatureSha256 ,
0 commit comments