test(android): consolidate ADB and Apktool boundary checks (#12837)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 13:54:53 +00:00
1 parent 11c951228c
commit 79525a7c3e
5 files changed
+69 -133

No files matched your search

+5 -13
View File
@@ -394,19 +394,11 @@ describe("parsePackageListOutput", () => {
]);
});
it("keeps unrecognized lines for partial coverage reporting", () => {
const { packages, unparsedLines } = parsePackageListOutput(
"package:/data/app/x/base.apk=com.ok\n garbage line \n",
);
expect(packages).toHaveLength(1);
expect(unparsedLines).toEqual({ sample: [" garbage line "], total: 1 });
});
it("samples the first ten unrecognized lines and counts every one", () => {
const rows = Array.from(
{ length: 11 },
(_, index) => `row ${String(index + 1)}`,
);
it("preserves the first ten raw unrecognized lines and counts every one", () => {
const rows = [
" garbage line ",
...Array.from({ length: 10 }, (_, index) => `row ${String(index + 1)}`),
];
const { packages, unparsedLines } = parsePackageListOutput(
["package:/data/app/x/base.apk=com.ok", ...rows].join("\n"),
);
+10 -27
View File
@@ -1968,37 +1968,13 @@ it.each(["complete", "truncated"] as const)(
},
);
it("inspects the display and window focus", async () => {
const { binary } = await writeAdbStub(
shellStub({
"wm:size": "Physical size: 1080x2340\n",
"wm:density": "Physical density: 420\n",
"dumpsys:window":
" mCurrentFocus=Window{abcdef u0 com.example.app/com.example.app.MainActivity}\n",
}),
);
const display = await evidenceResult(providerOver(binary), {
operation: "inspect_adb_display",
input: { serial: "emulator-5554" },
});
expect(display.physical_size).toEqual({ width: 1080, height: 2340 });
expect(display.physical_density).toBe(420);
const window = await evidenceResult(providerOver(binary), {
operation: "inspect_adb_window",
input: { serial: "emulator-5554" },
});
expect(window.focused_window).toBe(
"Window{abcdef u0 com.example.app/com.example.app.MainActivity}",
);
});
// Older builds print `wm density` as a bare number; the display projection
// must keep it as the physical density (morluto/rea#3942).
it("keeps a bare numeric wm density as the physical density", async () => {
it("inspects display and window focus with a bare physical density", async () => {
const { binary } = await writeAdbStub(
shellStub({
"wm:size": "Physical size: 1080x2340\n",
"wm:density": "420\n",
"dumpsys:window":
" mCurrentFocus=Window{abcdef u0 com.example.app/com.example.app.MainActivity}\n",
}),
);
const display = await evidenceResult(providerOver(binary), {
@@ -2010,6 +1986,13 @@ it("keeps a bare numeric wm density as the physical density", async () => {
physical_density: 420,
override_density: null,
});
const window = await evidenceResult(providerOver(binary), {
operation: "inspect_adb_window",
input: { serial: "emulator-5554" },
});
expect(window.focused_window).toBe(
"Window{abcdef u0 com.example.app/com.example.app.MainActivity}",
);
});
it("reads Android 16 focus declarations from displays when windows omits them", async () => {
+38 -37
View File
@@ -580,20 +580,53 @@ it.each([
expect(result.error.message).toContain("apktool.yml");
});
it("preserves empty resource strings and reports markup omissions as partial", async () => {
it("preserves primary strings and reports markup omissions in default and localized tables", async () => {
const stringsXml =
'<resources><string name="empty"/><string name="raw"> A &amp; B </string><string name="styled">Hello <b>world</b></string></resources>';
const { command, root } = await writeApktoolStub(decodeStub({ stringsXml }));
const { command, root } = await writeApktoolStub((root) =>
decodeStub({ stringsXml, withGerman: false })(root).replace(
'if [ "$1" = "d" ]; then',
`if [ "$1" = "d" ]; then
mkdir -p "$5/res/values-de"
printf '<resources><string name="styled">Hallo <b>Welt</b></string></resources>' > "$5/res/values-de/strings.xml"`,
),
);
const apk = await apkFixture(root);
const result = await evidenceResult(providerOver(command), {
operation: "decode_android_resources",
input: { path: apk.path, include_strings: true },
const provider = providerOver(command);
onTestFinished(() => provider.close());
const observation = await new ApktoolResourceAnalysisService(
provider,
).execute("decode_android_resources", {
path: apk.path,
include_strings: true,
locales: ["de"],
});
if (!observation.ok) throw observation.error;
const result = apktoolResultSchemas.decode_android_resources.parse(
observation.value.normalized_result,
);
expect(result.strings).toEqual([
{ name: "empty", value: "" },
{ name: "raw", value: " A &amp; B " },
]);
expect(result.coverage).toBe("partial");
expect(result.string_tables).toMatchObject([
{
locale: null,
status: "present",
total_count: 2,
unparsed_count: 1,
coverage: "partial",
},
{
locale: "de",
status: "present",
strings: [],
total_count: 0,
unparsed_count: 1,
coverage: "partial",
},
]);
});
it("preserves literal U+FFFD in decoded XML with complete coverage", async () => {
@@ -1032,38 +1065,6 @@ it("skips all string tables when include_strings is false despite locales reques
expect(result.strings).toEqual([]);
});
it("marks table with styled markup present with partial coverage and unparsed count", async () => {
const { command, root } = await writeApktoolStub((root) =>
decodeStub({ withGerman: false })(root).replace(
'if [ "$1" = "d" ]; then',
`if [ "$1" = "d" ]; then
mkdir -p "$5/res/values-de"
printf '<resources><string name="styled">Hallo <b>Welt</b></string></resources>' > "$5/res/values-de/strings.xml"`,
),
);
const apk = await apkFixture(root);
const observation = await new ApktoolResourceAnalysisService(
providerOver(command),
).execute("decode_android_resources", {
path: apk.path,
include_strings: true,
locales: ["de"],
});
if (!observation.ok) throw observation.error;
const result = apktoolResultSchemas.decode_android_resources.parse(
observation.value.normalized_result,
);
const deTable = result.string_tables?.find((t) => t.locale === "de");
expect(deTable).toEqual({
locale: "de",
status: "present",
strings: [],
total_count: 0,
unparsed_count: 1,
coverage: "partial",
});
});
it("skips remaining tables without reading or parsing once aggregate string budget is exhausted", async () => {
const { command, root } = await writeApktoolStub((root) =>
decodeStub({
@@ -2,24 +2,7 @@ import { expect, it } from "vitest";
import { invokeApktoolCli } from "../../support/cli/apktoolCli.js";
it("dispatches --no-strings as include_strings false", async () => {
const result = await invokeApktoolCli([
"decode-android-resources",
"/targets/app.apk",
"--no-strings",
"--json",
]);
expect(result.exitCode).toBe(0);
expect(result.requests).toEqual([
{
operation: "decode_android_resources",
input: { path: "/targets/app.apk", include_strings: false },
},
]);
});
it("keeps string projection enabled when the flag is omitted", async () => {
it("enables strings and leaves the decode deadline unset by default", async () => {
const result = await invokeApktoolCli([
"decode-android-resources",
"/targets/app.apk",
@@ -35,15 +18,7 @@ it("keeps string projection enabled when the flag is omitted", async () => {
]);
});
it("passes decode_timeout_ms only when the caller selects it", async () => {
const omitted = await invokeApktoolCli([
"decode-android-resources",
"/targets/app.apk",
"--json",
]);
expect(omitted.exitCode).toBe(0);
expect(omitted.requests[0]?.input).not.toHaveProperty("decode_timeout_ms");
it("forwards a selected decode deadline and refuses invalid bounds", async () => {
const selected = await invokeApktoolCli([
"decode-android-resources",
"/targets/app.apk",
@@ -52,9 +27,16 @@ it("passes decode_timeout_ms only when the caller selects it", async () => {
"--json",
]);
expect(selected.exitCode).toBe(0);
expect(selected.requests[0]?.input).toMatchObject({
decode_timeout_ms: 900_000,
});
expect(selected.requests).toEqual([
{
operation: "decode_android_resources",
input: {
path: "/targets/app.apk",
include_strings: true,
decode_timeout_ms: 900_000,
},
},
]);
for (const value of ["0", "2147483648"]) {
const rejected = await invokeApktoolCli([
+4 -26
View File
@@ -21,13 +21,15 @@ const OWNER_ADMITTED_LOCALES = [
"b+fil+Latn+419+ABCDEFGH",
] as const;
it("forwards the table-only string choice through the CLI", async () => {
it("forwards repeated locales with the table-only string choice", async () => {
const result = await invokeApktoolCli([
"decode-android-resources",
"/targets/app.apk",
"--string-tables-only",
"--locales",
"de",
"--locales",
"pt-BR",
"--json",
]);
expect(result.exitCode, result.stdout).toBe(0);
@@ -37,7 +39,7 @@ it("forwards the table-only string choice through the CLI", async () => {
input: {
path: "/targets/app.apk",
include_strings: true,
locales: ["de"],
locales: ["de", "pt-BR"],
string_tables_only: true,
},
},
@@ -64,30 +66,6 @@ it("forwards every locale the apktool input owner admits", async () => {
}
});
it("forwards repeated --locales to project multiple localized tables", async () => {
const result = await invokeApktoolCli([
"decode-android-resources",
"/targets/app.apk",
"--locales",
"de",
"--locales",
"pt-BR",
"--json",
]);
expect(result.exitCode).toBe(0);
expect(result.requests).toEqual([
{
operation: "decode_android_resources",
input: {
path: "/targets/app.apk",
include_strings: true,
locales: ["de", "pt-BR"],
},
},
]);
});
it.each(["not a locale", "en-r419", "es-r419"])(
"refuses the invalid locale %s before invoking Apktool",
async (locale) => {