Skip to content

Commit cab1675

Browse files
authored
Merge pull request #261 from mozilla/fix-download-hash
Encode download hash in telemetry as hex string
2 parents d3a0112 + d918d6a commit cab1675

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

browser/components/downloads/DownloadsTelemetry.enterprise.sys.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,19 @@ export const DownloadsTelemetryEnterprise = {
229229
sizeBytes = 0;
230230
}
231231

232+
const hashBufferCString = download.saver.getSha256Hash();
233+
const hashHex = hashBufferCString
234+
? new Uint8Array(
235+
Array.from(hashBufferCString, c => c.charCodeAt(0))
236+
).toHex()
237+
: "";
238+
232239
const telemetryData = {
233240
filename: fileInfo.filename,
234241
file_path: fileInfo.file_path,
235242
extension: fileInfo.extension,
236243
mime_type: fileInfo.mime_type,
237-
sha256_hash: download.saver.getSha256Hash() || "",
244+
sha256_hash: hashHex,
238245
size_bytes: sizeBytes,
239246
source_url: sourceUrl || "",
240247
is_private: download.source?.isPrivate || false,

browser/components/downloads/test/unit/test_DownloadsTelemetry_enterprise.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ add_task(async function test_enterprise_data_parsing() {
131131
isPrivate: false,
132132
},
133133
contentType: "application/pdf",
134+
saver: {
135+
getSha256Hash() {
136+
const hardcodedHash =
137+
"1234567890abcdef1234567890abcdeffedcba0987654321fedcba0987654321";
138+
const hexIntArray = Uint8Array.fromHex(hardcodedHash);
139+
const hashBufferCString = String.fromCharCode.apply(null, hexIntArray);
140+
return hashBufferCString;
141+
},
142+
},
134143
};
135144

136145
// Disable ping submission to prevent clearing telemetry data before we can inspect it
@@ -172,6 +181,11 @@ add_task(async function test_enterprise_data_parsing() {
172181
"application/pdf",
173182
"Should preserve MIME type"
174183
);
184+
Assert.equal(
185+
event.extra.sha256_hash,
186+
"1234567890abcdef1234567890abcdeffedcba0987654321fedcba0987654321",
187+
"Should record decoded SHA 256 hash"
188+
);
175189
Assert.equal(
176190
event.extra.size_bytes,
177191
"12345",

0 commit comments

Comments
 (0)