diff options
author | 2023-01-26 18:39:57 +0100 | |
---|---|---|
committer | 2023-01-26 12:39:57 -0500 | |
commit | 60b32d58565d87e87573eb268408293fc28ec657 (patch) | |
tree | f60f95bfb2d581f7164450e90885a08b30d98e68 /packages/integrations/node/test/url-protocol.test.js | |
parent | d47a9075bf13617fb5545aec50b46a76044bf85d (diff) | |
download | astro-60b32d58565d87e87573eb268408293fc28ec657.tar.gz astro-60b32d58565d87e87573eb268408293fc28ec657.tar.zst astro-60b32d58565d87e87573eb268408293fc28ec657.zip |
Fix `Astro.url.protocol` when using the @astrojs/node SSR adapter with HTTPS (#5992)
Diffstat (limited to 'packages/integrations/node/test/url-protocol.test.js')
-rw-r--r-- | packages/integrations/node/test/url-protocol.test.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/packages/integrations/node/test/url-protocol.test.js b/packages/integrations/node/test/url-protocol.test.js new file mode 100644 index 000000000..0da4bdeb0 --- /dev/null +++ b/packages/integrations/node/test/url-protocol.test.js @@ -0,0 +1,73 @@ +import { TLSSocket } from 'tls'; +import nodejs from '../dist/index.js'; +import { loadFixture, createRequestAndResponse } from './test-utils.js'; +import { expect } from 'chai'; + +describe('URL protocol', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/url-protocol/', + output: 'server', + adapter: nodejs({ mode: 'standalone' }), + }); + await fixture.build(); + }); + + it('return http when non-secure', async () => { + const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs'); + let { req, res, text } = createRequestAndResponse({ + url: '/', + }); + + handler(req, res); + req.send(); + + const html = await text(); + expect(html).to.include('http:'); + }); + + it('return https when secure', async () => { + const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs'); + let { req, res, text } = createRequestAndResponse({ + socket: new TLSSocket(), + url: '/', + }); + + handler(req, res); + req.send(); + + const html = await text(); + expect(html).to.include('https:'); + }); + + it('return http when the X-Forwarded-Proto header is set to http', async () => { + const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs'); + let { req, res, text } = createRequestAndResponse({ + headers: { 'X-Forwarded-Proto': 'http' }, + url: '/', + }); + + handler(req, res); + req.send(); + + const html = await text(); + expect(html).to.include('http:'); + }); + + it('return https when the X-Forwarded-Proto header is set to https', async () => { + const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs'); + let { req, res, text } = createRequestAndResponse({ + headers: { 'X-Forwarded-Proto': 'https' }, + url: '/', + }); + + handler(req, res); + req.send(); + + const html = await text(); + expect(html).to.include('https:'); + }); +}); |