Skip to content

Commit 2c4cc1e

Browse files
authored
Merge pull request #6 from qld-gov-au/develop
CICD, Caching, Template Overrides for theming
2 parents 3da863d + fa8c8ed commit 2c4cc1e

File tree

5 files changed

+76
-32
lines changed

5 files changed

+76
-32
lines changed

.github/workflows/test.yml

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Tests
23
on:
34
push:
@@ -6,21 +7,37 @@ on:
67
- master
78

89
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.10'
17+
- name: Install requirements
18+
run: pip install flake8 pycodestyle
19+
- name: Check syntax
20+
run: flake8
21+
922
test:
23+
needs: lint
1024
strategy:
11-
matrix:
12-
ckan-version: ["2.10", 2.9]
1325
fail-fast: false
26+
matrix:
27+
ckan-version: ["2.11", "2.10", 2.9]
28+
experimental: [false]
29+
include:
30+
- ckan-version: 'master'
31+
experimental: true #master is unstable, good to know if we are compatible or not
1432

33+
name: Test on CKAN ${{ matrix.ckan-version }}
1534
runs-on: ubuntu-latest
1635
container:
17-
# The CKAN version tag of the Solr and Postgres containers should match
18-
# the one of the container the tests run on.
19-
# You can switch this base image with a custom image tailored to your project
20-
image: openknowledge/ckan-dev:${{ matrix.ckan-version }}
36+
image: ckan/ckan-dev:${{ matrix.ckan-version }}
37+
options: --user root
2138
services:
2239
solr:
23-
image: ckan/ckan-solr:${{ matrix.ckan-version }}
40+
image: ckan/ckan-solr:${{ matrix.ckan-version }}-solr9
2441
postgres:
2542
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
2643
env:
@@ -30,7 +47,6 @@ jobs:
3047
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
3148
redis:
3249
image: redis:3
33-
3450
env:
3551
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
3652
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
@@ -39,25 +55,35 @@ jobs:
3955
CKAN_REDIS_URL: redis://redis:6379/1
4056

4157
steps:
42-
- uses: actions/checkout@v4
43-
44-
- name: Install lint requirements
45-
run: pip install flake8 pycodestyle
46-
- name: Check syntax
47-
run: flake8
48-
49-
- name: Install requirements
50-
# Install any extra requirements your extension has here (dev requirements, other extensions etc)
51-
run: |
52-
pip install -r requirements.txt
53-
pip install -r dev-requirements.txt
54-
pip install -e .
55-
- name: Setup extension
56-
# Extra initialization steps
57-
run: |
58-
# Replace default path to CKAN core config file with the one on the container
59-
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini
60-
61-
ckan -c test.ini db init
62-
- name: Run tests
63-
run: pytest --ckan-ini=test.ini --cov=ckanext.oidc_pkce --disable-warnings ckanext/oidc_pkce
58+
- uses: actions/checkout@v4
59+
continue-on-error: ${{ matrix.experimental }}
60+
61+
- if: ${{ matrix.ckan-version == 2.9 }}
62+
continue-on-error: ${{ matrix.experimental }}
63+
run: pip install "setuptools>=44.1.0,<71"
64+
- name: Install requirements
65+
continue-on-error: ${{ matrix.experimental }}
66+
# Install any extra requirements your extension has here (dev requirements, other extensions etc)
67+
run: |
68+
pip install -r requirements.txt
69+
pip install -r dev-requirements.txt
70+
pip install -e .
71+
72+
- name: Setup extension
73+
continue-on-error: ${{ matrix.experimental }}
74+
# Extra initialization steps
75+
run: |
76+
# Replace default path to CKAN core config file with the one on the container
77+
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini
78+
ckan -c test.ini db init
79+
80+
- name: Run tests
81+
continue-on-error: ${{ matrix.experimental }}
82+
run: pytest --ckan-ini=test.ini --cov=ckanext.oidc_pkce --disable-warnings ckanext/oidc_pkce --junit-xml=/tmp/artifacts/junit/results.xml
83+
84+
- name: Test Summary
85+
uses: test-summary/action@v2
86+
continue-on-error: ${{ matrix.experimental }}
87+
with:
88+
paths: "/tmp/artifacts/junit/*.xml"
89+
if: always()

ckanext/oidc_pkce/interfaces.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def get_oidc_user(self, userinfo: dict[str, Any]) -> Optional[model.User]:
5858
data["plugin_extras"] = extras
5959

6060
user_dict.update(data)
61+
user_dict.pop("name") # Username is untouched, so exclude it from the update payload.
6162
tk.get_action("user_update")({"user": admin["name"]}, user_dict)
6263

6364
signals.user_sync.send(user.id)

ckanext/oidc_pkce/templates/user/login.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
#}
55

66
{% block form %}
7+
{% block sso_form %}
78
<p><a href="{{ h.url_for('user.login') }}/oidc-pkce" class="btn btn-primary"><i class="fa fa-sign-in"></i> Log in via single sign-on</a></p>
9+
{% endblock %}
810
{{ super() }}
911
{% endblock %}
1012

1113
{% block help_register_button %}
1214
{{ super() }}
15+
{% block sso_help_register %}
1316
<a href="{{ h.url_for('user.login') }}/oidc-pkce" class="btn btn-secondary">Register via single sign-on</a>
17+
{% endblock %}
1418
{% endblock %}

ckanext/oidc_pkce/views.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from flask import Blueprint
99

1010
import ckan.plugins.toolkit as tk
11-
from ckan.common import session
11+
from ckan.plugins.toolkit import request
12+
from ckan.common import session # flask.session
1213
from ckan.plugins import PluginImplementations
1314

1415
from . import config, utils
@@ -29,8 +30,17 @@ def get_blueprints():
2930
return [bp]
3031

3132

33+
def _no_cache():
34+
# Ensure auth pages are not public cached
35+
# Alternative way, generate anon user from ckan.common import current_user
36+
request.environ[u'__no_cache__'] = True
37+
# Flag that should soon be in ckan to disable cache-control: private
38+
request.environ[u'__no_private_cache__'] = True
39+
40+
3241
@bp.route("/user/login/oidc-pkce")
3342
def login():
43+
_no_cache()
3444
verifier = utils.code_verifier()
3545
state = utils.app_state()
3646
session[SESSION_VERIFIER] = verifier
@@ -61,6 +71,7 @@ def login():
6171

6272

6373
def callback():
74+
_no_cache()
6475
# TODO: check state
6576
error = tk.request.args.get("error")
6677
state = tk.request.args.get("state")
@@ -82,7 +93,7 @@ def callback():
8293
error = "The app state does not match"
8394

8495
if error:
85-
log.error(f"Error: {error}")
96+
log.error("Error: %s", error)
8697
session[SESSION_ERROR] = error
8798
return tk.redirect_to(came_from)
8899

test.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use = config:../ckan/test-core.ini
1010
# tests here. These will override the one defined in CKAN core's test-core.ini
1111
ckan.plugins = oidc_pkce
1212

13+
ckanext.oidc_pkce.base_url = http://unit-test
14+
ckanext.oidc_pkce.client_id = unit-test
1315

1416
# Logging configuration
1517
[loggers]

0 commit comments

Comments
 (0)