
      import { Temporal } from "@js-temporal/polyfill";
      import { URLPattern } from "urlpattern-polyfill";
      globalThis.addEventListener = () => {};
    
import { UrlError } from "../type-BSR-vRXo.js";
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
import "../assert-MZs1qjMx.js";
import "../assert_instance_of-DHz7EHNU.js";
import "../lookup-q8DeFAjR.js";
import "../actor-By5NMImS.js";
import "../key-B057bXm0.js";
import { verifyRequest } from "../http-CCydyMoV.js";
import { getAuthenticatedDocumentLoader } from "../authdocloader-lhbaj4KA.js";
import { mockDocumentLoader, test } from "../testing-Cqwzq9nj.js";
import "../std__assert-X-_kMxKM.js";
import { assertRejects } from "../assert_rejects-DiIiJbZn.js";
import "../assert_is_error-BPGph1Jx.js";
import "../assert_not_equals-f3m3epl3.js";
import "../assert_throws-BOO88avQ.js";
import { rsaPrivateKey2 } from "../keys-Dz9o2VwW.js";
import { esm_default } from "../esm-CIFbziGC.js";

//#region src/runtime/authdocloader.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