Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PoWeb): Use HTTP 422 when parcel is well-formed but invalid #501

Merged
merged 5 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"node": ">=12"
},
"devDependencies": {
"@relaycorp/relaynet-poweb": "^1.3.19",
"@relaycorp/relaynet-poweb": "^1.5.2",
"@relaycorp/shared-config": "^1.4.13",
"@relaycorp/ws-mock": "^1.5.0",
"@semantic-release/exec": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/services/poweb/parcelCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
InvalidMessageError,
ParcelDelivery,
Signer,
StreamingMode,
} from '@relaycorp/relaynet-core';
import { StreamingMode } from '@relaycorp/relaynet-poweb';
import { CloseFrame, createMockWebSocketStream, MockClient } from '@relaycorp/ws-mock';
import AbortController from 'abort-controller';
import bufferToArray from 'buffer-to-arraybuffer';
Expand Down
4 changes: 2 additions & 2 deletions src/services/poweb/parcelDelivery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ test('Malformed parcels should be refused with an HTTP 400 response', async () =
expect(fixtures.parcelStore.storeParcelFromPeerGateway).not.toBeCalled();
});

test('Well-formed yet invalid parcels should be refused with an HTTP 403 response', async () => {
test('Well-formed yet invalid parcels should be refused with an HTTP 422 response', async () => {
const logging = makeMockLogging();
const fastify = await makeServer(logging.logger);
const fixtures = getFixtures();
Expand All @@ -161,7 +161,7 @@ test('Well-formed yet invalid parcels should be refused with an HTTP 403 respons
makeAuthorizationHeaderValue(countersignature),
);

expect(response).toHaveProperty('statusCode', 403);
expect(response).toHaveProperty('statusCode', 422);
expect(JSON.parse(response.payload)).toHaveProperty('message', 'Parcel is invalid');
expect(logging.logs).toContainEqual(
partialPinoLog('info', 'Invalid parcel', {
Expand Down
2 changes: 1 addition & 1 deletion src/services/poweb/parcelDelivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default async function registerRoutes(
} catch (err) {
if (err instanceof InvalidMessageError) {
parcelAwareLogger.info({ err }, 'Invalid parcel');
return reply.code(403).send({ message: 'Parcel is invalid' });
return reply.code(422).send({ message: 'Parcel is invalid' });
}

parcelAwareLogger.error({ err }, 'Failed to save parcel');
Expand Down