feat(fn): make missing config fatal
This commit is contained in:
Родитель
aae1e7e02c
Коммит
e0487ff80e
8
index.js
8
index.js
|
@ -14,7 +14,11 @@ const EVENTS = {
|
|||
SPAM: 'spamreport'
|
||||
}
|
||||
|
||||
const { SQS_SUFFIX } = process.env
|
||||
const { AUTH, SQS_SUFFIX } = process.env
|
||||
|
||||
if (! AUTH || ! SQS_SUFFIX) {
|
||||
throw new Error('Missing config')
|
||||
}
|
||||
|
||||
const QUEUES = {
|
||||
Bounce: `fxa-email-bounce-${SQS_SUFFIX}`,
|
||||
|
@ -33,7 +37,7 @@ async function main (data) {
|
|||
// If there's a body, it's a request from the API gateway
|
||||
if (data.body) {
|
||||
// Requests from the API gateway must be authenticated
|
||||
if (! data.queryStringParameters || data.queryStringParameters.auth !== process.env.AUTH) {
|
||||
if (! data.queryStringParameters || data.queryStringParameters.auth !== AUTH) {
|
||||
return {
|
||||
statusCode: 401,
|
||||
body: 'Unauthorized',
|
||||
|
|
3
test.js
3
test.js
|
@ -18,6 +18,7 @@ suite('fxa-sendgrid-event-proxy:', () => {
|
|||
let sqs, proxy
|
||||
|
||||
setup(() => {
|
||||
process.env.AUTH = 'authentication string'
|
||||
process.env.SQS_SUFFIX = 'wibble'
|
||||
sqs = {
|
||||
push: sinon.spy()
|
||||
|
@ -466,7 +467,6 @@ suite('fxa-sendgrid-event-proxy:', () => {
|
|||
|
||||
suite('call with an authorised request object:', () => {
|
||||
setup(done => {
|
||||
process.env.AUTH = 'authentication string'
|
||||
proxy.main({
|
||||
body: JSON.stringify({
|
||||
email: 'foo@example.com',
|
||||
|
@ -512,7 +512,6 @@ suite('fxa-sendgrid-event-proxy:', () => {
|
|||
let promise
|
||||
|
||||
setup(() => {
|
||||
process.env.AUTH = 'authentication string'
|
||||
promise = proxy.main({
|
||||
body: JSON.stringify({
|
||||
email: 'foo@example.com',
|
||||
|
|
Загрузка…
Ссылка в новой задаче