Skip to content

Commit

Permalink
chore(http-server): set upper delay limit boundary to 5000
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Nov 27, 2024
1 parent 984511f commit 9f58663
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ describe('getHttpConfigFromRequest()', () => {
)
);
});

test('validates delay is smaller than or equal to 5000', () => {
assertLeft(getHttpConfigFromRequest({ url: { path: '/' }, headers: { prefer: 'delay=5001' } }), error =>
expect(error.name).toEqual(
'https://www.getambassador.io/docs/blackbird/latest/reference/mock-server-errors#unprocessable_entity'
)
);

assertRight(getHttpConfigFromRequest({ url: { path: '/' }, headers: { prefer: 'delay=5000' } }), parsed =>
expect(parsed).toHaveProperty('delay', 5000)
);
});
});
});
});
2 changes: 1 addition & 1 deletion packages/http-server/src/getHttpConfigFromRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PreferencesDecoder = D.partial({
delay: pipe(
D.string,
IntegerFromString,
D.refine((n): n is number => n >= 0, 'a positive integer')
D.refine((n): n is number => n >= 0 && n <= 5000, 'a positive integer smaller than or equal to 5000')
),
dynamic: pipe(D.string, BooleanFromString),
example: D.string,
Expand Down
4 changes: 2 additions & 2 deletions test-harness/specs/delay/delay_negative.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ paths:
mock -p 4010 ${document}
====command====
curl -i http://localhost:4010/widget -H "Prefer: delay=-5"
====expect-loose====
====expect====
HTTP/1.1 422 Unprocessable Entity

{"type":"https://www.getambassador.io/docs/blackbird/latest/reference/mock-server-errors#unprocessable_entity","title":"Invalid request.","status":422,"detail":"optional property \"delay\"\n└─ cannot decode -5, should be a positive integer"}
{"type":"https://www.getambassador.io/docs/blackbird/latest/reference/mock-server-errors#unprocessable_entity","title":"Invalid request.","status":422,"detail":"optional property \"delay\"\n└─ cannot decode -5, should be a positive integer smaller than or equal to 5000"}

0 comments on commit 9f58663

Please sign in to comment.