summaryrefslogtreecommitdiff
path: root/packages/integrations/node/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/node/test')
-rw-r--r--packages/integrations/node/test/fixtures/url-protocol/package.json9
-rw-r--r--packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro11
-rw-r--r--packages/integrations/node/test/url-protocol.test.js73
3 files changed, 93 insertions, 0 deletions
diff --git a/packages/integrations/node/test/fixtures/url-protocol/package.json b/packages/integrations/node/test/fixtures/url-protocol/package.json
new file mode 100644
index 000000000..4b0775716
--- /dev/null
+++ b/packages/integrations/node/test/fixtures/url-protocol/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/url-protocol",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "astro": "workspace:*",
+ "@astrojs/node": "workspace:*"
+ }
+}
diff --git a/packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro b/packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro
new file mode 100644
index 000000000..61fb9867b
--- /dev/null
+++ b/packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro
@@ -0,0 +1,11 @@
+---
+---
+
+<html lang="en">
+ <head>
+ <title>url-protocol</title>
+ </head>
+ <body>
+ {Astro.url.protocol}
+ </body>
+</html>
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:');
+ });
+});