Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 56 additions & 42 deletions app/common/adapter/binary/EdgedriverBinary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import path from 'node:path';

import { SingletonProto } from 'egg';

import { BinaryType } from '../../enum/Binary.ts';
import { AbstractBinary, BinaryAdapter, type BinaryItem, type FetchResult } from './AbstractBinary.ts';

// Microsoft moved the Edge WebDriver download listing off the public
// Azure Blob container (the old XML listing API returns
// `PublicAccessNotPermitted` since ~2026-04-07). The new source of truth
// is a single JSON dump at https://msedgedriver.microsoft.com/listing.json
// which lists every version-prefixed driver file; individual files are
// downloadable from https://msedgedriver.microsoft.com/<name>.
const EDGEDRIVER_LISTING_URL = 'https://msedgedriver.microsoft.com/listing.json';
const EDGEDRIVER_DOWNLOAD_BASE = 'https://msedgedriver.microsoft.com/';

interface EdgedriverListingEntry {
isDirectory: boolean;
name: string;
contentLength: number;
lastModified: string;
}
interface EdgedriverListing {
items: EdgedriverListingEntry[];
generatedAt: string;
}

@SingletonProto()
@BinaryAdapter(BinaryType.Edgedriver)
export class EdgedriverBinary extends AbstractBinary {
Expand Down Expand Up @@ -169,51 +187,47 @@ export class EdgedriverBinary extends AbstractBinary {
}

// fetch sub dir
// /foo/ => foo/
// /126.0.2578.0/ => 126.0.2578.0/
const subDir = dir.slice(1);
// https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver?prefix=124.0.2478.97/&delimiter=/&maxresults=100&restype=container&comp=list
const url = `https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver?prefix=${encodeURIComponent(subDir)}&delimiter=/&maxresults=100&restype=container&comp=list`;
const xml = await this.requestXml(url);
return { items: this.#parseItems(xml), nextParams: null };
}

#parseItems(xml: string): BinaryItem[] {
const listing = await this.#fetchListing();
if (!listing) {
return { items: [], nextParams: null };
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Returning an empty items array when the listing fetch fails can be misleading, as it suggests the version exists but contains no files. It is safer to return undefined to signal a fetch failure. Additionally, verifying that listing.items exists before iterating prevents potential runtime errors if the API response structure is unexpected. Ensure that parsing of query parameters or API responses gracefully handles invalid inputs by providing sensible fallbacks or defaults.

Suggested change
if (!listing) {
return { items: [], nextParams: null };
}
if (!listing?.items) {
return;
}
References
  1. Ensure that parsing of query parameters gracefully handles invalid inputs (e.g., non-numeric values) by providing sensible fallbacks or defaults, rather than causing unexpected behavior.

const items: BinaryItem[] = [];
// <Blob><Name>124.0.2478.97/edgedriver_arm64.zip</Name><Url>https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/124.0.2478.97/edgedriver_arm64.zip</Url><Properties><Last-Modified>Fri, 10 May 2024 18:35:44 GMT</Last-Modified><Etag>0x8DC712000713C13</Etag><Content-Length>9191362</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding /><Content-Language /><Content-MD5>1tjPTf5JU6KKB06Qf1JOGw==</Content-MD5><Cache-Control /><BlobType>BlockBlob</BlobType><LeaseStatus>unlocked</LeaseStatus></Properties></Blob>
const fileRe =
/<Blob><Name>([^<]+?)<\/Name><Url>([^<]+?)<\/Url><Properties><Last-Modified>([^<]+?)<\/Last-Modified><Etag>(?:[^<]+?)<\/Etag><Content-Length>(\d+)<\/Content-Length>/g;
const matchItems = xml.matchAll(fileRe);
for (const m of matchItems) {
const fullname = m[1].trim();
// <Blob>
// <Name>124.0.2478.97/edgedriver_arm64.zip</Name>
// <Url>https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/124.0.2478.97/edgedriver_arm64.zip</Url>
// <Properties>
// <Last-Modified>Fri, 10 May 2024 18:35:44 GMT</Last-Modified>
// <Etag>0x8DC712000713C13</Etag>
// <Content-Length>9191362</Content-Length>
// <Content-Type>application/octet-stream</Content-Type>
// <Content-Encoding/>
// <Content-Language/>
// <Content-MD5>1tjPTf5JU6KKB06Qf1JOGw==</Content-MD5>
// <Cache-Control/>
// <BlobType>BlockBlob</BlobType>
// <LeaseStatus>unlocked</LeaseStatus>
// </Properties>
// </Blob>
// ignore size = 0 dir
const name = path.basename(fullname);
const url = m[2].trim();
const date = m[3].trim();
const size = Number.parseInt(m[4].trim());
for (const entry of listing.items) {
if (entry.isDirectory) continue;
if (!entry.name.startsWith(subDir)) continue;
// Only direct children of `subDir`, not nested paths.
const rest = entry.name.slice(subDir.length);
if (!rest || rest.includes('/')) continue;
items.push({
name,
name: rest,
isDir: false,
url,
size,
date,
url: `${EDGEDRIVER_DOWNLOAD_BASE}${entry.name}`,
size: entry.contentLength,
date: entry.lastModified,
});
}
return items;
return { items, nextParams: null };
}

async #fetchListing(): Promise<EdgedriverListing | undefined> {
const { data, status, headers } = await this.httpclient.request(EDGEDRIVER_LISTING_URL, {
dataType: 'json',
timeout: 30_000,
followRedirect: true,
gzip: true,
});
if (status !== 200) {
this.logger.warn(
'[EdgedriverBinary.fetchListing:non-200-status] url: %s, status: %s, headers: %j, data: %j',
EDGEDRIVER_LISTING_URL,
status,
headers,
data,
);
return;
}
return data as EdgedriverListing;
}
}
12 changes: 8 additions & 4 deletions test/common/adapter/binary/EdgedriverBinary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe('test/common/adapter/binary/EdgedriverBinary.test.ts', () => {
data: await TestUtil.readFixturesFile('edgeupdates.json'),
persist: false,
});
app.mockHttpclient('https://msedgedriver.microsoft.com/listing.json', 'GET', {
data: await TestUtil.readFixturesFile('msedgedriver-listing.json'),
persist: false,
});
let result = await binary.fetch('/');
assert.deepEqual(result, {
items: [
Expand Down Expand Up @@ -63,13 +67,13 @@ describe('test/common/adapter/binary/EdgedriverBinary.test.ts', () => {
// {
// name: 'edgedriver_win64.zip',
// isDir: false,
// url: 'https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/126.0.2578.0/edgedriver_win64.zip',
// url: 'https://msedgedriver.microsoft.com/126.0.2578.0/edgedriver_win64.zip',
// size: 9564395,
// date: 'Fri, 10 May 2024 17:04:10 GMT'
// date: '2024-05-10T17:04:10+00:00'
// }
assert.equal(item.isDir, false);
assert.match(item.name, /^edgedriver_\w+.zip$/);
assert.match(item.url, /^https:\/\//);
assert.match(item.name, /^edgedriver_[\w]+\.zip$/);
assert.match(item.url, /^https:\/\/msedgedriver\.microsoft\.com\//);
assert.ok(typeof item.size === 'number');
assert.ok(item.size > 0);
assert.ok(item.date);
Expand Down
35 changes: 35 additions & 0 deletions test/fixtures/msedgedriver-listing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"items": [
{
"isDirectory": false,
"name": "126.0.2578.0/edgedriver_arm64.zip",
"contentLength": 9085682,
"lastModified": "2024-05-10T17:03:37+00:00"
},
{
"isDirectory": false,
"name": "126.0.2578.0/edgedriver_mac64.zip",
"contentLength": 10907611,
"lastModified": "2024-05-10T16:37:33+00:00"
},
{
"isDirectory": false,
"name": "126.0.2578.0/edgedriver_mac64_m1.zip",
"contentLength": 10090619,
"lastModified": "2024-05-10T16:37:33+00:00"
},
{
"isDirectory": false,
"name": "126.0.2578.0/edgedriver_win32.zip",
"contentLength": 8759537,
"lastModified": "2024-05-10T17:04:29+00:00"
},
{
"isDirectory": false,
"name": "126.0.2578.0/edgedriver_win64.zip",
"contentLength": 9564395,
"lastModified": "2024-05-10T17:04:10+00:00"
}
],
"generatedAt": "2026-04-08T13:18:30.7241345+00:00"
}
Loading