Skip to content

Commit

Permalink
Merge pull request #745 from getodk/next
Browse files Browse the repository at this point in the history
Release v2024.2.1
  • Loading branch information
matthew-white authored Oct 17, 2024
2 parents 87bbdb3 + f7b89af commit 461ec09
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 59 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: 20.17.0
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ services:
options:
max-file: "30"
pyxform:
image: 'ghcr.io/getodk/pyxform-http:v2.1.0'
image: 'ghcr.io/getodk/pyxform-http:v2.1.1'
restart: always
secrets:
volumes:
Expand Down
2 changes: 2 additions & 0 deletions test/mock-http-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ app.get('/reset', withStdLogging((req, res) => {
res.json('OK');
}));

app.get('/v1/reflect-headers', withStdLogging((req, res) => res.json(req.headers)));

app.get('/*', ok('GET'));
app.post('/*', ok('POST'));
// TODO add more methods as required
Expand Down
28 changes: 0 additions & 28 deletions test/nginx-test.dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion test/nginx.test.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
nginx:
build:
context: ..
dockerfile: ./test/nginx-test.dockerfile
dockerfile: nginx.dockerfile
depends_on:
- service
- enketo
Expand Down
5 changes: 0 additions & 5 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ wait_for_http_response() {
fi
}

log "Checking nginx dockerfiles have same base image..."
# It would be nice if Dockerfiles allowed some kind of templating which would
# allow for direct sharing between the real and test nginx dockerfiles.
diff <(grep FROM nginx-test.dockerfile) <(grep FROM ../nginx.dockerfile | grep -v AS)

log "Starting test services..."
docker_compose up --build --detach

Expand Down
58 changes: 35 additions & 23 deletions test/test-nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ describe('nginx config', () => {
resetBackendMock(),
]));

it('well-known should serve from HTTP', async () => {
// when
const res = await fetchHttp('/.well-known/acme-challenge');

// then
assert.equal(res.status, 301);
assert.equal(res.headers.get('location'), 'https://localhost:9000/.well-known/acme-challenge');
});

it('well-known should serve from HTTPS', async () => {
// when
const res = await fetchHttps('/.well-known/acme-challenge');

// then
assert.equal(res.status, 404);
});

it('HTTP should forward to HTTPS', async () => {
// when
const res = await fetchHttp('/');
Expand All @@ -43,30 +26,31 @@ describe('nginx config', () => {
});

[
'/index.html',
'/version.txt',
].forEach(staticFile => {
[ '/index.html', /<div id="app"><\/div>/ ],
[ '/version.txt', /^versions:/ ],
].forEach(([ staticFile, expectedContent ]) => {
it(`${staticFile} file should have no-cache header`, async () => {
// when
const res = await fetchHttps(staticFile);

// then
assert.equal(res.status, 200);
assert.equal(await res.text(), `hi:${staticFile}\n`);
assert.match(await res.text(), expectedContent);
assert.equal(await res.headers.get('cache-control'), 'no-cache');
});
});

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

// then
assert.equal(res.status, 200);
assert.equal(await res.text(), `hi:${staticFile}\n`);
assert.isNull(await res.headers.get('cache-control'));
});
});
Expand Down Expand Up @@ -96,6 +80,34 @@ describe('nginx config', () => {
{ method:'GET', path:'/v1/some/central-backend/path' },
);
});

it('should set x-forwarded-proto header to "https"', async () => {
// when
const res = await fetch(`https://localhost:9001/v1/reflect-headers`);
// then
assert.equal(res.status, 200);

// when
const body = await res.json();
// then
assert.equal(body['x-forwarded-proto'], 'https');
});

it('should override supplied x-forwarded-proto header', async () => {
// when
const res = await fetch(`https://localhost:9001/v1/reflect-headers`, {
headers: {
'x-forwarded-proto': 'http',
},
});
// then
assert.equal(res.status, 200);

// when
const body = await res.json();
// then
assert.equal(body['x-forwarded-proto'], 'https');
});
});

function fetchHttp(path, options) {
Expand Down

0 comments on commit 461ec09

Please sign in to comment.