mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 13:35:42 +09:00
fix(api): answer 403 when the client ip header is unparsable (#2483)
This commit is contained in:
1 parent
a036d9a2e1
commit
9a229c1b73
5 files changed
+109
-17
No files matched your search
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {AppErrorHandler} from '@fluxer/errors/src/domains/core/ErrorHandlers';
|
||||
import {MissingClientIpError} from '@fluxer/ip_utils/src/ClientIp';
|
||||
import {Hono} from 'hono';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
@@ -125,4 +126,15 @@ describe('RequestClientIp', () => {
|
||||
await app.request('http://localhost/v1/messages', {headers: {'x-forwarded-for': '203.0.113.10'}});
|
||||
expect(seen).toEqual(['203.0.113.10', null, '203.0.113.10']);
|
||||
});
|
||||
it('a missing client ip surfaces as 403 FORBIDDEN through AppErrorHandler', async () => {
|
||||
const app = new Hono<HonoEnv>();
|
||||
app.get('/v1/messages', (ctx) => {
|
||||
requireRequestClientIp(ctx);
|
||||
return ctx.text('ok');
|
||||
});
|
||||
app.onError(AppErrorHandler);
|
||||
const response = await app.request('http://localhost/v1/messages');
|
||||
expect(response.status).toBe(403);
|
||||
expect(await response.json()).toMatchObject({code: 'FORBIDDEN'});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user