Skip to content

Commit b2d3fd1

Browse files
committed
Update code
1 parent 06738ea commit b2d3fd1

File tree

15 files changed

+71
-44
lines changed

15 files changed

+71
-44
lines changed

.github/workflows/run-ci-cd.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
- name: Check for uncommitted changes
7979
run: |
8080
git diff --exit-code || (echo 'Unstaged changes detected. \
81-
Run `make check-all` and use `git add` to address it.' && exit 1)
81+
Run `make check` and use `git add` to address it.' && exit 1)
8282
8383
spellcheck:
8484
name: Run spell check
@@ -241,6 +241,7 @@ jobs:
241241
run: |
242242
touch frontend/.env
243243
echo "VITE_API_URL=${{ secrets.VITE_API_URL }}" >> frontend/.env
244+
echo "VITE_CSRF_URL=${{ secrets.VITE_CSRF_URL }}" >> frontend/.env
244245
echo "VITE_ENVIRONMENT=${{ secrets.VITE_ENVIRONMENT }}" >> frontend/.env
245246
echo "VITE_GRAPHQL_URL=${{ secrets.VITE_GRAPHQL_URL }}" >> frontend/.env
246247
echo "VITE_IDX_URL=${{ secrets.VITE_IDX_URL }}" >> frontend/.env
@@ -404,6 +405,7 @@ jobs:
404405
run: |
405406
touch frontend/.env
406407
echo "VITE_API_URL=${{ secrets.VITE_API_URL }}" >> frontend/.env
408+
echo "VITE_CSRF_URL=${{ secrets.VITE_CSRF_URL }}" >> frontend/.env
407409
echo "VITE_ENVIRONMENT=${{ secrets.VITE_ENVIRONMENT }}" >> frontend/.env
408410
echo "VITE_GRAPHQL_URL=${{ secrets.VITE_GRAPHQL_URL }}" >> frontend/.env
409411
echo "VITE_IDX_URL=${{ secrets.VITE_IDX_URL }}" >> frontend/.env

.github/workflows/test-schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Check for uncommitted changes
5050
run: |
5151
git diff --exit-code || (echo 'Unstaged changes detected. \
52-
Run `make check-all` and use `git add` to address it.' && exit 1)
52+
Run `make check` and use `git add` to address it.' && exit 1)
5353
5454
code-ql:
5555
name: CodeQL

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Please follow these contribution guidelines for OWASP Schema-related changes:
234234
Nest enforces code quality standards to ensure consistency and maintainability. You can run automated checks locally before pushing your changes:
235235
236236
```bash
237-
make check-all
237+
make check
238238
```
239239
240240
This command runs linters and other static analysis tools for both the frontend and backend.
@@ -245,7 +245,7 @@ This command runs linters and other static analysis tools for both the frontend
245245
Our CI/CD pipelines automatically run tests against every Pull Request. You can run tests locally before submitting a PR:
246246

247247
```bash
248-
make test-all
248+
make test
249249
```
250250

251251
This command runs tests and checks that coverage threshold requirements are satisfied for both backend and frontend.
@@ -286,7 +286,7 @@ git checkout -b feature/my-feature-name
286286
- Run the code quality checks and tests:
287287
288288
```bash
289-
make check-test-all
289+
make check-test
290290
```
291291
292292
- Write meaningful commit messages:

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ include schema/Makefile
77
build:
88
@docker compose build
99

10-
check-all: \
10+
clean: \
11+
clean-backend \
12+
clean-frontend \
13+
clean-schema
14+
15+
check: \
1116
check-backend \
1217
check-frontend \
1318
check-spelling
1419

1520
check-backend: \
1621
pre-commit
1722

18-
check-test-all: \
19-
check-all \
20-
test-all
23+
check-test: \
24+
check \
25+
test
2126

2227
check-test-backend: \
2328
pre-commit \
@@ -33,7 +38,7 @@ pre-commit:
3338
run:
3439
@COMPOSE_BAKE=true docker compose -f docker/docker-compose-local.yaml up --build --remove-orphans
3540

36-
test-all: \
41+
test: \
3742
test-nest-app \
3843
test-schema
3944

backend/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
clean-backend:
2+
@rm -rf frontend/.cache
3+
@rm -rf frontend/.local
4+
@rm -rf frontend/.venv
5+
16
exec-backend-command:
27
@docker exec -i nest-backend $(CMD)
38

File renamed without changes.

backend/settings/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from rest_framework import routers
1414

1515
from apps.core.api.algolia import algolia_search
16-
from apps.core.api.csrf_token import get_csrf_token
16+
from apps.core.api.csrf import get_csrf_token
1717
from apps.github.api.urls import router as github_router
1818
from apps.owasp.api.urls import router as owasp_router
1919
from apps.slack.apps import SlackConfig
@@ -23,9 +23,9 @@
2323
router.registry.extend(owasp_router.registry)
2424

2525
urlpatterns = [
26+
path("csrf/", get_csrf_token),
2627
path("idx/", csrf_protect(algolia_search)),
2728
path("graphql/", csrf_protect(GraphQLView.as_view(graphiql=settings.DEBUG))),
28-
path("csrf/", get_csrf_token),
2929
path("api/v1/", include(router.urls)),
3030
path("a/", admin.site.urls),
3131
]

frontend/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ check-frontend: \
33
format-frontend-code \
44
lint-frontend-code
55

6+
clean-frontend:
7+
@rm -rf frontend/.pnpm-store
8+
@rm -rf frontend/node_modules
9+
610
exec-frontend-command:
711
@docker exec -t nest-frontend $(CMD)
812

@@ -19,8 +23,8 @@ shell-frontend:
1923
@CMD="/bin/sh" $(MAKE) exec-frontend-command-it
2024

2125
test-frontend: \
22-
test-frontend-e2e \
23-
test-frontend-unit
26+
test-frontend-unit \
27+
test-frontend-e2e
2428

2529
test-frontend-e2e:
2630
@DOCKER_BUILDKIT=1 docker build \

frontend/__tests__/unit/utils/utility.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCsrfToken } from 'utils/utility'
22

3-
jest.mock('api/getCsrfToken', () => ({
4-
getInitialCsrfToken: jest.fn(() => Promise.resolve('abc123')),
3+
jest.mock('api/fetchCsrfToken', () => ({
4+
fetchCsrfToken: jest.fn(() => Promise.resolve('abc123')),
55
}))
66

77
describe('utility tests', () => {

frontend/src/api/fetchCsrfToken.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { CSRF_URL } from 'utils/credentials'
2+
import { AppError } from 'wrappers/ErrorWrapper'
3+
4+
export const fetchCsrfToken = async (): Promise<string> => {
5+
try {
6+
const response = await fetch(CSRF_URL, {
7+
credentials: 'include',
8+
method: 'GET',
9+
})
10+
11+
if (!response.ok) {
12+
const message = `Failed to fetch CSRF token: ${response.status} ${response.statusText}`
13+
throw new AppError(response.status, message)
14+
}
15+
16+
const data = await response.json()
17+
18+
if (!data?.csrftoken) {
19+
throw new AppError(500, 'CSRF token missing in response')
20+
}
21+
22+
return data.csrftoken
23+
} catch (error) {
24+
if (error instanceof AppError) {
25+
throw error
26+
}
27+
28+
const message = error?.message || 'Unexpected error while fetching CSRF token'
29+
throw new AppError(500, message)
30+
}
31+
}

0 commit comments

Comments
 (0)