Skip to content

Commit

Permalink
fix(next-tinacms-github): sends 500 with message if signing key is mi…
Browse files Browse the repository at this point in the history
…ssing
  • Loading branch information
ncphillips committed Aug 10, 2020
1 parent 4e89438 commit 002ce35
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/next-tinacms-github/src/github/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { apiProxy } from './proxy'

describe('apiProxy', () => {
describe('without a signing key', () => {
it('responds with status 500', async () => {
// @ts-ignore That's the point of the test.
const handler = apiProxy(undefined)
const req = {}
const res = new ResStub()

await handler(req, res)

expect(res.status).toHaveBeenCalledWith(500)
})
it('sends JSON response', async () => {
// @ts-ignore That's the point of the test.
const handler = apiProxy(undefined)
const req = {}
const res = new ResStub()

await handler(req, res)

expect(res.json).toHaveBeenCalled()
})
})
})

class ResStub {
status = jest.fn(() => this)
json = jest.fn()
}
6 changes: 6 additions & 0 deletions packages/next-tinacms-github/src/github/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { AES, enc } from 'crypto-js'
import axios from 'axios'

export const apiProxy = (signingKey: string) => (req: any, res: any) => {
if (!signingKey) {
return res.status(500).json({
message:
'next-tinacms-github: the apiProxy was created without a signing key.',
})
}
const { headers, ...data } = JSON.parse(req.body)

// Parse out the amalgamated token
Expand Down

0 comments on commit 002ce35

Please sign in to comment.