Skip to content

Commit

Permalink
test-nginx: assert x-forwarded-proto header is always https (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Oct 7, 2024
1 parent 87bbdb3 commit 5c4d261
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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: 28 additions & 0 deletions test/test-nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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 5c4d261

Please sign in to comment.