Skip to content

Commit 81cff7a

Browse files
committed
Update verify.ts
Proposed fix from coderabbitai
1 parent c884e05 commit 81cff7a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/verify.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export async function verifyAsset(
4949
algorithm: SupportedAlgorithmNames = "sha256",
5050
): Promise<void> {
5151
const manifestFile = getManifest(algorithm);
52+
const urlObj = new URL(downloadUrl);
53+
let assetName = urlObj.pathname.split("/").pop();
5254

5355
/**
5456
* 1. Establish the Local Baseline.
@@ -71,6 +73,7 @@ export async function verifyAsset(
7173
let manifestBaseUrl = "";
7274
try {
7375
const metadata = await fetchAssetMetadata(downloadUrl, token);
76+
assetName = meta.name;
7477
manifestBaseUrl = getGitHubManifestUrl(
7578
metadata.owner,
7679
metadata.repo,
@@ -83,7 +86,7 @@ export async function verifyAsset(
8386
* with GitHub's infrastructure hash.
8487
*/
8588
if (metadata.updated_at >= GITHUB_DIGEST_THRESHOLD) {
86-
info(`Verifying via asset metadata: ${metadata.name}`);
89+
info(`Verifying via asset metadata: ${assetName}`);
8790
if (metadata.digest) {
8891
const githubHash = getHexFromDigest(metadata.digest);
8992
if (githubHash !== actualHash) {
@@ -137,13 +140,13 @@ export async function verifyAsset(
137140
.split(/\r?\n/)
138141
.map((line) => line.match(/^([A-Fa-f0-9]+) [* ](.+)$/))
139142
.find(
140-
(m): m is RegExpMatchArray => Boolean(m) && m[2].trim() === metadata.name,
143+
(m): m is RegExpMatchArray => Boolean(m) && m[2].trim() === assetName,
141144
);
142145

143146
if (!manifestMatch) {
144147
silentUnlink(zipPath);
145148
throw new Error(
146-
`No verified hash found for ${metadata.name} in the signed manifest.`,
149+
`No verified hash found for ${assetName} in the signed manifest.`,
147150
);
148151
}
149152

@@ -163,7 +166,7 @@ export async function verifyAsset(
163166
);
164167
}
165168

166-
info(`Successfully verified ${metadata.name} (PGP + SHA256)`);
169+
info(`Successfully verified ${assetName} (PGP + SHA256)`);
167170
}
168171

169172
function silentUnlink(filePath: string): void {

0 commit comments

Comments
 (0)