From 4c84c716f398b5b793b67f972e3307215df0be87 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:47:41 +0000 Subject: [PATCH 01/54] chore(pre-commit): autoupdate hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.1.0 → 23.3.0](https://github.com/psf/black/compare/23.1.0...23.3.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index acd12a620..bdbe8cfd6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,7 +34,7 @@ repos: args: ["--maxkb=1500"] - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.3.0 hooks: - id: black types: From 3083b2432e11471712f6d6fba3d029e7b6cfa9b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 22:12:35 +0000 Subject: [PATCH 02/54] chore(deps): bump django from 4.1.7 to 4.2 in /appcontainer Bumps [django](https://github.com/django/django) from 4.1.7 to 4.2. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/4.1.7...4.2) --- updated-dependencies: - dependency-name: django dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- appcontainer/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appcontainer/requirements.txt b/appcontainer/requirements.txt index d2261cfdf..564541046 100644 --- a/appcontainer/requirements.txt +++ b/appcontainer/requirements.txt @@ -1,5 +1,5 @@ Authlib==1.2.0 -Django==4.1.7 +Django==4.2 django-csp==3.7 eligibility-api==2023.01.1 requests==2.28.2 From 693eec74df3347dca9fc49a51cbe01cfc325b6a3 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Tue, 4 Apr 2023 19:24:48 +0000 Subject: [PATCH 03/54] chore: replace deprecated `length_is` in favor of `length` filter --- benefits/enrollment/templates/enrollment/success.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefits/enrollment/templates/enrollment/success.html b/benefits/enrollment/templates/enrollment/success.html index e74c6331c..61a40e8d8 100644 --- a/benefits/enrollment/templates/enrollment/success.html +++ b/benefits/enrollment/templates/enrollment/success.html @@ -18,7 +18,7 @@

{{ page.headline }}

{% endblock inner-content %} {% block call-to-action %} - {% if page.buttons|length_is:"1" %} + {% if page.buttons|length == 1 %}

From 080b18a593fe45057abadc203ebd719db8a9baa5 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Tue, 4 Apr 2023 21:25:45 +0000 Subject: [PATCH 04/54] chore: update code for configuring static file storage replace deprecated approach with new STORAGES setting --- benefits/settings.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/benefits/settings.py b/benefits/settings.py index c93e7dd26..93fb0e9a5 100644 --- a/benefits/settings.py +++ b/benefits/settings.py @@ -196,9 +196,13 @@ def _filter_empty(ls): STATIC_URL = "/static/" STATICFILES_DIRS = [os.path.join(BASE_DIR, "benefits", "static")] # use Manifest Static Files Storage by default -STATICFILES_STORAGE = os.environ.get( - "DJANGO_STATICFILES_STORAGE", "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" -) +STORAGES = { + "staticfiles": { + "BACKEND": os.environ.get( + "DJANGO_STATICFILES_STORAGE", "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" + ) + } +} STATIC_ROOT = os.path.join(BASE_DIR, "static") # Logging configuration From dd39c120f76dddcfc3af0fd6580b37f7dcc5c216 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 5 Apr 2023 22:01:04 +0000 Subject: [PATCH 05/54] chore(deps): bump sentry-sdk from 1.18.0 to 1.19.1 in /appcontainer Bumps [sentry-sdk](https://github.com/getsentry/sentry-python) from 1.18.0 to 1.19.1. - [Release notes](https://github.com/getsentry/sentry-python/releases) - [Changelog](https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md) - [Commits](https://github.com/getsentry/sentry-python/compare/1.18.0...1.19.1) --- updated-dependencies: - dependency-name: sentry-sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- appcontainer/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appcontainer/requirements.txt b/appcontainer/requirements.txt index d2261cfdf..76daf05d1 100644 --- a/appcontainer/requirements.txt +++ b/appcontainer/requirements.txt @@ -3,5 +3,5 @@ Django==4.1.7 django-csp==3.7 eligibility-api==2023.01.1 requests==2.28.2 -sentry-sdk==1.18.0 +sentry-sdk==1.19.1 six==1.16.0 From 0a11b5b5975a877bbc135a0348196d2debdbee0d Mon Sep 17 00:00:00 2001 From: machiko Date: Thu, 6 Apr 2023 14:22:06 -0700 Subject: [PATCH 06/54] fix(url): fix broken link in docs --- docs/use-cases/courtesy-cards.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/use-cases/courtesy-cards.md b/docs/use-cases/courtesy-cards.md index d4122cc53..840380d44 100644 --- a/docs/use-cases/courtesy-cards.md +++ b/docs/use-cases/courtesy-cards.md @@ -33,7 +33,7 @@ flowchart LR Notes: - [Eligibility Server documentation](https://docs.calitp.org/eligibility-server/) -- [More details about the Benefits architecture](../deployment/infrastructure/#architecture) +- [More details about the Benefits architecture](../../deployment/infrastructure/#architecture) - Velocity is the system MST uses to manage Courtesy Cards ## Process From 4ef33da6423c1e35c0ffd8ddb0597582f61f55c4 Mon Sep 17 00:00:00 2001 From: Machiko Yasuda Date: Fri, 7 Apr 2023 01:59:51 +0000 Subject: [PATCH 07/54] fix(Docker): set platform --- .devcontainer/Dockerfile | 2 +- appcontainer/Dockerfile | 2 +- compose.yml | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 37da0fcf9..a9f38b39c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM benefits_client:latest +FROM --platform=linux/amd64 benefits_client:latest # install devcontainer requirements COPY .devcontainer/requirements.txt .devcontainer/requirements.txt diff --git a/appcontainer/Dockerfile b/appcontainer/Dockerfile index 8165f5938..795aecbb7 100644 --- a/appcontainer/Dockerfile +++ b/appcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/cal-itp/docker-python-web:main +FROM --platform=linux/amd64 ghcr.io/cal-itp/docker-python-web:main # install python dependencies COPY appcontainer/requirements.txt requirements.txt diff --git a/compose.yml b/compose.yml index b39a881f3..6d284afd5 100644 --- a/compose.yml +++ b/compose.yml @@ -38,6 +38,7 @@ services: server: image: ghcr.io/cal-itp/eligibility-server:dev env_file: .devcontainer/server/.env.server + platform: linux/amd64 ports: - "8000" volumes: From 55ea8437bacb4ee9cd61276534f5ccbebd0d30cf Mon Sep 17 00:00:00 2001 From: Machiko Yasuda Date: Fri, 7 Apr 2023 02:10:54 +0000 Subject: [PATCH 08/54] docs(test): testing git --- docs/use-cases/college.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/use-cases/college.md b/docs/use-cases/college.md index c66564322..d949d9c8f 100644 --- a/docs/use-cases/college.md +++ b/docs/use-cases/college.md @@ -1,4 +1,4 @@ -# College Discount +# College discount We have another potential transit discount use case, which is for students/faculty/staff from the Monterey-Salinas Transit (MST) area. We will be taking [the existing program](https://mst.org/fares/overview/) where students from certain schools ride free, expanding it to faculty and staff in some cases, and allowing those riders to enroll their contactless bank (credit/debit) cards for half-price (50%) discounts during fall and winter breaks. From 4852c7a2bcd26dd9d29990bcee84054361a06d00 Mon Sep 17 00:00:00 2001 From: Machiko Yasuda Date: Fri, 7 Apr 2023 02:15:37 +0000 Subject: [PATCH 09/54] test: Test git again --- docs/use-cases/college.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/use-cases/college.md b/docs/use-cases/college.md index d949d9c8f..c66564322 100644 --- a/docs/use-cases/college.md +++ b/docs/use-cases/college.md @@ -1,4 +1,4 @@ -# College discount +# College Discount We have another potential transit discount use case, which is for students/faculty/staff from the Monterey-Salinas Transit (MST) area. We will be taking [the existing program](https://mst.org/fares/overview/) where students from certain schools ride free, expanding it to faculty and staff in some cases, and allowing those riders to enroll their contactless bank (credit/debit) cards for half-price (50%) discounts during fall and winter breaks. From 200184bb3b8250bbcf84b8ca401f418a85264571 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Fri, 7 Apr 2023 13:15:37 -0700 Subject: [PATCH 10/54] fix: try platform in compose file --- .devcontainer/Dockerfile | 2 +- appcontainer/Dockerfile | 2 +- compose.yml | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a9f38b39c..37da0fcf9 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=linux/amd64 benefits_client:latest +FROM benefits_client:latest # install devcontainer requirements COPY .devcontainer/requirements.txt .devcontainer/requirements.txt diff --git a/appcontainer/Dockerfile b/appcontainer/Dockerfile index 795aecbb7..8165f5938 100644 --- a/appcontainer/Dockerfile +++ b/appcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=linux/amd64 ghcr.io/cal-itp/docker-python-web:main +FROM ghcr.io/cal-itp/docker-python-web:main # install python dependencies COPY appcontainer/requirements.txt requirements.txt diff --git a/compose.yml b/compose.yml index 6d284afd5..c5e2dea99 100644 --- a/compose.yml +++ b/compose.yml @@ -8,6 +8,7 @@ services: dockerfile: appcontainer/Dockerfile image: benefits_client:latest env_file: .env + platform: linux/amd64 ports: - "${DJANGO_LOCAL_PORT:-8000}:8000" @@ -21,6 +22,7 @@ services: entrypoint: sleep infinity depends_on: - server + platform: linux/amd64 ports: - "${DJANGO_LOCAL_PORT:-8000}:8000" volumes: @@ -30,6 +32,7 @@ services: image: benefits_client:dev entrypoint: mkdocs command: serve --dev-addr "0.0.0.0:8001" + platform: linux/amd64 ports: - "8001" volumes: From 6a469f3597a03135f6bb6f684f760e7dd3d26169 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Apr 2023 20:50:32 +0000 Subject: [PATCH 11/54] chore(pre-commit): autoupdate hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/Riverside-Healthcare/djLint: v1.19.16 → v1.19.17](https://github.com/Riverside-Healthcare/djLint/compare/v1.19.16...v1.19.17) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bdbe8cfd6..d3ec0c7a2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,6 +61,6 @@ repos: types_or: [javascript, css] - repo: https://github.com/Riverside-Healthcare/djLint - rev: v1.19.16 + rev: v1.19.17 hooks: - id: djlint-django From 6cc41f083318ba03abef6a78f5b8563664f3d482 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Mon, 10 Apr 2023 23:39:31 +0000 Subject: [PATCH 12/54] refactor: move dependencies to pyproject.toml install using pip against local source --- .devcontainer/Dockerfile | 7 ++--- .devcontainer/requirements.txt | 4 --- .dockerignore | 1 + appcontainer/Dockerfile | 14 +++++----- appcontainer/requirements.txt | 7 ----- pyproject.toml | 47 +++++++++++++++++++++++++++++----- tests/pytest/requirements.txt | 5 ---- 7 files changed, 50 insertions(+), 35 deletions(-) delete mode 100644 .devcontainer/requirements.txt delete mode 100644 appcontainer/requirements.txt delete mode 100644 tests/pytest/requirements.txt diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 37da0fcf9..5e50a622c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,15 +1,12 @@ FROM benefits_client:latest # install devcontainer requirements -COPY .devcontainer/requirements.txt .devcontainer/requirements.txt -RUN pip install -r .devcontainer/requirements.txt +RUN pip install -e .[dev] +# docs requirements are in a separate file for the GitHub Action COPY docs/requirements.txt docs/requirements.txt RUN pip install -r docs/requirements.txt -COPY tests/pytest/requirements.txt tests/pytest/requirements.txt -RUN pip install -r tests/pytest/requirements.txt - # install pre-commit environments in throwaway Git repository # https://stackoverflow.com/a/68758943 COPY .pre-commit-config.yaml . diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt deleted file mode 100644 index adb07efea..000000000 --- a/.devcontainer/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -black -djlint -flake8 -pre-commit diff --git a/.dockerignore b/.dockerignore index 5ea37e022..c4198b1d4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,3 +5,4 @@ .flake8 .*ignore *.db +*.egg-info diff --git a/appcontainer/Dockerfile b/appcontainer/Dockerfile index 8165f5938..6366be07c 100644 --- a/appcontainer/Dockerfile +++ b/appcontainer/Dockerfile @@ -1,15 +1,15 @@ FROM ghcr.io/cal-itp/docker-python-web:main -# install python dependencies -COPY appcontainer/requirements.txt requirements.txt -RUN pip install -r requirements.txt +# upgrade pip +RUN python -m pip install --upgrade pip -# copy Django utility script +# copy source files COPY manage.py manage.py +COPY bin bin +COPY benefits benefits +COPY pyproject.toml pyproject.toml -# copy source files -COPY bin/ bin/ -COPY benefits/ benefits/ +RUN pip install -e . # ensure $USER can compile messages in the locale directories USER root diff --git a/appcontainer/requirements.txt b/appcontainer/requirements.txt deleted file mode 100644 index be66c88b3..000000000 --- a/appcontainer/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -Authlib==1.2.0 -Django==4.2 -django-csp==3.7 -eligibility-api==2023.01.1 -requests==2.28.2 -sentry-sdk==1.19.1 -six==1.16.0 diff --git a/pyproject.toml b/pyproject.toml index 08fb8aad4..1e45ad635 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,51 @@ -# NOTE: you have to use single-quoted strings in TOML for regular expressions. -# It's the equivalent of r-strings in Python. Multiline strings are treated as -# verbose regular expressions by Black. Use [ ] to denote a significant space -# character. +[build-system] +requires = ["setuptools>=64", "wheel"] +build-backend = "setuptools.build_meta" -# Configuration for black +[project] +classifiers = ["Programming Language :: Python :: 3 :: Only"] +description = "Cal-ITP Benefits is an application that enables automated eligibility verification and enrollment for transit benefits onto customers’ existing contactless bank (credit/debit) cards." +dependencies = [ + "Authlib==1.2.0", + "Django==4.2", + "django-csp==3.7", + "eligibility-api==2023.01.1", + "requests==2.28.2", + "sentry-sdk==1.19.1", + "six==1.16.0", +] +dynamic = ["version"] +keywords = ["django"] +license = { file = "LICENSE" } +name = "benefits" +readme = "README.md" +requires-python = ">=3.9" + +[project.optional-dependencies] +dev = [ + "black", + "djlint", + "flake8", + "pre-commit", + "pytest", + "pytest-cov", + "pytest-django", + "pytest-mock", + "pytest-socket", +] +[project.urls] +Code = "https://github.com/cal-itp/benefits" +Documentation = "https://docs.calitp.org/benefits" +Issues = "https://github.com/cal-itp/benefits/issues" + +# Configuration for black [tool.black] line-length = 127 target-version = ['py310'] include = '\.pyi?$' # Configuration for djlint - [tool.djlint] ignore = "H017,H031" indent = 2 @@ -22,7 +56,6 @@ preserve_blank_lines = true use_gitignore = true # Configuration for pytest - [tool.coverage.run] omit = [ "benefits/core/migrations/*" diff --git a/tests/pytest/requirements.txt b/tests/pytest/requirements.txt deleted file mode 100644 index 4743c4a37..000000000 --- a/tests/pytest/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pytest -pytest-cov -pytest-django -pytest-mock -pytest-socket From 9bd4343b2c094c4fb0c74e652bc43e2942148f8a Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Mon, 10 Apr 2023 23:42:27 +0000 Subject: [PATCH 13/54] ci: update dependabot, tests --- .github/dependabot.yml | 2 +- .github/workflows/labeler-deploy-dev.yml | 8 ++++---- .github/workflows/tests-pytest.yml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 39db2af14..96c61c651 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,7 +6,7 @@ version: 2 updates: - package-ecosystem: "pip" - directory: "/appcontainer" # main requirements.txt + directory: "/" # pyproject.toml schedule: interval: "daily" commit-message: diff --git a/.github/workflows/labeler-deploy-dev.yml b/.github/workflows/labeler-deploy-dev.yml index f2e34da5f..b2441c058 100644 --- a/.github/workflows/labeler-deploy-dev.yml +++ b/.github/workflows/labeler-deploy-dev.yml @@ -5,11 +5,11 @@ on: branches: [dev] types: [opened] paths: - - '.github/workflows/deploy-*.yml' - - 'benefits/**' - - 'bin/**' + - ".github/workflows/deploy-*.yml" + - "benefits/**" + - "bin/**" - Dockerfile - - requirements.txt + - pyproject.toml jobs: label-deployment-dev: diff --git a/.github/workflows/tests-pytest.yml b/.github/workflows/tests-pytest.yml index 120883142..0f5cc27f1 100644 --- a/.github/workflows/tests-pytest.yml +++ b/.github/workflows/tests-pytest.yml @@ -18,10 +18,10 @@ jobs: with: python-version-file: .github/workflows/.python-version cache: pip - cache-dependency-path: "**/requirements.txt" + cache-dependency-path: "**/pyproject.toml" - name: Install Python dependencies - run: pip install -r appcontainer/requirements.txt -r tests/pytest/requirements.txt + run: pip install -e .[dev] - name: Run setup run: ./bin/init.sh From 0d97c0108dd27b21466a7e1be414a96233badd4f Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Mon, 10 Apr 2023 23:51:15 +0000 Subject: [PATCH 14/54] fix: tell setuptools which package to install --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 1e45ad635..2496fc4bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,3 +66,6 @@ DJANGO_SETTINGS_MODULE = "benefits.settings" markers = [ "request_path: use with session_request to initialize with the given path", ] + +[tool.setuptools] +packages = ["benefits"] From b981af8e5fbbf35c2a2ac97e85a4513f304bf3eb Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Mon, 10 Apr 2023 23:51:44 +0000 Subject: [PATCH 15/54] chore(devcontainer): install TOML extension --- .devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 555a41401..8f192c4a0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,6 +20,7 @@ }, // Add the IDs of extensions you want installed when the container is created. "extensions": [ + "bungcip.better-toml", "batisteo.vscode-django", "bpruitt-goddard.mermaid-markdown-syntax-highlighting", "eamodio.gitlens", From 5b5b02f620dff86563b8504275878f964575fb32 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Mon, 10 Apr 2023 23:55:47 +0000 Subject: [PATCH 16/54] refactor: split dev/test extra dependencies no need for test runs to install dev packages --- .devcontainer/Dockerfile | 2 +- .github/workflows/tests-pytest.yml | 2 +- pyproject.toml | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5e50a622c..9063a1f42 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,7 @@ FROM benefits_client:latest # install devcontainer requirements -RUN pip install -e .[dev] +RUN pip install -e .[dev,test] # docs requirements are in a separate file for the GitHub Action COPY docs/requirements.txt docs/requirements.txt diff --git a/.github/workflows/tests-pytest.yml b/.github/workflows/tests-pytest.yml index 0f5cc27f1..84b4a9f58 100644 --- a/.github/workflows/tests-pytest.yml +++ b/.github/workflows/tests-pytest.yml @@ -21,7 +21,7 @@ jobs: cache-dependency-path: "**/pyproject.toml" - name: Install Python dependencies - run: pip install -e .[dev] + run: pip install -e .[test] - name: Run setup run: ./bin/init.sh diff --git a/pyproject.toml b/pyproject.toml index 2496fc4bc..f95e11102 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,8 @@ dev = [ "djlint", "flake8", "pre-commit", +] +test = [ "pytest", "pytest-cov", "pytest-django", From 6c65db82051121ed4b6a9460db96f35d0aae89a8 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Thu, 13 Apr 2023 18:56:54 +0000 Subject: [PATCH 17/54] feat(settings): enforce strict Content Security Policy * disallow base-uri * disallow object-src * disallow unsafe-inline for script-src * require nonce for script-src --- benefits/settings.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/benefits/settings.py b/benefits/settings.py index 93fb0e9a5..34baa2cfd 100644 --- a/benefits/settings.py +++ b/benefits/settings.py @@ -271,9 +271,9 @@ def _filter_empty(ls): # In particular, note that the inner single-quotes are required! # https://django-csp.readthedocs.io/en/latest/configuration.html#policy-settings -CSP_DEFAULT_SRC = ["'self'"] +CSP_BASE_URI = ["'none'"] -CSP_IMG_SRC = ["'self'", "data:"] +CSP_DEFAULT_SRC = ["'self'"] CSP_CONNECT_SRC = ["'self'", "https://api.amplitude.com/"] env_connect_src = _filter_empty(os.environ.get("DJANGO_CSP_CONNECT_SRC", "").split(",")) @@ -292,8 +292,15 @@ def _filter_empty(ls): if len(env_frame_src) > 0: CSP_FRAME_SRC = env_frame_src +CSP_IMG_SRC = ["'self'", "data:"] + +# Configuring strict Content Security Policy +# https://django-csp.readthedocs.io/en/latest/nonce.html +CSP_INCLUDE_NONCE_IN = ["script-src"] + +CSP_OBJECT_SRC = ["'none'"] + CSP_SCRIPT_SRC = [ - "'unsafe-inline'", "https://cdn.amplitude.com/libs/", "https://cdn.jsdelivr.net/", "*.littlepay.com", @@ -305,7 +312,6 @@ def _filter_empty(ls): CSP_STYLE_SRC = [ "'self'", - "'unsafe-inline'", "https://california.azureedge.net/", "https://fonts.googleapis.com/css", ] From 9b20fa70cb6c85df03811cb95d26ae73edbf0a68 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Thu, 13 Apr 2023 19:02:20 +0000 Subject: [PATCH 18/54] chore: implement nonce on + {% include "core/includes/analytics.html" with api_key=analytics.api_key uid=analytics.uid did=analytics.did %} @@ -125,9 +128,12 @@

{{ page.headline }}

But we aren't using CA State Template Javascript, so include Bootstrap directly {% endcomment %} - + - - {% if request.recaptcha %}{% endif %} + {% if request.recaptcha %} + + {% endif %} diff --git a/benefits/core/templates/core/includes/analytics.html b/benefits/core/templates/core/includes/analytics.html index bb1ef84a6..1efd2eb93 100644 --- a/benefits/core/templates/core/includes/analytics.html +++ b/benefits/core/templates/core/includes/analytics.html @@ -1,4 +1,4 @@ -