From eac8ed48c5365a2f7c5a18d03d8fc2bcbe5f011e Mon Sep 17 00:00:00 2001 From: Khafra Date: Fri, 25 Oct 2024 14:47:54 -0400 Subject: [PATCH] add unsafe-url referrerPolicy test (#3772) --- test/fetch/issue-3767.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/fetch/issue-3767.js diff --git a/test/fetch/issue-3767.js b/test/fetch/issue-3767.js new file mode 100644 index 00000000000..fec7c71dbe6 --- /dev/null +++ b/test/fetch/issue-3767.js @@ -0,0 +1,30 @@ +'use strict' + +const { once } = require('node:events') +const { createServer } = require('node:http') +const { test } = require('node:test') +const { fetch } = require('../..') +const { tspl } = require('@matteo.collina/tspl') + +// https://github.com/nodejs/undici/issues/3767 +test('referrerPolicy unsafe-url is respected', async (t) => { + const { completed, deepEqual } = tspl(t, { plan: 1 }) + + const referrer = 'https://google.com/hello/world' + + const server = createServer((req, res) => { + deepEqual(req.headers.referer, referrer) + + res.end() + }).listen(0) + + t.after(server.close.bind(server)) + await once(server, 'listening') + + await fetch(`http://localhost:${server.address().port}`, { + referrer, + referrerPolicy: 'unsafe-url' + }) + + await completed +})