Skip to content

Commit

Permalink
test-nginx: assert x-forwarded-proto header is overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Oct 6, 2024
1 parent 60b354e commit 7b7dd89
Show file tree
Hide file tree
Showing 2 changed files with 34 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
32 changes: 32 additions & 0 deletions test/test-nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,38 @@ 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
console.log('body:', body);
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
console.log('body:', body);
assert.equal(body['x-forwarded-proto'], 'https');
});
});

function fetchHttp(path, options) {
Expand Down

0 comments on commit 7b7dd89

Please sign in to comment.