Skip to content

Commit b236032

Browse files
test(dart-symbol-map): Fix checksum assertions
1 parent 35af51f commit b236032

1 file changed

Lines changed: 54 additions & 28 deletions

File tree

tests/integration/upload_dart_symbol_map.rs

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use std::sync::atomic::{AtomicU8, Ordering};
2+
use std::sync::LazyLock;
3+
4+
use serde_json::Value;
25

36
use crate::integration::test_utils::AssertCommand;
47
use crate::integration::{MockEndpointBuilder, TestManager};
58

6-
/// A test org auth token with org="wat-org" and empty URL.
7-
/// Format: sntrys_{base64_payload}_{base64_secret}
8-
/// Payload: {"iat":1704374159.069583,"url":"","region_url":"","org":"wat-org"}
9-
const ORG_AUTH_TOKEN_WAT_ORG: &str = "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";
10-
119
#[test]
1210
fn command_upload_dart_symbol_map_missing_capability() {
1311
// Server does not advertise `dartsymbolmap` capability → command should bail early.
@@ -181,26 +179,47 @@ fn command_upload_dart_symbol_map_with_custom_url() {
181179
.run_and_assert(AssertCommand::Success);
182180
}
183181

182+
/// A test to ensure that the command can resolve an organization from an
183+
/// org auth token.
184184
#[test]
185185
fn command_upload_dart_symbol_map_org_from_token() {
186+
/// Path to the mapping file
187+
const MAPPING_PATH: &str = "tests/integration/_fixtures/dart_symbol_map/dartsymbolmap.json";
188+
189+
/// A test org auth token with org="wat-org" and empty URL.
190+
/// Format: sntrys_{base64_payload}_{base64_secret}
191+
/// Payload: {"iat":1704374159.069583,"url":"","region_url":"","org":"wat-org"}
192+
const ORG_AUTH_TOKEN_WAT_ORG: &str = "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";
193+
194+
/// Checksum of the mapping file
195+
const EXPECTED_CHECKSUM: &str = "6aa44eb08e4a72d1cf32fe7c2504216fb1a3e862";
196+
197+
/// Expected request body for uploading the Dart symbol map
198+
static EXPECTED_REQUEST: LazyLock<Value> = LazyLock::new(|| {
199+
serde_json::json!({
200+
EXPECTED_CHECKSUM: {
201+
"chunks": [EXPECTED_CHECKSUM],
202+
"debug_id": "54fdf14a-41a1-426a-a073-8185e11a89d6-83920e6f",
203+
"name": "dartsymbolmap.json",
204+
}
205+
})
206+
});
207+
186208
// When no --org is provided and SENTRY_ORG is not set, the org should be resolved
187209
// from the org auth token.
188210
let call_count = AtomicU8::new(0);
189211

190212
TestManager::new()
191-
// Server advertises capability including `dartsymbolmap`.
192213
// This endpoint uses "wat-org" in the path - if org resolution fails,
193214
// the request would go to a different path and not match.
194215
.mock_endpoint(
195216
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/")
196217
.with_response_file("dart_symbol_map/get-chunk-upload.json"),
197218
)
198-
// Accept chunk upload requests for the missing chunks
199219
.mock_endpoint(MockEndpointBuilder::new(
200220
"POST",
201221
"/api/0/organizations/wat-org/chunk-upload/",
202222
))
203-
// Assemble flow: 1) not_found (missingChunks), 2) created, 3) ok
204223
.mock_endpoint(
205224
MockEndpointBuilder::new(
206225
"POST",
@@ -212,38 +231,45 @@ fn command_upload_dart_symbol_map_org_from_token() {
212231
let body_json: serde_json::Value =
213232
serde_json::from_slice(body).expect("request body should be valid JSON");
214233

215-
let (checksum, _obj) = body_json
216-
.as_object()
217-
.and_then(|m| m.iter().next())
218-
.map(|(k, v)| (k.clone(), v.clone()))
219-
.expect("assemble request must contain at least one object");
234+
assert_eq!(
235+
body_json, *EXPECTED_REQUEST,
236+
"assemble request should match expected checksum payload"
237+
);
220238

221-
match call_count.fetch_add(1, Ordering::Relaxed) {
222-
0 => format!(
223-
"{{\"{checksum}\":{{\"state\":\"not_found\",\"missingChunks\":[\"{checksum}\"]}}}}"
224-
)
225-
.into(),
226-
1 => format!(
227-
"{{\"{checksum}\":{{\"state\":\"created\",\"missingChunks\":[]}}}}"
228-
)
229-
.into(),
230-
2 => format!(
231-
"{{\"{checksum}\":{{\"state\":\"ok\",\"detail\":null,\"missingChunks\":[],\"dif\":{{\"id\":\"1\",\"uuid\":\"00000000-0000-0000-0000-000000000000\",\"debugId\":\"00000000-0000-0000-0000-000000000000\",\"objectName\":\"dartsymbolmap.json\",\"cpuName\":\"any\",\"headers\":{{\"Content-Type\":\"application/octet-stream\"}},\"size\":1,\"sha1\":\"{checksum}\",\"dateCreated\":\"1776-07-04T12:00:00.000Z\",\"data\":{{}}}}}}}}"
232-
)
233-
.into(),
239+
let response = match call_count.fetch_add(1, Ordering::Relaxed) {
240+
0 => serde_json::json!({
241+
EXPECTED_CHECKSUM: {
242+
"state": "not_found",
243+
"missingChunks": [EXPECTED_CHECKSUM],
244+
}
245+
}),
246+
1 => serde_json::json!({
247+
EXPECTED_CHECKSUM: {
248+
"state": "created",
249+
"missingChunks": [],
250+
}
251+
}),
252+
2 => serde_json::json!({
253+
EXPECTED_CHECKSUM: {
254+
"state": "ok",
255+
"missingChunks": [],
256+
}
257+
}),
234258
n => panic!(
235259
"Only 3 calls to the assemble endpoint expected, but there were {}.",
236260
n + 1
237261
),
238-
}
262+
};
263+
264+
serde_json::to_vec(&response).expect("assemble response should be valid JSON")
239265
})
240266
.expect(3),
241267
)
242268
.assert_cmd([
243269
"dart-symbol-map",
244270
"upload",
245271
// No --org flag provided!
246-
"tests/integration/_fixtures/dart_symbol_map/dartsymbolmap.json",
272+
MAPPING_PATH,
247273
"tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb",
248274
])
249275
// Use org auth token with embedded org="wat-org" instead of default token

0 commit comments

Comments
 (0)