diff --git a/test/tests/integration/middleware/ratelimit.test.ts b/test/tests/integration/middleware/ratelimit.test.ts index 596ff603..8acb4b16 100644 --- a/test/tests/integration/middleware/ratelimit.test.ts +++ b/test/tests/integration/middleware/ratelimit.test.ts @@ -1,11 +1,15 @@ +import fs from 'node:fs'; import type { Server } from 'node:http'; import request, { type Response } from 'supertest'; import requestIp from 'request-ip'; import type { RateLimiterRedis } from 'rate-limiter-flexible'; import { expect } from 'chai'; +import nock from 'nock'; import type { Socket } from 'socket.io-client'; import { getTestServer, addFakeProbe, deleteFakeProbe } from '../../../utils/server.js'; +const nockMocks = JSON.parse(fs.readFileSync('./test/mocks/nock-geoip.json').toString()) as Record; + describe('rate limiter', () => { let app: Server; let requestAgent: any; @@ -25,18 +29,23 @@ describe('rate limiter', () => { const rateLimiter = await import('../../../../src/lib/ratelimiter.js'); rateLimiterInstance = rateLimiter.default; + + nock('https://globalping-geoip.global.ssl.fastly.net').get(/.*/).reply(200, nockMocks['01.00'].fastly); + nock('https://ipinfo.io').get(/.*/).reply(200, nockMocks['01.00'].ipinfo); + nock('https://geoip.maxmind.com/geoip/v2.1/city/').get(/.*/).reply(200, nockMocks['01.00'].maxmind); probe = await addFakeProbe(); probe.emit('probe:status:update', 'ready'); }); - after(async () => { - await deleteFakeProbe(probe); - }); afterEach(async () => { await rateLimiterInstance.delete(clientIpv6); }); + after(async () => { + await deleteFakeProbe(probe); + }); + describe('headers', () => { it('should NOT include headers (GET)', async () => { const response = await requestAgent.get('/v1/').send() as Response;