@@ -60,7 +60,7 @@ describe('createRouter', () => {
|
||||
},
|
||||
config: new ConfigReader({
|
||||
permissions: { enabled: false },
|
||||
search: { maxPageLimit: 200 },
|
||||
search: { maxPageLimit: 200, maxTermLength: 20 },
|
||||
}),
|
||||
permissions: mockPermissionEvaluator,
|
||||
logger,
|
||||
@@ -162,6 +162,19 @@ describe('createRouter', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject term length over configured max', async () => {
|
||||
const response = await request(app).get(
|
||||
`/query?term=HelloWorld1234567890!`,
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
expect(response.body).toMatchObject({
|
||||
error: {
|
||||
message: /The term length "21" is greater than "20"/i,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('removes backend-only properties from search documents', async () => {
|
||||
mockSearchEngine.query.mockResolvedValue({
|
||||
results: [
|
||||
|
||||
@@ -82,7 +82,15 @@ export async function createRouter(
|
||||
config.getOptionalNumber('search.maxTermLength') ?? defaultMaxTermLength;
|
||||
|
||||
const requestSchema = z.object({
|
||||
term: z.string().max(maxTermLength).default(''),
|
||||
term: z
|
||||
.string()
|
||||
.refine(
|
||||
term => term.length <= maxTermLength,
|
||||
term => ({
|
||||
message: `The term length "${term.length}" is greater than "${maxTermLength}"`,
|
||||
}),
|
||||
)
|
||||
.default(''),
|
||||
filters: jsonObjectSchema.optional(),
|
||||
types: z
|
||||
.array(z.string().refine(type => Object.keys(types).includes(type)))
|
||||
|
||||
Reference in New Issue
Block a user