
      import { Temporal } from "@js-temporal/polyfill";
      import { URLPattern } from "urlpattern-polyfill";
      globalThis.addEventListener = () => {};
    
import "../lookup-Csp1y88W.js";
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
import "../assert-MZs1qjMx.js";
import "../assert_instance_of-DHz7EHNU.js";
import "../actor-BV5H5O8U.js";
import "../key-DpaoFQ82.js";
import { verifyRequest } from "../http-CqzO68Am.js";
import { getAuthenticatedDocumentLoader } from "../docloader-C2NUa918.js";
import { mockDocumentLoader, test } from "../testing-YUoSZp2V.js";
import "../std__assert-DWivtrGR.js";
import { assertRejects } from "../assert_rejects-Ce45JcFg.js";
import "../assert_throws-BNXdRGWP.js";
import "../assert_not_equals-C80BG-_5.js";
import { rsaPrivateKey2 } from "../keys-DLwYJ_nN.js";
import { esm_default } from "../esm-DGtLO56g.js";
import { UrlError } from "@fedify/vocab-runtime";

//#region src/utils/docloader.test.ts
test("getAuthenticatedDocumentLoader()", async (t) => {
	esm_default.spyGlobal();
	esm_default.get("begin:https://example.com/object", async (cl) => {
		const v = await verifyRequest(cl.request, {
			documentLoader: mockDocumentLoader,
			contextLoader: mockDocumentLoader,
			currentTime: Temporal.Now.instant()
		});
		return new Response(JSON.stringify(v != null), { headers: { "Content-Type": "application/json" } });
	});
	await t.step("test", async () => {
		const loader = await getAuthenticatedDocumentLoader({
			keyId: new URL("https://example.com/key2"),
			privateKey: rsaPrivateKey2
		});
		assertEquals(await loader("https://example.com/object"), {
			contextUrl: null,
			documentUrl: "https://example.com/object",
			document: true
		});
	});
	esm_default.hardReset();
	await t.step("deny non-HTTP/HTTPS", async () => {
		const loader = await getAuthenticatedDocumentLoader({
			keyId: new URL("https://example.com/key2"),
			privateKey: rsaPrivateKey2
		});
		assertRejects(() => loader("ftp://localhost"), UrlError);
	});
	await t.step("deny private network", async () => {
		const loader = await getAuthenticatedDocumentLoader({
			keyId: new URL("https://example.com/key2"),
			privateKey: rsaPrivateKey2
		});
		assertRejects(() => loader("http://localhost"), UrlError);
	});
});
test("getAuthenticatedDocumentLoader() cancellation", {
	sanitizeResources: false,
	sanitizeOps: false
}, async (t) => {
	esm_default.spyGlobal();
	await t.step("document loader cancellation", async () => {
		esm_default.get("https://example.com/slow-object", () => new Promise((resolve) => {
			setTimeout(() => {
				resolve({
					status: 200,
					headers: { "Content-Type": "application/activity+json" },
					body: {
						"@context": "https://www.w3.org/ns/activitystreams",
						type: "Note",
						content: "Slow response"
					}
				});
			}, 1e3);
		}));
		const loader = getAuthenticatedDocumentLoader({
			keyId: new URL("https://example.com/key2"),
			privateKey: rsaPrivateKey2
		});
		const controller = new AbortController();
		const promise = loader("https://example.com/slow-object", { signal: controller.signal });
		controller.abort();
		await assertRejects(() => promise, Error);
		await assertRejects(() => loader("https://example.com/object", { signal: controller.signal }), Error);
	});
	await t.step("immediate cancellation", async () => {
		const loader = getAuthenticatedDocumentLoader({
			keyId: new URL("https://example.com/key2"),
			privateKey: rsaPrivateKey2
		});
		const controller = new AbortController();
		controller.abort();
		await assertRejects(() => loader("https://example.com/object", { signal: controller.signal }), Error);
	});
	esm_default.hardReset();
});

//#endregion