Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit 9c9e5c5

Browse files
authored
Modify proxy test to use mocked FCM API and test it in CI (#413)
* Build curl into the test sygnal image rather than requiring manual installation * Switch to mitmproxy (mitmdump) and mount CA root cert into container * Disable APNs exercise for now * Use dummy responses for FCM proxy test (so no Google account needed for testing) * curl.sh: add shebang and exec last line for exit code * Add proxy test to CI * Newsfile * Remove obsolete nginx config * Use healthchecks to determine up-ness
1 parent aad13aa commit 9c9e5c5

File tree

14 files changed

+202
-68
lines changed

14 files changed

+202
-68
lines changed

.github/workflows/docker_check.yml

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@
33
# an early source of warnings that the Dockerfile isn't right.
44
# This check also triggers when this file itself is modified.
55

6-
name: Check Docker image can be built successfully
6+
name: Docker checks
77

88
on:
99
push:
10+
branches: ["main"]
11+
12+
pull_request:
1013
paths:
14+
# changes to the container build definition
1115
- 'docker/Dockerfile'
16+
17+
# changes to this CI flow
1218
- '.github/workflows/docker_check.yml'
1319

20+
# changes to the source code or dependencies
21+
- 'pyproject.toml'
22+
- 'poetry.lock'
23+
- 'sygnal/**'
24+
25+
# changes to the proxy-test setup
26+
- 'scripts-dev/proxy-test/**'
27+
1428
permissions:
1529
contents: read
1630

1731
jobs:
1832
build:
33+
name: Build Docker image
1934
runs-on: ubuntu-latest
2035
steps:
2136
- name: Set up QEMU
@@ -24,6 +39,19 @@ jobs:
2439
with:
2540
platforms: arm64
2641

42+
# Use the containerd image store,
43+
# otherwise we can't export the multi-arch image later
44+
# https://github.com/docker/buildx/issues/59#issuecomment-2770311050
45+
- name: Set up Docker
46+
uses: docker/setup-docker-action@v4
47+
with:
48+
daemon-config: |
49+
{
50+
"features": {
51+
"containerd-snapshotter": true
52+
}
53+
}
54+
2755
- name: Set up Docker Buildx
2856
id: buildx
2957
uses: docker/setup-buildx-action@v1
@@ -43,6 +71,89 @@ jobs:
4371
with:
4472
context: .
4573
push: false
74+
load: true
75+
tags: "localhost/sygnal:latest"
4676
labels: "gitsha1=${{ github.sha }}"
4777
file: "docker/Dockerfile"
4878
platforms: linux/amd64,linux/arm64
79+
80+
cache-from: type=gha
81+
cache-to: type=gha,mode=max
82+
83+
- name: Save container image to disk
84+
run: |
85+
docker image save localhost/sygnal:latest --output ${{ runner.temp }}/sygnal_image.tar
86+
87+
# https://docs.docker.com/build/ci/github-actions/share-image-jobs/
88+
- name: Upload container image for subsequent steps
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: sygnal_image
92+
path: ${{ runner.temp }}/sygnal_image.tar
93+
retention-days: 1
94+
95+
proxytest:
96+
name: Check Proxy functionality
97+
runs-on: ubuntu-latest
98+
needs: build
99+
steps:
100+
- name: Download container image from build step
101+
uses: actions/download-artifact@v4
102+
with:
103+
name: sygnal_image
104+
path: ${{ runner.temp }}
105+
106+
- name: Load image into container engine
107+
run: |
108+
docker image load --input ${{ runner.temp }}/sygnal_image.tar
109+
110+
- uses: actions/checkout@v4.2.2
111+
112+
- name: Prepare test setup
113+
run: |
114+
scripts-dev/proxy-test/setup.sh
115+
# Chown the mitmproxy setup files to be group-owned by root,
116+
# because mitmproxy will re-number its user and group at startup,
117+
# but the group with that ID must already exist inside the container...
118+
# See: https://github.com/mitmproxy/mitmproxy/issues/6840
119+
sudo chown -R :root scripts-dev/proxy-test/mitmproxy
120+
121+
- name: Start test services in Compose file
122+
uses: hoverkraft-tech/compose-action@8be2d741e891ac9b8ac20825e6f3904149599925 # v2.2.0
123+
with:
124+
compose-file: scripts-dev/proxy-test/docker-compose.yml
125+
126+
- name: Invoke test script
127+
run: |
128+
echo "Waiting for container to be healthy"
129+
for _ in {0..10}; do
130+
sleep 1
131+
container_state=$(docker inspect sygnal | jq '.[0].State')
132+
echo "Container state: $container_state"
133+
if ! echo "$container_state" | jq --exit-status '.Status == "running"'; then
134+
echo "Container not running!"
135+
exit 1
136+
fi
137+
if echo "$container_state" | jq --exit-status '.Health.Status == "healthy"'; then
138+
echo "Container healthy!"
139+
break
140+
fi
141+
done
142+
docker exec sygnal sh /curl.sh notification-gcm.json
143+
144+
- name: Print sygnal logs
145+
if: always()
146+
run: |
147+
docker logs sygnal
148+
149+
- name: Print mitmdump logs
150+
if: always()
151+
run: |
152+
docker logs mitmdump
153+
154+
- name: Upload mitmdump output
155+
if: always()
156+
uses: actions/upload-artifact@v4
157+
with:
158+
name: proxytest_mitmdump
159+
path: scripts-dev/proxy-test/out/mitmdump_out

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ _trial_temp*
1919
/.python-version
2020
/htmlcov
2121

22+
/scripts-dev/proxy-test/out
23+
/scripts-dev/proxy-test/mitmproxy
24+
2225
.vscode/
2326
.idea/
2427
.DS_Store

CONTRIBUTING.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,28 @@ unit tests and lints in a local development environment:
273273
To test whether proxy support is working or not, a docker compose file has been
274274
provided to make things easier.
275275

276+
**Note:** `podman` and `podman compose` commands also work instead of `docker` for these steps.
277+
This may be preferable if root access is not available or desired.
278+
276279
For GCM Pushkin proxy testing follow these steps:
277-
- create a firebase project & service account
278-
- download the service account file from firebase & save to `./scripts-dev/proxy-test/service_account.json`
279-
- configure the PROJECT_ID in `./scripts-dev/proxy-test/sygnal.yaml`
280-
- build a docker image of sygnal named `sygnal`
280+
- build a docker image of sygnal named `localhost/sygnal`
281281
- cd to `./scripts-dev/proxy-test/`
282+
- **If you want to test with the real FCM service** (otherwise, skip these steps — the FCM service will be replaced with dummy responses):
283+
- create a firebase project & service account
284+
- download the service account file from firebase & save to `./scripts-dev/proxy-test/service_account.json`
285+
- configure the PROJECT_ID in `./scripts-dev/proxy-test/sygnal.yaml`
286+
- comment out the `map-local` lines in `docker-compose.yaml`
287+
- run `./setup.sh`
282288
- run `docker compose up`
283289
- in another terminal, run `docker exec -it sygnal bash`
284-
- run `apt update && apt install curl -y`
285-
- run `chmod +x curl.sh`
286290
- run `./curl.sh`
287-
- you can tell if the proxy is **NOT** working by inspecting the sygnal logs & seeing something along the lines of "Network is unreachable" or DNS resolution/proxy errors
288-
- you cal tell if the proxy is working by inspecting the sygnal logs & seeing the following error from firebase '"code": 400, "message": "The registration token is not a valid FCM registration token"'
289-
- this is due to the `pushkey` being set to PUSHKEY_HERE in `notification.json`
290-
- if you want to fully test an actual notification, you will have to update this value in `./scripts-dev/proxy-test/notification.json` before calling `docker compose up`
291+
- **If you are testing with the dummy FCM responses (default):**
292+
- expect to see a 200 OK response from Sygnal. If you get one, the proxy must be working.
293+
- **If you are testing with the real FCM service**:
294+
- you can tell if the proxy is **NOT** working by inspecting the sygnal logs & seeing something along the lines of "Network is unreachable" or DNS resolution/proxy errors
295+
- you can tell if the proxy is working by inspecting the sygnal logs & seeing the following error from firebase '"code": 400, "message": "The registration token is not a valid FCM registration token"'
296+
- this is due to the `pushkey` being set to PUSHKEY_HERE in `notification.json`
297+
- if you want to fully test an actual notification, you will have to update this value in `./scripts-dev/proxy-test/notification.json` before calling `docker compose up`
291298

292299
## Updating your pull request
293300

changelog.d/413.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a CI test for Sygnal's HTTP proxy functionality.

scripts-dev/proxy-test/curl.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#!/bin/sh
2+
13
if [ "$#" -ne 1 ]; then
24
echo "Usage: $0 <notification_file>"
35
exit 1
46
fi
57

6-
curl -i -H "Content-Type: application/json" --request POST -d @$1 http://localhost:5000/_matrix/push/v1/notify
8+
exec curl --fail -i -H "Content-Type: application/json" --request POST -d @$1 http://localhost:5000/_matrix/push/v1/notify

scripts-dev/proxy-test/docker-compose.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
services:
22
sygnal:
3-
image: sygnal
3+
image: localhost/sygnal-with-curl
4+
build:
5+
dockerfile: sygnal-with-curl.Dockerfile
46
networks:
57
no-internet:
68
ipv4_address: 172.28.0.2
@@ -11,19 +13,28 @@ services:
1113
- ./curl.sh:/curl.sh
1214
- ./notification-gcm.json:/notification-gcm.json
1315
- ./notification-ios.json:/notification-ios.json
14-
- ./proxy.conf:/etc/apt/apt.conf.d/proxy.conf
16+
- ./mitmproxy:/mitmproxy:ro
17+
environment:
18+
SSL_CERT_FILE: /mitmproxy/ca.crt
1519
ports:
1620
- 5000:5000
1721

1822
proxy:
19-
image: dominikbechstein/nginx-forward-proxy
23+
image: docker.io/mitmproxy/mitmproxy
24+
command: >-
25+
mitmdump
26+
-w /out/mitmdump_out
27+
--map-local '|https://oauth2.googleapis.com/token|/responses/oauth2_googleapis_token.json'
28+
--map-local '|https://fcm.googleapis.com/v1/projects/*|/responses/fcm_push.json'
2029
networks:
2130
no-internet:
2231
ipv4_address: 172.28.0.3
2332
internet:
24-
container_name: nginx-forward-proxy
33+
container_name: mitmdump
2534
volumes:
26-
- ./nginx.conf:/usr/local/nginx/conf/nginx.conf:ro
35+
- ./out:/out:Z
36+
- ./mitmproxy:/home/mitmproxy/.mitmproxy:z
37+
- ./responses:/responses:ro
2738
ports:
2839
- 8080:8080
2940

scripts-dev/proxy-test/nginx.conf

Lines changed: 0 additions & 44 deletions
This file was deleted.

scripts-dev/proxy-test/proxy.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"access_token": "DUMMY_ACCESS_TOKEN", "refresh_token": "DUMMY_REFRESH_TOKEN", "expires_in": 86400}

0 commit comments

Comments
 (0)