Skip to content

Commit 461ec09

Browse files
Merge pull request #745 from getodk/next
Release v2024.2.1
2 parents 87bbdb3 + f7b89af commit 461ec09

File tree

8 files changed

+44
-59
lines changed

8 files changed

+44
-59
lines changed

.github/workflows/test-nginx.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
fetch-tags: true
16+
submodules: recursive
1317
- uses: actions/setup-node@v4
1418
with:
1519
node-version: 20.17.0

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ services:
108108
options:
109109
max-file: "30"
110110
pyxform:
111-
image: 'ghcr.io/getodk/pyxform-http:v2.1.0'
111+
image: 'ghcr.io/getodk/pyxform-http:v2.1.1'
112112
restart: always
113113
secrets:
114114
volumes:

test/mock-http-server/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ app.get('/reset', withStdLogging((req, res) => {
1414
res.json('OK');
1515
}));
1616

17+
app.get('/v1/reflect-headers', withStdLogging((req, res) => res.json(req.headers)));
18+
1719
app.get('/*', ok('GET'));
1820
app.post('/*', ok('POST'));
1921
// TODO add more methods as required

test/nginx-test.dockerfile

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

test/nginx.test.docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
nginx:
1717
build:
1818
context: ..
19-
dockerfile: ./test/nginx-test.dockerfile
19+
dockerfile: nginx.dockerfile
2020
depends_on:
2121
- service
2222
- enketo

test/run-tests.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ wait_for_http_response() {
2626
fi
2727
}
2828

29-
log "Checking nginx dockerfiles have same base image..."
30-
# It would be nice if Dockerfiles allowed some kind of templating which would
31-
# allow for direct sharing between the real and test nginx dockerfiles.
32-
diff <(grep FROM nginx-test.dockerfile) <(grep FROM ../nginx.dockerfile | grep -v AS)
33-
3429
log "Starting test services..."
3530
docker_compose up --build --detach
3631

test/test-nginx.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ describe('nginx config', () => {
66
resetBackendMock(),
77
]));
88

9-
it('well-known should serve from HTTP', async () => {
10-
// when
11-
const res = await fetchHttp('/.well-known/acme-challenge');
12-
13-
// then
14-
assert.equal(res.status, 301);
15-
assert.equal(res.headers.get('location'), 'https://localhost:9000/.well-known/acme-challenge');
16-
});
17-
18-
it('well-known should serve from HTTPS', async () => {
19-
// when
20-
const res = await fetchHttps('/.well-known/acme-challenge');
21-
22-
// then
23-
assert.equal(res.status, 404);
24-
});
25-
269
it('HTTP should forward to HTTPS', async () => {
2710
// when
2811
const res = await fetchHttp('/');
@@ -43,30 +26,31 @@ describe('nginx config', () => {
4326
});
4427

4528
[
46-
'/index.html',
47-
'/version.txt',
48-
].forEach(staticFile => {
29+
[ '/index.html', /<div id="app"><\/div>/ ],
30+
[ '/version.txt', /^versions:/ ],
31+
].forEach(([ staticFile, expectedContent ]) => {
4932
it(`${staticFile} file should have no-cache header`, async () => {
5033
// when
5134
const res = await fetchHttps(staticFile);
5235

5336
// then
5437
assert.equal(res.status, 200);
55-
assert.equal(await res.text(), `hi:${staticFile}\n`);
38+
assert.match(await res.text(), expectedContent);
5639
assert.equal(await res.headers.get('cache-control'), 'no-cache');
5740
});
5841
});
5942

6043
[
61-
'/should-be-cached.txt',
44+
'/blank.html',
45+
'/favicon.ico',
46+
// there's no way to predict generated asset paths, as they have cache-busting names
6247
].forEach(staticFile => {
6348
it(`${staticFile} file should not have no-cache header`, async () => {
6449
// when
6550
const res = await fetchHttps(staticFile);
6651

6752
// then
6853
assert.equal(res.status, 200);
69-
assert.equal(await res.text(), `hi:${staticFile}\n`);
7054
assert.isNull(await res.headers.get('cache-control'));
7155
});
7256
});
@@ -96,6 +80,34 @@ describe('nginx config', () => {
9680
{ method:'GET', path:'/v1/some/central-backend/path' },
9781
);
9882
});
83+
84+
it('should set x-forwarded-proto header to "https"', async () => {
85+
// when
86+
const res = await fetch(`https://localhost:9001/v1/reflect-headers`);
87+
// then
88+
assert.equal(res.status, 200);
89+
90+
// when
91+
const body = await res.json();
92+
// then
93+
assert.equal(body['x-forwarded-proto'], 'https');
94+
});
95+
96+
it('should override supplied x-forwarded-proto header', async () => {
97+
// when
98+
const res = await fetch(`https://localhost:9001/v1/reflect-headers`, {
99+
headers: {
100+
'x-forwarded-proto': 'http',
101+
},
102+
});
103+
// then
104+
assert.equal(res.status, 200);
105+
106+
// when
107+
const body = await res.json();
108+
// then
109+
assert.equal(body['x-forwarded-proto'], 'https');
110+
});
99111
});
100112

101113
function fetchHttp(path, options) {

0 commit comments

Comments
 (0)