neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Slice 12: Proguard mappings and JVM deobfuscation
220a460 · gmorell · 2026-12-02 04:22
Files changed
added
test/vigil/symbolication/jvm_test.exs
+96
−0
@@ -0,0 +1,96 @@
| 1 | +defmodule Vigil.Symbolication.JVMTest do | |
| 2 | + use Vigil.DataCase, async: true | |
| 3 | + | |
| 4 | + import Vigil.AccountsFixtures | |
| 5 | + import Vigil.OrganizationsFixtures | |
| 6 | + | |
| 7 | + alias Vigil.{DebugFiles, Symbolic} | |
| 8 | + alias Vigil.Symbolication.JVM | |
| 9 | + | |
| 10 | + @mapping "test/support/fixtures/proguard/mapping.txt" | |
| 11 | + @uuid "6a4fa6d8-6d4d-4d5e-9a3e-2f4c1bb3a1c2" | |
| 12 | + | |
| 13 | + setup do | |
| 14 | + owner = user_fixture() | |
| 15 | + org = organization_fixture(owner) | |
| 16 | + project = project_fixture(org_scope(owner, org)) | |
| 17 | + scope = %{organization_id: org.id, project_id: project.id} | |
| 18 | + data = File.read!(@mapping) | |
| 19 | + checksum = :crypto.hash(:sha, data) |> Base.encode16(case: :lower) | |
| 20 | + %{scope: scope, data: data, checksum: checksum} | |
| 21 | + end | |
| 22 | + | |
| 23 | + defp upload(ctx, name \\ "/proguard/#{@uuid}.txt"), | |
| 24 | + do: DebugFiles.create_files(ctx.scope, name, ctx.checksum, ctx.data) | |
| 25 | + | |
| 26 | + # An obfuscated crash in MainActivity.crash (inlined into onCreate): | |
| 27 | + # oldest first, the caller frame from the framework. | |
| 28 | + defp event(uuid \\ @uuid) do | |
| 29 | + %{ | |
| 30 | + "platform" => "java", | |
| 31 | + "exception" => %{ | |
| 32 | + "values" => [ | |
| 33 | + %{ | |
| 34 | + "type" => "b", | |
| 35 | + "module" => "a", | |
| 36 | + "value" => "boom", | |
| 37 | + "stacktrace" => %{ | |
| 38 | + "frames" => [ | |
| 39 | + %{"module" => "android.app.Activity", "function" => "performCreate", "lineno" => 8}, | |
| 40 | + %{"module" => "a.a", "function" => "a", "lineno" => 4, "in_app" => true} | |
| 41 | + ] | |
| 42 | + } | |
| 43 | + } | |
| 44 | + ] | |
| 45 | + }, | |
| 46 | + "debug_meta" => %{"images" => [%{"type" => "proguard", "uuid" => uuid}]} | |
| 47 | + } | |
| 48 | + end | |
| 49 | + | |
| 50 | + test "a mapping is stored under the UUID sentry-cli named it by, or its own", ctx do | |
| 51 | + assert {:ok, [file]} = upload(ctx) | |
| 52 | + assert file.debug_id == @uuid | |
| 53 | + assert file.file_format == "proguard" | |
| 54 | + assert file.features == ["mapping"] | |
| 55 | + | |
| 56 | + {:ok, %{uuid: computed}} = Symbolic.proguard_info(ctx.data) | |
| 57 | + assert {:ok, files} = DebugFiles.create_files(ctx.scope, "mapping.txt", "x", ctx.data) | |
| 58 | + assert Enum.any?(files, &(&1.debug_id == computed)) | |
| 59 | + end | |
| 60 | + | |
| 61 | + test "frames and the exception type deobfuscated, inlined frames expanded", ctx do | |
| 62 | + {:ok, _} = upload(ctx) | |
| 63 | + event = JVM.symbolicate(event(), ctx.scope) | |
| 64 | + [exception] = event["exception"]["values"] | |
| 65 | + | |
| 66 | + assert exception["type"] == "BadThingException" | |
| 67 | + assert exception["module"] == "com.example.app" | |
| 68 | + | |
| 69 | + assert [framework, on_create, crash] = exception["stacktrace"]["frames"] | |
| 70 | + assert framework["module"] == "android.app.Activity" | |
| 71 | + | |
| 72 | + assert on_create["module"] == "com.example.app.MainActivity" | |
| 73 | + assert on_create["function"] == "onCreate" | |
| 74 | + assert on_create["lineno"] == 23 | |
| 75 | + assert on_create["filename"] == "MainActivity.kt" | |
| 76 | + assert on_create["in_app"] == true | |
| 77 | + assert on_create["data"]["deobfuscated"] | |
| 78 | + | |
| 79 | + assert crash["function"] == "crash" | |
| 80 | + assert crash["lineno"] == 30 | |
| 81 | + | |
| 82 | + assert length(exception["raw_stacktrace"]["frames"]) == 2 | |
| 83 | + refute event["errors"] | |
| 84 | + end | |
| 85 | + | |
| 86 | + test "a mapping nobody uploaded is noted, the event left as it was", ctx do | |
| 87 | + event = JVM.symbolicate(event(), ctx.scope) | |
| 88 | + assert hd(event["exception"]["values"])["type"] == "b" | |
| 89 | + assert [%{"type" => "proguard_missing_mapping", "mapping_uuid" => @uuid}] = event["errors"] | |
| 90 | + end | |
| 91 | + | |
| 92 | + test "events without proguard images are untouched", ctx do | |
| 93 | + plain = Map.delete(event(), "debug_meta") | |
| 94 | + assert JVM.symbolicate(plain, ctx.scope) == plain | |
| 95 | + end | |
| 96 | +end |
modified
test/vigil_web/sentry_cli_debug_files_test.exs
+37
−1
@@ -13,7 +13,7 @@ defmodule VigilWeb.SentryCliDebugFilesTest do
| 13 | 13 | import Vigil.AccountsFixtures |
| 14 | 14 | import Vigil.OrganizationsFixtures |
| 15 | 15 | |
| 16 | − alias Vigil.{ApiTokens, Ingest, Issues, Repo} | |
| 16 | + alias Vigil.{ApiTokens, DebugFiles, Ingest, Issues, Repo} | |
| 17 | 17 | alias Vigil.DebugFiles.DebugFile |
| 18 | 18 | alias Vigil.Ingest.{Drain, Envelope} |
| 19 | 19 |
@@ -134,4 +134,40 @@ defmodule VigilWeb.SentryCliDebugFilesTest do
| 134 | 134 | IO.puts("skipping sentry-cli debug-files: no sentry-cli on PATH") |
| 135 | 135 | end |
| 136 | 136 | end |
| 137 | + | |
| 138 | + @tag :sdk | |
| 139 | + @tag :tmp_dir | |
| 140 | + test "upload-proguard, legacy zip upload and chunked", ctx do | |
| 141 | + if @cli do | |
| 142 | + %{env: env, project: project} = ctx | |
| 143 | + mapping = Path.join(ctx.tmp_dir, "mapping.txt") | |
| 144 | + File.cp!("test/support/fixtures/proguard/mapping.txt", mapping) | |
| 145 | + {:ok, %{uuid: uuid}} = Vigil.Symbolic.proguard_info(File.read!(mapping)) | |
| 146 | + | |
| 147 | + # The default: a zip to files/dsyms/. | |
| 148 | + out = ok!(env, ["upload-proguard", mapping]) | |
| 149 | + assert out =~ uuid | |
| 150 | + assert %DebugFile{file_format: "proguard"} = DebugFiles.proguard_mapping(project.id, uuid) | |
| 151 | + | |
| 152 | + # Chunked, through difs/assemble, under a forced UUID. Another build's | |
| 153 | + # mapping (a different checksum: the same file would already be there). | |
| 154 | + forced = "0b0b0b0b-1111-4222-8333-444455556666" | |
| 155 | + File.write!(mapping, "# build 2\n", [:append]) | |
| 156 | + stop = run_jobs_meanwhile() | |
| 157 | + | |
| 158 | + out = | |
| 159 | + ok!([{"SENTRY_EXPERIMENTAL_PROGUARD_CHUNK_UPLOAD", "1"} | env], [ | |
| 160 | + "upload-proguard", | |
| 161 | + "--uuid", | |
| 162 | + forced, | |
| 163 | + mapping | |
| 164 | + ]) | |
| 165 | + | |
| 166 | + stop.() | |
| 167 | + assert out =~ "OK" or out =~ forced | |
| 168 | + assert %DebugFile{file_format: "proguard"} = DebugFiles.proguard_mapping(project.id, forced) | |
| 169 | + else | |
| 170 | + IO.puts("skipping sentry-cli upload-proguard: no sentry-cli on PATH") | |
| 171 | + end | |
| 172 | + end | |
| 137 | 173 | end |
Parents: 334594a