e115934061
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Has been cancelled
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
const express = require('express');
|
|
const request = require('supertest');
|
|
|
|
const mockRequireRumProxyAuth = jest.fn((_req, _res, next) => next());
|
|
const mockIsRumProxyEnabled = jest.fn();
|
|
const mockProxyRumRequest = jest.fn((_req, res) => res.status(202).send());
|
|
|
|
jest.mock('~/server/middleware', () => ({
|
|
requireRumProxyAuth: (...args) => mockRequireRumProxyAuth(...args),
|
|
}));
|
|
|
|
jest.mock('@librechat/api', () => ({
|
|
getRumProxyBodyLimit: jest.fn(() => '3mb'),
|
|
isRumProxyEnabled: (...args) => mockIsRumProxyEnabled(...args),
|
|
proxyRumRequest: (...args) => mockProxyRumRequest(...args),
|
|
}));
|
|
|
|
describe('RUM proxy routes', () => {
|
|
let app;
|
|
|
|
beforeAll(() => {
|
|
const rumRouter = require('../rum');
|
|
|
|
app = express();
|
|
app.use('/api/rum', rumRouter);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
mockRequireRumProxyAuth.mockClear();
|
|
mockIsRumProxyEnabled.mockReset();
|
|
mockProxyRumRequest.mockClear();
|
|
});
|
|
|
|
it('returns 404 before auth and proxying when RUM proxy mode is disabled', async () => {
|
|
mockIsRumProxyEnabled.mockReturnValue(false);
|
|
|
|
const response = await request(app)
|
|
.post('/api/rum/v1/traces')
|
|
.set('Content-Type', 'application/x-protobuf')
|
|
.send(Buffer.from('payload'));
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(response.body).toEqual({ message: 'RUM proxy is not configured' });
|
|
expect(mockRequireRumProxyAuth).not.toHaveBeenCalled();
|
|
expect(mockProxyRumRequest).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('authenticates and proxies when RUM proxy mode is enabled', async () => {
|
|
mockIsRumProxyEnabled.mockReturnValue(true);
|
|
|
|
const response = await request(app)
|
|
.post('/api/rum/v1/traces')
|
|
.set('Content-Type', 'application/x-protobuf')
|
|
.send(Buffer.from('payload'));
|
|
|
|
expect(response.status).toBe(202);
|
|
expect(mockRequireRumProxyAuth).toHaveBeenCalledTimes(1);
|
|
expect(mockProxyRumRequest).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('uses RUM-specific auth for logs as well as traces', async () => {
|
|
mockIsRumProxyEnabled.mockReturnValue(true);
|
|
|
|
const response = await request(app)
|
|
.post('/api/rum/v1/logs')
|
|
.set('Content-Type', 'application/x-protobuf')
|
|
.send(Buffer.from('payload'));
|
|
|
|
expect(response.status).toBe(202);
|
|
expect(mockRequireRumProxyAuth).toHaveBeenCalledTimes(1);
|
|
expect(mockProxyRumRequest).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|