From 981651b8087afbf93ec5a3e780b0660e02685ade Mon Sep 17 00:00:00 2001 From: Berry den Hartog <38954346+berrydenhartog@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:48:22 +0200 Subject: [PATCH] Set dockerfile to use jest config --- Dockerfile | 1 + amt/api/deps.py | 2 ++ amt/middleware/csrf.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index 6e9f27cc6..622d79e99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,7 @@ COPY ./poetry.lock ./pyproject.toml ./ COPY ./package-lock.json ./package.json .nvmrc ./ COPY ./webpack.config.js ./webpack.config.prod.js ./ COPY ./tsconfig.json ./eslint.config.mjs ./ +COPY ./jest.config.ts ./ RUN mkdir -p $NVM_DIR && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash diff --git a/amt/api/deps.py b/amt/api/deps.py index 490c04dad..f99d9128a 100644 --- a/amt/api/deps.py +++ b/amt/api/deps.py @@ -69,7 +69,9 @@ def TemplateResponse( # pyright: ignore [reportIncompatibleMethodOverride] if context is None: context = {} + context["csrftoken"] = request.state.csrftoken + return super().TemplateResponse(request, name, context, status_code, headers, media_type, background) def Redirect(self, request: Request, url: str) -> HTMLResponse: diff --git a/amt/middleware/csrf.py b/amt/middleware/csrf.py index ff4290cd5..126eb863b 100644 --- a/amt/middleware/csrf.py +++ b/amt/middleware/csrf.py @@ -40,8 +40,10 @@ def _include_request(self, request: Request) -> bool: async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: signed_token = "" + if self._include_request(request): request.state.csrftoken = "" + if request.method in self.safe_methods: csrf_token, signed_token = self.csrf_protect.generate_csrf_tokens() logger.debug(f"generating tokens: csrf_token={csrf_token}, signed_token={signed_token}")