fix(core): Some more browser-id related fixes (no-changelog) (#9102)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-04-10 10:37:23 +02:00
committed by GitHub
parent 3e231dbfe6
commit a7108d14f9
3 changed files with 21 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ import { PUBLIC_API_REST_PATH_SEGMENT, REST_PATH_SEGMENT } from '../constants';
import type { SetupProps, TestServer } from '../types';
import { LicenseMocker } from '../license';
import { AuthService } from '@/auth/auth.service';
import type { APIRequest } from '@/requests';
/**
* Plugin to prefix a path segment into a request URL pathname.
@@ -43,11 +44,12 @@ function prefix(pathSegment: string) {
};
}
const browserId = 'test-browser-id';
function createAgent(app: express.Application, options?: { auth: boolean; user: User }) {
const agent = request.agent(app);
void agent.use(prefix(REST_PATH_SEGMENT));
if (options?.auth && options?.user) {
const token = Container.get(AuthService).issueJWT(options.user);
const token = Container.get(AuthService).issueJWT(options.user, browserId);
agent.jar.setCookie(`${AUTH_COOKIE_NAME}=${token}`);
}
return agent;
@@ -73,6 +75,10 @@ export const setupTestServer = ({
const app = express();
app.use(rawBodyReader);
app.use(cookieParser());
app.use((req: APIRequest, _, next) => {
req.browserId = browserId;
next();
});
// Mock all telemetry and logging
mockInstance(Logger);