Skip to content

Commit 96b73a9

Browse files
committed
Run cache-only mode in CI: real backends and a conformance run
CI never exercised authorization codes and access tokens kept in the protocol cache only: the conformance OP used FilesystemAdapter, which that mode refuses, and the tests against real Memcached and Redis servers were skipped for want of a server. - The unit job gets Memcached and Redis service containers, so CacheOnlyBackendsTest runs on every PHP version. With OIDC_TEST_BACKENDS_REQUIRED=1, set in CI, a missing server fails those tests instead of skipping them. - The conformance job runs every plan a second time with docker/docker-compose.cache-only.yml, which adds a Memcached container and switches the OP to MemcachedAdapter, with codes and access tokens kept in the cache only and the same server as the lock store. The plans pass in either mode, so a step then checks the OP's database: no authorization code, and no access token except those backing a refresh token, after the cache-only run; some of each after the database run. - "Stop SSP" now addresses the compose project that "Start SSP docker" created (--project-directory was missing, so it stopped nothing). - docker-compose.yml gives SSP_VERSION and OIDC_VERSION the Dockerfile's defaults, since an empty build argument overrode them. The docs show the cache-only command, the network and working directory the compose commands need, and link the Docker Compose section directly. Assisted-by: Claude Code (claude-opus-5-5, implementation & verification) Assisted-by: OpenAI Codex (gpt-6.2-sol, xhigh review) Assisted-by: Google Antigravity (gemini-4-neon-high, review)
1 parent 69fcdd8 commit 96b73a9

7 files changed

Lines changed: 113 additions & 11 deletions

File tree

‎.github/workflows/test.yaml‎

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
php-versions: ["8.3", "8.4", "8.5"]
17+
# Servers for the cache-only artifact tests which run against real backends (CacheOnlyBackendsTest).
18+
services:
19+
memcached:
20+
image: memcached:1.6
21+
ports:
22+
- 11211:11211
23+
redis:
24+
image: redis:7
25+
ports:
26+
- 6379:6379
1727

1828
steps:
1929
- name: Setup PHP, with composer and extensions
2030
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
2131
with:
2232
php-version: ${{ matrix.php-versions }}
23-
# memcached and redis: the cache-only artifact tests build (but never connect) clients of both.
33+
# memcached and redis: the cache-only artifact tests build clients of both, and the integration tests
34+
# connect them to the servers above.
2435
extensions: mbstring, xml, memcached, redis
2536
tools: composer:v2
2637
coverage: pcov
@@ -66,6 +77,11 @@ jobs:
6677
./vendor/bin/phpunit $NO_COVERAGE
6778
6879
- name: Run integration tests
80+
env:
81+
OIDC_TEST_MEMCACHED_HOST: 127.0.0.1:11211
82+
OIDC_TEST_REDIS_HOST: 127.0.0.1:6379
83+
# Fail, rather than skip, the real-backend tests if a server is not given.
84+
OIDC_TEST_BACKENDS_REQUIRED: "1"
6985
run: |
7086
echo $NO_COVERAGE
7187
./vendor/bin/phpunit $NO_COVERAGE --no-configuration -c phpunit.integration.xml
@@ -208,11 +224,20 @@ jobs:
208224
run: php vendor/bin/psalm --show-info=true
209225

210226
conformance-suite:
227+
# Named, since the default name would list every matrix value, the compose file arguments included.
228+
name: Conformance suite, SSP ${{ matrix.ssp-version }}, ${{ matrix.protocol-storage }}
211229
runs-on: ubuntu-latest
212230
strategy:
213231
fail-fast: false
214232
matrix:
215233
ssp-version: ["v2.5.0"]
234+
# cache-only: authorization codes and access tokens kept in the protocol cache only, on Memcached.
235+
protocol-storage: ["database", "cache-only"]
236+
include:
237+
- protocol-storage: database
238+
compose-files: -f docker/docker-compose.yml
239+
- protocol-storage: cache-only
240+
compose-files: -f docker/docker-compose.yml -f docker/docker-compose.cache-only.yml
216241
env:
217242
SUITE_BASE_URL: https://localhost.emobix.co.uk:8443
218243
VERSION: release-v5.3.4
@@ -245,7 +270,7 @@ jobs:
245270
working-directory: ./main
246271
# Must run after conformance suite since they share a docker network.
247272
run: |
248-
SSP_VERSION=${{ matrix.ssp-version }} OIDC_VERSION=@dev docker compose -f docker/docker-compose.yml --project-directory . up -d --build
273+
SSP_VERSION=${{ matrix.ssp-version }} OIDC_VERSION=@dev docker compose ${{ matrix.compose-files }} --project-directory . up -d --build
249274
sleep 30
250275
# while ! curl -skfail https://op.local.stack-dev.cirrusidentity.com/.well-known/openid-configuration >/dev/null; do sleep 2; done
251276
- name: Run Basic conformance tests
@@ -260,6 +285,31 @@ jobs:
260285
- name: Run RP backchannel
261286
run: |
262287
./conformance-suite/scripts/run-test-plan.py "oidcc-backchannel-rp-initiated-logout-certification-test-plan[response_type=code][client_registration=static_client]" ./main/conformance-tests/conformance-back-channel-logout-ci.json
288+
- name: Check where codes and access tokens were stored
289+
working-directory: ./main
290+
# The plans pass in either mode, so they can not tell a cache-only run which fell back to the database. A
291+
# code or access token kept in the cache only never gets a database row; one stored in the database always
292+
# does. Access tokens that back a refresh token are written to the database in both modes, so only the others
293+
# are counted. Users are written in both modes (the seeded database has none), which shows the queries read
294+
# the OP's database.
295+
run: |
296+
count() {
297+
docker compose ${{ matrix.compose-files }} --project-directory . exec -T oidc-op \
298+
sqlite3 /var/simplesamlphp/data/mydb.sq3 "SELECT COUNT(*) FROM $1"
299+
}
300+
users=$(count oidc_user)
301+
codes=$(count oidc_auth_code)
302+
tokens=$(count "oidc_access_token a WHERE NOT EXISTS
303+
(SELECT 1 FROM oidc_refresh_token r WHERE r.access_token_id = a.id)")
304+
echo "User rows: $users, authorization code rows: $codes, access token rows without a refresh token: $tokens"
305+
[ "$users" -gt 0 ] || { echo "::error::No user in the database: the check does not read the OP's."; exit 1; }
306+
if [ "${{ matrix.protocol-storage }}" = "cache-only" ]; then
307+
[ "$codes" = "0" ] || { echo "::error::Codes reached the database in a cache-only run."; exit 1; }
308+
[ "$tokens" = "0" ] || { echo "::error::Access tokens reached the database in a cache-only run."; exit 1; }
309+
else
310+
[ "$codes" -gt 0 ] || { echo "::error::No code reached the database in a database run."; exit 1; }
311+
[ "$tokens" -gt 0 ] || { echo "::error::No access token reached the database in a database run."; exit 1; }
312+
fi
263313
- name: Dump OP logs
264314
if: failure()
265315
working-directory: ./main
@@ -268,11 +318,11 @@ jobs:
268318
# failed check anywhere. The reason is in the OP's log, which otherwise leaves with the container.
269319
# Same compose invocation as "Start SSP docker", so this addresses the project that step created.
270320
run: |
271-
docker compose -f docker/docker-compose.yml --project-directory . logs --no-color --tail 2000 oidc-op || true
321+
docker compose ${{ matrix.compose-files }} --project-directory . logs --no-color --tail 2000 oidc-op || true
272322
- name: Stop SSP
273323
working-directory: ./main
274324
run: |
275-
docker compose -f docker/docker-compose.yml down
325+
docker compose ${{ matrix.compose-files }} --project-directory . down
276326
- name: Stop Conformance Suite
277327
working-directory: ./conformance-suite
278328
# cleaning up errors out on removing the network, so add "|| true" to prevent that from breaking the build
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Used on top of docker-compose.yml: the OP keeps authorization codes and access tokens in the protocol cache only,
2+
# on a Memcached server which is its lock store too (docker/ssp/module_oidc.php reads OIDC_CONFORMANCE_MEMCACHED).
3+
# docker compose -f docker/docker-compose.yml -f docker/docker-compose.cache-only.yml --project-directory . up
4+
services:
5+
oidc-memcached:
6+
image: memcached:1.6
7+
oidc-op:
8+
environment:
9+
- OIDC_CONFORMANCE_MEMCACHED=oidc-memcached:11211
10+
depends_on:
11+
- oidc-memcached

‎docker/docker-compose.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ services:
1616
context: .
1717
dockerfile: docker/Dockerfile
1818
args:
19-
SSP_VERSION: "${SSP_VERSION}"
20-
OIDC_VERSION: "${OIDC_VERSION}"
19+
# Unset, the defaults of docker/Dockerfile: an empty build argument would override them.
20+
SSP_VERSION: "${SSP_VERSION:-v2.5.0}"
21+
OIDC_VERSION: "${OIDC_VERSION:-@dev}"
2122
environment:
2223
- STAGINGCOMPOSERREPOS=oidc
2324
- SSP_ADMIN_PASSWORD=secret1

‎docker/ssp/module_oidc.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,19 @@
121121
// Use defaults
122122
],
123123
];
124+
125+
// Set by docker/docker-compose.cache-only.yml: authorization codes and access tokens kept in the protocol cache only,
126+
// on this Memcached server ("host:port"), which is the lock store too.
127+
$cacheOnlyMemcached = getenv('OIDC_CONFORMANCE_MEMCACHED');
128+
if (is_string($cacheOnlyMemcached) && $cacheOnlyMemcached !== '') {
129+
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ADAPTER] = \Symfony\Component\Cache\Adapter\MemcachedAdapter::class;
130+
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ADAPTER_ARGUMENTS] = [
131+
\Symfony\Component\Cache\Adapter\MemcachedAdapter::createConnection("memcached://$cacheOnlyMemcached"),
132+
'oidcConformance',
133+
];
134+
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_ARTIFACTS] = [
135+
\SimpleSAML\Module\oidc\Codebooks\ProtocolArtifactEnum::AuthorizationCode,
136+
\SimpleSAML\Module\oidc\Codebooks\ProtocolArtifactEnum::AccessToken,
137+
];
138+
$config[ModuleConfig::OPTION_PROTOCOL_CACHE_ONLY_LOCK_STORE] = "memcached://$cacheOnlyMemcached";
139+
}

‎docs/4-oidc-docker.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,25 @@ Conformance tests are easier to run locally. See [Conformance](5-oidc-conformanc
121121

122122
Docker Compose runs multiple containers to ease testing. It builds an
123123
image containing the OIDC module. You can remove `--build` to reuse an
124-
existing container.
124+
existing container. Run the commands below from the root of this
125+
repository.
126+
127+
The containers join the conformance suite's Docker network,
128+
`conformance-suite_default`, so start the suite first (see
129+
[Conformance](5-oidc-conformance.md)). To run the OP without the suite,
130+
create the network with `docker network create conformance-suite_default`.
125131

126132
```bash
127133
# Use current branch/git checkout. Composer installs local checkout
128134
OIDC_VERSION=@dev docker-compose -f docker/docker-compose.yml --project-directory . up --build
129135

130136
# Use a specific module version
131137
OIDC_VERSION=dev-master docker-compose -f docker/docker-compose.yml --project-directory . up --build
138+
139+
# Keep authorization codes and access tokens in the protocol cache only,
140+
# on a Memcached container which is also the lock store
141+
OIDC_VERSION=@dev docker-compose -f docker/docker-compose.yml \
142+
-f docker/docker-compose.cache-only.yml --project-directory . up --build
132143
```
133144

134145
Visit the OP and verify a few clients exist:

‎docs/5-oidc-conformance.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ Next, run your SSP OIDC image.
3535
### Run SSP
3636

3737
Run SSP with OIDC on the same Docker network as the conformance tests so
38-
containers can communicate. See the "Docker Compose" section in the
39-
README for details.
38+
containers can communicate. See
39+
[Docker Compose](4-oidc-docker.md#docker-compose) for details.
40+
41+
To test with authorization codes and access tokens kept in the protocol
42+
cache only, start SSP with `docker/docker-compose.cache-only.yml` as well
43+
(the same section shows the command). CI runs every plan in both modes,
44+
and checks after a cache-only run that no authorization code reached the
45+
database, and no access token either, except those that back a refresh
46+
token.
4047

4148
### Run conformance tests (interactive)
4249

‎tests/integration/src/CacheOnly/CacheOnlyBackendsTest.php‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
/**
3838
* The checked store and the consumption gate against real backends. Skipped unless servers are given by
39-
* environment: OIDC_TEST_MEMCACHED_HOST and OIDC_TEST_REDIS_HOST, each "host" or "host:port".
39+
* environment: OIDC_TEST_MEMCACHED_HOST and OIDC_TEST_REDIS_HOST, each "host" or "host:port". With
40+
* OIDC_TEST_BACKENDS_REQUIRED=1, as CI sets it, a missing server fails the test instead.
4041
*/
4142
#[CoversClass(ProtocolCache::class)]
4243
#[CoversClass(ConsumptionGate::class)]
@@ -71,9 +72,14 @@ public static function backendProvider(): array
7172

7273
protected function hostOrSkip(string $backend): string
7374
{
74-
$host = getenv($backend === 'redis' ? 'OIDC_TEST_REDIS_HOST' : 'OIDC_TEST_MEMCACHED_HOST');
75+
$variable = $backend === 'redis' ? 'OIDC_TEST_REDIS_HOST' : 'OIDC_TEST_MEMCACHED_HOST';
76+
$host = getenv($variable);
7577

7678
if (!is_string($host) || $host === '') {
79+
// A skip would let a CI run which lost its servers pass without testing anything.
80+
if (getenv('OIDC_TEST_BACKENDS_REQUIRED') === '1') {
81+
$this->fail("No $backend server given in $variable, and OIDC_TEST_BACKENDS_REQUIRED is set.");
82+
}
7783
$this->markTestSkipped("No $backend server given.");
7884
}
7985

0 commit comments

Comments
 (0)