Skip to content

Commit

Permalink
fix(awala): Make Google PubSub push endpoints work (#232)
Browse files Browse the repository at this point in the history
We were running the content type validation too soon, using the request `Content-Type` instead of the content type of the CloudEvent.
  • Loading branch information
gnarea authored Oct 11, 2023
1 parent f5aa959 commit 2f2b99c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/awala/routes/awala.routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Awala routes', () => {
'content-type': 'INVALID_CONTENT_TYPE',
},
});
expect(response).toHaveProperty('statusCode', HTTP_STATUS_CODES.UNSUPPORTED_MEDIA_TYPE);
expect(response).toHaveProperty('statusCode', HTTP_STATUS_CODES.BAD_REQUEST);
});

test('Content type application/json should resolve to unsupported media type error', async () => {
Expand All @@ -89,7 +89,7 @@ describe('Awala routes', () => {
'content-type': 'application/json',
},
});
expect(response).toHaveProperty('statusCode', HTTP_STATUS_CODES.UNSUPPORTED_MEDIA_TYPE);
expect(response).toHaveProperty('statusCode', HTTP_STATUS_CODES.BAD_REQUEST);
});

test('Missing headers should resolve into bad request', async () => {
Expand Down
12 changes: 3 additions & 9 deletions src/awala/routes/awala.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,16 @@ const awalaEventToProcessor: {
[AwalaRequestMessageType.MEMBER_BUNDLE_REQUEST]: processMemberBundleRequest,
[AwalaRequestMessageType.MEMBER_PUBLIC_KEY_IMPORT]: processMemberKeyImportRequest,
};
const awalaRequestMessageTypeList: AwalaRequestMessageType[] =
Object.values(AwalaRequestMessageType);

export default function registerRoutes(
fastify: FastifyTypedInstance,
_opts: RouteOptions,
done: PluginDone,
): void {
fastify.removeAllContentTypeParsers();
fastify.addContentTypeParser(
awalaRequestMessageTypeList,
{ parseAs: 'buffer' },
(_request, payload, next) => {
next(null, payload);
},
);
fastify.addContentTypeParser('*', { parseAs: 'buffer' }, (_request, payload, next) => {
next(null, payload);
});

fastify.route({
method: ['POST'],
Expand Down

0 comments on commit 2f2b99c

Please sign in to comment.