summaryrefslogtreecommitdiff
path: root/packages/integrations/node/test/url-protocol.test.js
blob: a83cb2a41e12814c565a0157c591d6e02455e8a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { expect } from 'chai';
import { TLSSocket } from 'node:tls';
import nodejs from '../dist/index.js';
import { createRequestAndResponse, loadFixture } from './test-utils.js';

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:');
	});
});
elte@7.0.2'>@astrojs/svelte@7.0.2@astrojs/studio@0.1.3@astrojs/solid-js@5.0.1@astrojs/react@4.1.2@astrojs/preact@4.0.1@astrojs/mdx@4.0.3@astrojs/markdoc@0.12.4@astrojs/db@0.14.5@astrojs/alpinejs@0.4.1Gravatar Houston (Bot) 51-124/+177 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2024-12-20fix(deps): upgrade Vite (#12799)Gravatar Matt Kane 14-84/+152 2024-12-20update comment in packages/astro/src/types/public/common.ts (#12782)Gravatar Hiromasa Fujimori 2-1/+6 2024-12-19[ci] formatGravatar Matt Kane 1-4/+2 2024-12-19fix: pass raw frontmatter to when parsing markdown in glob loader (#12789)Gravatar Matt Kane 13-1/+171 2024-12-19chore: move files to `.mjs` (#12765)Gravatar Emanuele Stoppa 2-0/+0 2024-12-19chore: fix links in session errors (#12787)Gravatar Matt Kane 1-4/+4 2024-12-19[ci] release (#12762)astro@5.1.0Gravatar Houston (Bot) 33-159/+140 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>