Files
reverse-engineering-anything/src/desktop/AptRepositoryInventory.test.ts
T
morluto b61006e114 fix(desktop): preserve effective APT one-line source identity (#12711)
Use the same APT word reader for positional fields and option assignments. Carry authored and effective repository facts through capture and replay.

Fixes #12694.
2026-11-19 21:42:39 -05:00

830 lines
28 KiB
TypeScript

import { existsSync } from "node:fs";
import { chmod, mkdir, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import {
APT_LOCATIONS,
inspectAptRepositories,
resolveAptLocations,
} from "./AptRepositoryInventory.js";
import { runHostQuery, type QueryRunner } from "./HostQuery.js";
import {
GPGV_A_ONLY,
SIGNED_BY_BOTH,
VENDOR_A,
VENDOR_B,
} from "../domain/desktop/aptKeys.fixture.js";
import { exportInstall } from "../domain/desktop/appExportInstall.js";
import {
aptListFileName,
declaredPackageFiles,
parseAptIndexTargets,
} from "../domain/desktop/aptRepositories.js";
describe.skipIf(
process.platform !== "linux" || !existsSync("/usr/bin/apt-get"),
)("repository identity from real APT targets", () => {
it.each(["list", "sources"] as const)(
"preserves commas in %s repository fields through key retention and package attribution",
async (format) => {
const root = await createTestTempDirectory("apt-source-commas-");
const sources = join(root, `vendor.${format}`);
const key = join(root, "vendor.gpg");
const lists = join(root, "lists");
await mkdir(lists);
await writeFile(key, VENDOR_A.key);
const uris = ["https://vendor.invalid/repo,stable"];
if (format === "sources") uris.push("https://mirror.invalid/repo");
const declaredUris = uris.map((uri) =>
uri.replace(
"vendor.invalid",
"fixture-user:fixture,password@vendor.invalid",
),
);
// APT continues across the indented blank line. The active deb822
// source below must still match native targets at stanza 2.
const disabled =
"Types: deb\nURIs: https://disabled.invalid/\nSuites: stable\nComponents: main\n \nEnabled: no\n\n";
await writeFile(
sources,
format === "list"
? `deb [arch=amd64,arm64 arch+=i386 arch-=arm64 signed-by=${key}] ${declaredUris[0]} stable,updates main,extra contrib\n`
: `${disabled}Types: deb\nURIs: ${declaredUris.join("/\n ")}/\nSuites: stable,updates\nComponents: main,extra contrib\nArchitectures: amd64 arm64\nArchitectures-Add: i386\nArchitectures-Remove: arm64\nSigned-By: ${key}\n`,
);
// No update, download or package installation: APT only describes the
// configured targets, with source and state paths confined to this root.
const query: QueryRunner = async (command, argv, signal, options) => {
// Key verification uses the existing captured status fixture; only
// APT's source grammar and target coordinates are exercised natively.
if (command === "gpgv") return { stdout: GPGV_A_ONLY, exitCode: 2 };
if (command !== "apt-get")
throw new Error(`Unexpected query ${command}`);
return runHostQuery(
"/usr/bin/apt-get",
[
"-o",
`Dir::Etc::sourcelist=${sources}`,
"-o",
"Dir::Etc::sourceparts=-",
"-o",
`Dir::State::lists=${lists}`,
...argv,
"--no-release-info",
],
signal,
options,
);
};
const output = await query(
"apt-get",
["indextargets", "Created-By: Packages"],
undefined,
);
if (typeof output !== "object" || output.exitCode !== 0)
throw new Error(`APT target query failed: ${JSON.stringify(output)}`);
const targets = parseAptIndexTargets(output.stdout);
expect(new Set(targets.map(({ position }) => position))).toEqual(
new Set([format === "sources" ? 2 : 1]),
);
const descriptions = targets.map((target) => target.description);
expect(descriptions).toContainEqual(
expect.stringMatching(/ i386 Packages$/u),
);
expect(descriptions).not.toContainEqual(
expect.stringMatching(/ arm64 Packages$/u),
);
const selected = targets.filter(
(target) =>
target.component === "main,extra" &&
target.description.endsWith(" amd64 Packages"),
);
expect(
selected.map((target) => target.repoUri.replace(/\/$/u, "")),
).toEqual(uris);
for (const target of selected)
await writeFile(
join(lists, `${aptListFileName(target.baseUri)}InRelease`),
SIGNED_BY_BOTH,
);
const facts = await inspectAptRepositories(
{
sources: selected.map((target) => target.description),
origins: selected.map(() => "Vendor"),
},
{ runQuery: query, apt: { lists, trustedParts: root, trusted: key } },
undefined,
);
expect(facts.repositories).toEqual(
uris.map((uri) =>
expect.objectContaining({
uri,
uri_credentials_removed: uri === uris[0],
suite: "stable,updates",
components: ["main,extra", "contrib"],
architectures: ["amd64", "i386"],
signing_key: expect.objectContaining({
path: key,
fingerprint: VENDOR_A.fingerprint,
}),
}),
),
);
expect([...facts.keys.values()]).toEqual([VENDOR_A.key]);
const captured = JSON.stringify([
facts.repositories,
...facts.indexTargets.values(),
]);
expect(captured).not.toContain("fixture-user");
expect(captured).not.toContain("fixture,password");
expect(
declaredPackageFiles(facts.repositories, facts.indexTargets),
).toEqual(
new Set(
targets
.filter(({ repoUri }) =>
repoUri.startsWith("https://mirror.invalid/"),
)
.map(({ description }) => description),
),
);
},
);
});
it.each([
[
"https://vendor.invalid/a%2Cb",
"https://vendor.invalid/a,b/",
"https://vendor.invalid/a%2Cb",
false,
],
[
"https://test-user%3Atest-secret%40vendor.invalid/a",
"https://test-user:test-secret@vendor.invalid/a/",
null,
true,
],
[
"https://test-user:test-secret@secret-suffix%40vendor.invalid/a",
"https://test-user:test-secret%40secret-suffix@vendor.invalid/a/",
null,
true,
],
[
"https://vendor.invalid/a%40b",
"https://vendor.invalid/a@b/",
"https://vendor.invalid/a%40b",
false,
],
] as const)(
"retains separate sanitized authored and observed APT URIs for %s",
async (authored, observed, retained, credentials) => {
const root = await createTestTempDirectory("apt-repo-replay-");
const file = join(root, "vendor.list");
await writeFile(file, `deb ${authored} stable main\n`);
const source = "https://vendor.invalid/a stable/main arm64 Packages";
const output = [
`Description: ${source}`,
`Sourcesentry: ${file}:1`,
`Repo-URI: ${observed}`,
"Release: stable",
"Component: main",
"Base-URI: https://vendor.invalid/dists/stable/",
`Filename: ${join(root, "Packages")}`,
].join("\n");
const runQuery: QueryRunner = async (command) => {
if (command !== "apt-get") throw new Error(`Unexpected query ${command}`);
return { stdout: output, exitCode: 0 };
};
const facts = await inspectAptRepositories(
{ sources: [source], origins: ["Vendor"] },
{
runQuery,
apt: {
lists: root,
trustedParts: root,
trusted: join(root, "trusted.gpg"),
},
},
undefined,
);
expect(facts.repositories[0]).toMatchObject({
uri: retained,
repo_uri: observed.replace(/^https:\/\/[^/]*@/u, "https://"),
uri_credentials_removed: credentials,
});
expect(JSON.stringify(facts.repositories)).not.toMatch(
/test-user|test-secret/u,
);
},
);
it.skipIf(process.platform === "win32").each([
{
authored: "ma%69n cont%72ib",
effective: ["main", "contrib"],
replayable: true,
},
{ authored: '"main extra"', effective: ["main extra"], replayable: false },
])(
"uses the same replay decision for one-line repository components $authored",
async ({ authored, effective, replayable }) => {
const root = await createTestTempDirectory("apt-list-replay-");
const file = join(root, "vendor.list");
const key = join(root, "vendor.gpg");
const uri = "https://vendor.invalid/apt";
const suite = '"st%61ble"';
const baseUri = `${uri}/dists/stable/`;
await writeFile(key, VENDOR_A.key);
await writeFile(
join(root, `${aptListFileName(baseUri)}InRelease`),
"controlled release",
);
await writeFile(
file,
`deb [signed-by=${key}] "${uri}" ${suite} ${authored}\n`,
);
const descriptions = effective.map(
(component) => `${uri} stable/${component} amd64 Packages`,
);
const output = effective
.map((component, index) =>
[
`Description: ${descriptions[index]}`,
`Sourcesentry: ${file}:1`,
`Repo-URI: ${uri}/`,
"Release: stable",
"Suite: stable",
`Component: ${component}`,
`Base-URI: ${baseUri}`,
`Filename: ${join(root, "Packages")}`,
].join("\n"),
)
.join("\n\n");
const runQuery: QueryRunner = async (command) => {
if (command === "apt-get") return { stdout: output, exitCode: 0 };
if (command === "gpgv") return { stdout: GPGV_A_ONLY, exitCode: 2 };
throw new Error(`Unexpected query ${command}`);
};
const sources = descriptions.slice(0, 1);
const facts = await inspectAptRepositories(
{ sources, origins: ["Vendor"] },
{ runQuery, apt: { lists: root, trustedParts: root, trusted: key } },
undefined,
);
expect(facts.repositories).toEqual([
expect.objectContaining({
uri: `"${uri}"`,
repo_uri: `${uri}/`,
suite,
repo_suite: "stable",
repo_components: effective,
signing_key: expect.objectContaining({
fingerprint: VENDOR_A.fingerprint,
}),
}),
]);
expect(
declaredPackageFiles(facts.repositories, facts.indexTargets),
).toEqual(new Set(replayable ? descriptions : []));
const install = exportInstall(
{
kind: "deb",
name: "example:amd64",
version: "1.0",
architecture: "amd64",
sources,
source_origins: ["Vendor"],
package_lists_present: true,
apt_repositories: [...facts.repositories],
},
"example",
"x64",
);
if (replayable)
expect(install).toMatchObject({
ok: true,
value: {
sources: [{ uri, suite: "stable", components: effective }],
},
});
else
expect(install).toMatchObject({
ok: false,
error: {
reason: expect.stringContaining(
"one AgentEnv deb822 component token",
),
},
});
},
);
it("records an expanded APT source suite separately from the authored suite", async () => {
const root = await createTestTempDirectory("apt-source-suite-");
const file = join(root, "vendor.sources");
const uri = "https://vendor.invalid/archive/";
const suite = "stable/binary-$(ARCH)/";
const repoSuite = "stable/binary-x86_64/";
await writeFile(
file,
`Types: deb\nURIs: ${uri}\nSuites: ${suite} fallback/\n`,
);
const source = `${uri.slice(0, -1)} ${repoSuite} Packages`;
const output = [
`Description: ${source}`,
`Sourcesentry: ${file}:1`,
`Repo-URI: ${uri}`,
`Release: ${repoSuite}`,
`Base-URI: ${uri}${repoSuite}`,
`Filename: ${join(root, "Packages")}`,
].join("\n");
const runQuery: QueryRunner = async (command) => {
if (command !== "apt-get") throw new Error(`Unexpected query ${command}`);
return { stdout: output, exitCode: 0 };
};
const facts = await inspectAptRepositories(
{ sources: [source], origins: ["Vendor"] },
{
runQuery,
apt: {
lists: root,
trustedParts: root,
trusted: join(root, "trusted.gpg"),
configuredArchitecture: "x86_64",
},
},
undefined,
);
expect(facts.repositories[0]).toMatchObject({
suite,
repo_suite: repoSuite,
release: null,
});
});
it.each([
["https://vendor.invalid:/archive", "https://vendor.invalid/archive/"],
[
"https://vendor.invalid:80abc/archive",
"https://vendor.invalid:80/archive/",
],
["https://vendor.invalid:https/archive", "https://vendor.invalid/archive/"],
["https://[2001:db8::11]:80abc/apt", "https://[2001:db8::11]:80/apt/"],
["https://[2001:db8::11]:https/apt", "https://[2001:db8::11]/apt/"],
])(
"retains authored %s when APT reports %s, including its signing key",
async (authored, repoUri) => {
const root = await createTestTempDirectory("apt-port-suffix-");
const sources = join(root, "vendor.sources");
const key = join(root, "vendor.gpg");
const lists = join(root, "lists");
const baseUri = `${repoUri}dists/stable/`;
const source = `${repoUri.slice(0, -1)} stable/main amd64 Packages`;
await mkdir(lists);
await writeFile(key, VENDOR_A.key);
await writeFile(
join(lists, `${aptListFileName(baseUri)}InRelease`),
"controlled release",
);
await writeFile(
sources,
`Types: deb\nURIs: ${authored}\nSuites: stable\nComponents: main\nSigned-By: ${key}\n`,
);
const targets = [
`Description: ${source}`,
`Sourcesentry: ${sources}:1`,
`Repo-URI: ${repoUri}`,
"Release: stable",
"Suite: stable",
"Component: main",
`Base-URI: ${baseUri}`,
`Filename: ${join(lists, "Packages")}`,
].join("\n");
const runQuery: QueryRunner = async (command) => {
if (command === "apt-get") return { stdout: targets, exitCode: 0 };
if (command !== "gpgv") throw new Error(`Unexpected query ${command}`);
return { stdout: GPGV_A_ONLY, exitCode: 2 };
};
const facts = await inspectAptRepositories(
{ sources: [source], origins: ["Vendor"] },
{
runQuery,
apt: { lists, trustedParts: root, trusted: join(root, "trusted.gpg") },
},
undefined,
);
expect(facts.repositories).toEqual([
expect.objectContaining({
source,
sources_file: sources,
uri: authored,
repo_uri: repoUri,
uri_credentials_removed: false,
suite: "stable",
components: ["main"],
architectures: [],
release: "stable",
signing_key: expect.objectContaining({
path: key,
format: "binary",
fingerprint: VENDOR_A.fingerprint,
}),
}),
]);
expect(facts.repositories[0]).not.toHaveProperty("signing_key_reason");
expect([...facts.keys.values()]).toEqual([VENDOR_A.key]);
},
);
it("withholds an undecodable APT index and preserves an intact peer", async () => {
const root = await createTestTempDirectory("apt-index-encoding-");
const file = join(root, "vendor.list");
await writeFile(
file,
"deb https://bad.invalid/a%FFb stable main\ndeb https://good.invalid/a%EF%BF%BDb stable main\n",
);
const bad = "https://bad.invalid/a\ufffdb stable/main arm64 Packages";
const good = "https://good.invalid/a\ufffdb stable/main arm64 Packages";
const paragraph = (source: string, uri: string, position: number) =>
[
`Description: ${source}`,
`Sourcesentry: ${file}:${position}`,
`Repo-URI: ${uri}`,
"Release: stable",
"Component: main",
`Base-URI: ${uri}dists/stable/`,
`Filename: ${join(root, "Packages")}`,
].join("\n");
const bytes = Buffer.from(
`${paragraph(bad.replace("\ufffd", "ÿ"), "https://bad.invalid/aÿb/", 1)}\n\n`,
"latin1",
);
const output = Buffer.concat([
bytes,
Buffer.from(paragraph(good, "https://good.invalid/a\ufffdb/", 2)),
]);
const query: QueryRunner = async (command, _argv, signal, options) => {
if (command !== "apt-get") throw new Error(`Unexpected query ${command}`);
return runHostQuery(
process.execPath,
[
"-e",
'process.stdout.write(Buffer.from(process.argv[1], "base64"))',
output.toString("base64"),
],
signal,
options,
);
};
const facts = await inspectAptRepositories(
{ sources: [bad, good], origins: ["Vendor", "Vendor"] },
{
runQuery: query,
apt: {
lists: root,
trustedParts: root,
trusted: join(root, "trusted.gpg"),
},
},
undefined,
);
expect([...facts.indexTargets.keys()]).toEqual([good]);
expect(facts.repositories[0]).toMatchObject({
uri: null,
signing_key_reason: expect.stringContaining("unreadable UTF-8"),
});
expect(facts.repositories[0]).not.toHaveProperty("repo_uri");
expect(facts.repositories[1]).toMatchObject({
uri: "https://good.invalid/a%EF%BF%BDb",
repo_uri: "https://good.invalid/a\ufffdb/",
});
expect(declaredPackageFiles(facts.repositories, facts.indexTargets)).toEqual(
new Set([good]),
);
});
it.each(["list", "sources"] as const)(
"does not broaden %s Signed-By fingerprint restrictions to every key in a keyring",
async (format) => {
const root = await createTestTempDirectory("apt-signed-by-");
const sources = join(root, `vendor.${format}`);
const key = join(root, "vendor.gpg");
const trustedParts = join(root, "trusted.gpg.d");
await mkdir(trustedParts);
await writeFile(key, VENDOR_A.key);
await writeFile(
join(root, "vendor.example_repo_InRelease"),
"controlled release",
);
const source = "https://vendor.example/repo stable/main amd64 Packages";
const targets = [
`Description: ${source}`,
`Sourcesentry: ${sources}:1`,
"Repo-URI: https://vendor.example/repo/",
"Release: stable",
"Component: main",
"Base-URI: https://vendor.example/repo/",
`Filename: ${join(root, "Packages")}`,
].join("\n");
let verifications = 0;
const runQuery: QueryRunner = async (command) => {
if (command === "apt-get") return { stdout: targets, exitCode: 0 };
if (command !== "gpgv") throw new Error(`Unexpected query ${command}`);
verifications += 1;
return { stdout: GPGV_A_ONLY, exitCode: 1 };
};
const inspect = async (signedBy: string) => {
await writeFile(
sources,
format === "list"
? `deb [signed-by=${signedBy.replaceAll(" ", ",")}] https://vendor.example/repo stable main\n`
: `Types: deb\nURIs: https://vendor.example/repo\nSuites: stable\nComponents: main\nSigned-By: ${signedBy}\n`,
);
return inspectAptRepositories(
{ sources: [source], origins: ["Vendor"] },
{
runQuery,
apt: { lists: root, trustedParts, trusted: key },
},
undefined,
);
};
const pathOnly = await inspect(key);
expect(pathOnly.repositories[0]?.signing_key).toMatchObject({
path: key,
fingerprint: VENDOR_A.fingerprint,
});
expect(pathOnly.keys.size).toBe(1);
for (const selector of [VENDOR_B.fingerprint, `${VENDOR_B.fingerprint}!`]) {
for (const signedBy of [selector, `${key} ${selector}`]) {
const restricted = await inspect(signedBy);
expect(restricted.repositories[0]).toMatchObject({
source,
sources_file: sources,
uri: "https://vendor.example/repo",
suite: "stable",
components: ["main"],
signing_key: null,
signing_key_reason: expect.stringContaining(selector),
});
expect(restricted.repositories[0]?.signing_key_reason).toContain(
"not supported",
);
expect(restricted.keys.size).toBe(0);
}
}
expect(verifications).toBe(1);
},
);
describe.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
"an InRelease the check cannot reach beside a readable detached pair",
() => {
it("keeps the release.gpg and Release files apt still holds", async () => {
const root = await createTestTempDirectory("apt-inrelease-");
const lists = join(root, "lists");
const sources = join(root, "vendor.list");
const key = join(root, "vendor.gpg");
const trustedParts = join(root, "trusted.gpg.d");
// A symlink into a folder the check cannot search makes InRelease alone unprobeable.
const denied = join(root, "denied");
await mkdir(lists);
await mkdir(trustedParts);
await mkdir(denied);
await writeFile(key, VENDOR_A.key);
// A symlink into a folder the check cannot search makes InRelease alone unprobeable.
const released = "vendor.example_repo_";
await writeFile(
join(denied, `${released}InRelease`),
"controlled release",
);
await symlink(
join(denied, `${released}InRelease`),
join(lists, `${released}InRelease`),
);
await writeFile(join(lists, `${released}Release.gpg`), "signature");
await writeFile(join(lists, `${released}Release`), "controlled release");
await chmod(denied, 0o000);
try {
const source = "https://vendor.example/repo stable/main amd64 Packages";
const targets = [
`Description: ${source}`,
`Sourcesentry: ${sources}:1`,
"Repo-URI: https://vendor.example/repo/",
"Release: stable",
"Component: main",
"Base-URI: https://vendor.example/repo/",
`Filename: ${join(lists, `${released}Packages`)}`,
].join("\n");
const verified: string[][] = [];
const runQuery: QueryRunner = async (command, argv) => {
if (command === "apt-get") return { stdout: targets, exitCode: 0 };
if (command !== "gpgv")
throw new Error(`Unexpected query ${command}`);
verified.push(argv.slice(argv.indexOf("--keyring") + 2));
return { stdout: GPGV_A_ONLY, exitCode: 1 };
};
await writeFile(
sources,
`deb [signed-by=${key}] https://vendor.example/repo stable main\n`,
);
const result = await inspectAptRepositories(
{ sources: [source], origins: ["Vendor"] },
{
runQuery,
apt: { lists, trustedParts, trusted: key },
},
undefined,
);
expect(result.repositories[0]?.signing_key).toMatchObject({
fingerprint: VENDOR_A.fingerprint,
});
expect(verified).toEqual([
[
join(lists, `${released}Release.gpg`),
join(lists, `${released}Release`),
],
]);
} finally {
await chmod(denied, 0o755);
}
});
},
);
describe.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
"an InRelease the check cannot reach with no detached pair beside it",
() => {
it("leaves the signed release unknown instead of reporting none", async () => {
// Only an InRelease known to be missing establishes that apt holds no
// signed release. An unprobed one may still be there, so the check has to
// report that it could not tell rather than absence.
const root = await createTestTempDirectory("apt-inrelease-unknown-");
const lists = join(root, "lists");
const sources = join(root, "vendor.list");
const key = join(root, "vendor.gpg");
const trustedParts = join(root, "trusted.gpg.d");
const denied = join(root, "denied");
await mkdir(lists);
await mkdir(trustedParts);
await mkdir(denied);
await writeFile(key, VENDOR_A.key);
const released = "vendor.example_repo_";
await writeFile(
join(denied, `${released}InRelease`),
"controlled release",
);
await symlink(
join(denied, `${released}InRelease`),
join(lists, `${released}InRelease`),
);
await chmod(denied, 0o000);
try {
const source = "https://vendor.example/repo stable/main amd64 Packages";
const targets = [
`Description: ${source}`,
`Sourcesentry: ${sources}:1`,
"Repo-URI: https://vendor.example/repo/",
"Release: stable",
"Component: main",
"Base-URI: https://vendor.example/repo/",
`Filename: ${join(lists, `${released}Packages`)}`,
].join("\n");
const runQuery: QueryRunner = async (command) => {
if (command === "apt-get") return { stdout: targets, exitCode: 0 };
throw new Error(`Unexpected query ${command}`);
};
await writeFile(
sources,
`deb [signed-by=${key}] https://vendor.example/repo stable main\n`,
);
const result = await inspectAptRepositories(
{ sources: [source], origins: ["Vendor"] },
{
runQuery,
apt: { lists, trustedParts, trusted: key },
},
undefined,
);
expect(result.repositories[0]?.signing_key).toBeNull();
expect(result.repositories[0]?.signing_key_reason).toContain(
"could not be checked",
);
} finally {
await chmod(denied, 0o755);
}
});
},
);
describe.skipIf(
process.platform !== "linux" || !existsSync("/usr/bin/apt-config"),
)("resolveAptLocations with apt-config", () => {
it("preserves newline paths printed by the real apt-config command", async () => {
const root = await createTestTempDirectory("apt-config-newline-");
const selected = {
lists: `${root}/user's\nlists/`,
trustedParts: `${root}/trusted\nparts/`,
trusted: `${root}/trusted\nkeys.gpg`,
status: `${root}/installed\nstatus`,
};
const configured: QueryRunner = (command, argv, signal) =>
runHostQuery(
command,
[
"-o",
`Dir::State::Lists=${selected.lists}`,
"-o",
`Dir::Etc::TrustedParts=${selected.trustedParts}`,
"-o",
`Dir::Etc::Trusted=${selected.trusted}`,
"-o",
`Dir::State::status=${selected.status}`,
"-o",
"APT::Architecture=armhf",
...argv,
],
signal,
);
expect(await resolveAptLocations(configured, undefined)).toEqual({
...selected,
configuredArchitecture: "armhf",
});
});
it.each([
["x86_64", "x86_64"],
["amd64", "amd64"],
["../etc", undefined],
["x86_64/etc", undefined],
] as const)(
"keeps APT architecture %s only when it is an architecture token",
async (configured, kept) => {
const root = await createTestTempDirectory("apt-config-arch-");
const selected = {
lists: `${root}/lists/`,
trustedParts: `${root}/trusted/`,
trusted: `${root}/trusted.gpg`,
status: `${root}/status`,
};
const configuredQuery: QueryRunner = (command, argv, signal) =>
runHostQuery(
command,
[
"-o",
`Dir::State::Lists=${selected.lists}`,
"-o",
`Dir::Etc::TrustedParts=${selected.trustedParts}`,
"-o",
`Dir::Etc::Trusted=${selected.trusted}`,
"-o",
`Dir::State::status=${selected.status}`,
"-o",
`APT::Architecture=${configured}`,
...argv,
],
signal,
);
const locations = await resolveAptLocations(configuredQuery, undefined);
expect(locations).toEqual(
kept === undefined
? selected
: { ...selected, configuredArchitecture: kept },
);
},
);
it("reads the lists folder an APT_CONFIG file names, resolved under Dir::State", async () => {
const root = await createTestTempDirectory("apt-config-");
const config = join(root, "apt.conf");
await writeFile(
config,
`Dir::State "${root}/state";\nDir::State::Lists "user lists";\nAPT::Architecture "amd64";\n`,
);
const configured: QueryRunner = (command, argv, signal) =>
runHostQuery("env", [`APT_CONFIG=${config}`, command, ...argv], signal);
const locations = await resolveAptLocations(configured, undefined);
expect(locations).toEqual({
lists: `${root}/state/user lists/`,
trustedParts: "/etc/apt/trusted.gpg.d/",
trusted: "/etc/apt/trusted.gpg",
status: "/var/lib/dpkg/status",
configuredArchitecture: "amd64",
});
expect(
await resolveAptLocations(
(_command, argv, signal) =>
runHostQuery("/missing/apt-config", argv, signal),
undefined,
),
).toEqual(APT_LOCATIONS);
});
});