Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/services/domain-lists-download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync, rmSync } from "node:fs"
import { gzipSync } from "node:zlib"
import { afterEach, expect, it } from "vitest"
import { domainListsDirectory, installedPack, listFile, lookupDomains } from "../domain/domain-lists.js"
import { updateDomainLists } from "./domain-lists-download.js"
import { packHosts, updateDomainLists } from "./domain-lists-download.js"

const MANIFEST = "https://example.org/manifest.json"

Expand Down Expand Up @@ -113,3 +113,18 @@ it("refuses a manifest whose source id would write outside the pack", async () =
)
await expect(updateDomainLists({ env: process.env, fetch, manifestUrl: MANIFEST })).rejects.toThrow(/source id/)
})

it("names each host a download may reach once, the release's own included", () => {
expect(
packHosts([
"https://github.com/WireCatLabs/cli-core/releases/download/domain-lists/manifest.json",
"https://github.com/WireCatLabs/cli-core/releases/download/domain-lists-2026-11-25/ut1-sectors.txt.gz",
"https://www.stopforumspam.com/downloads/toxic_domains_whole.txt",
]),
).toEqual([
"github.com",
"release-assets.githubusercontent.com",
"objects.githubusercontent.com",
"www.stopforumspam.com",
])
})
9 changes: 7 additions & 2 deletions src/services/domain-lists-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export interface DomainListsUpdate {
const RELEASE_HOSTS = ["github.com", "release-assets.githubusercontent.com", "objects.githubusercontent.com"]
const DOWNLOAD_MS = 10 * 60_000

/** The hosts a download may reach, each once: `hostFetch` refuses a list that names one twice. */
export const packHosts = (urls: readonly string[]): string[] => [
...new Set([...RELEASE_HOSTS, ...urls.map((url) => new URL(url).hostname)]),
]

const ID = /^[a-z0-9][a-z0-9-]{0,62}$/
const SHA256 = /^[0-9a-f]{64}$/
const DOMAIN = /^[a-z0-9_]([a-z0-9_.-]*[a-z0-9])?$/
Expand Down Expand Up @@ -131,12 +136,12 @@ export const updateDomainLists = async ({
}: DomainListsUpdateOptions): Promise<DomainListsUpdate> => {
const manifest = await fetchManifest(
manifestUrl,
given ?? hostFetch({ hosts: [...RELEASE_HOSTS, new URL(manifestUrl).hostname], timeoutMs: 60_000 }),
given ?? hostFetch({ hosts: packHosts([manifestUrl]), timeoutMs: 60_000 }),
)
const get =
given ??
hostFetch({
hosts: [...RELEASE_HOSTS, ...manifest.sources.map((one) => new URL(one.url).hostname)],
hosts: packHosts(manifest.sources.map((one) => one.url)),
timeoutMs: DOWNLOAD_MS,
})
const before = installedPack(env)
Expand Down
Loading