Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions packages/filesystem/baidu/baidu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ describe("BaiduFileSystem", () => {
});
});

it("写入时预创建请求应走 https,避免 access_token 明文传输", async () => {
const fs = new BaiduFileSystem("/apps", "token");
const request = vi.spyOn(fs, "request").mockResolvedValue({ errno: 2, errmsg: "access denied" });
const writer = await fs.create("dir/file.user.js");

await expect(writer.write("code")).rejects.toMatchObject({ provider: "baidu" });
expect(request.mock.calls[0][0]).toMatch(/^https:\/\/pan\.baidu\.com\/rest\/2\.0\/xpan\/file\?method=precreate&/);
});

it("读取文件元数据缺失时应抛出 typed not found 错误", async () => {
const fs = new BaiduFileSystem("/apps", "token");
vi.spyOn(fs, "request").mockResolvedValue({ errno: -9, errmsg: "file not found" });
Expand Down
2 changes: 1 addition & 1 deletion packages/filesystem/baidu/rw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class BaiduFileWriter implements FileWriter {
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
let data = await this.fs.request(
`http://pan.baidu.com/rest/2.0/xpan/file?method=precreate&access_token=${this.fs.accessToken}`,
`https://pan.baidu.com/rest/2.0/xpan/file?method=precreate&access_token=${this.fs.accessToken}`,
{
method: "POST",
headers: myHeaders,
Expand Down
4 changes: 4 additions & 0 deletions scripts/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,9 @@ export function createFirefoxManifest(manifest, agentEnabled, firefoxId) {
)
);
delete result.message_serialization;
// 不声明时 Firefox MV3 扩展页面默认 CSP 为 "script-src 'self'; upgrade-insecure-requests;",
// 后台页发出的 GM_xmlhttpRequest 等 http:// 请求会被强制升级为 https:// 而失败(#1846)。
// 显式声明后脚本策略与默认一致,只去掉 upgrade-insecure-requests,与 Chrome MV3 行为对齐。
result.content_security_policy = { ...result.content_security_policy, extension_pages: "script-src 'self';" };
return result;
}
16 changes: 16 additions & 0 deletions scripts/build-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,20 @@ describe("构建配置 - 浏览器专用 manifest", () => {
expect(source.optional_permissions).toEqual(["background", "userScripts"]);
expect(source.background).toHaveProperty("service_worker");
});

it("Firefox 产物显式声明扩展页面 CSP,不带默认的 upgrade-insecure-requests(#1846)", () => {
const source = {
permissions: [],
optional_permissions: [],
background: { scripts: ["src/service_worker.js"] },
sandbox: { pages: ["src/sandbox.html"] },
};

const result = createFirefoxManifest(source, true, "{firefox-id}");

expect(result.content_security_policy).toEqual({
sandbox: FIREFOX_SANDBOX_CSP,
extension_pages: "script-src 'self';",
});
});
});
11 changes: 7 additions & 4 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ export default defineConfig({
name: "fast",
exclude: [...BASE_EXCLUDE, ...ISOLATED, ...UI_TESTS, ...SCRIPT_TESTS],
...sharedTest,
pool: "vmThreads",
isolate: false,
// 本地单 worker 时改用 threads + isolate:Vitest 对 vm 池强制 isolate=false,且在 maxWorkers 为 1 时
// 把整个项目合并进同一个 VM 上下文(setup 只跑一次),模块缓存、vi.mock、chrome mock 在文件间互相泄漏。
pool: process.env.CI ? "vmThreads" : "threads",
isolate: !process.env.CI,
maxWorkers: process.env.CI ? "75%" : 1,
testTimeout: 340,
sequence: {
Expand Down Expand Up @@ -101,8 +103,9 @@ export default defineConfig({
include: UI_TESTS,
exclude: BASE_EXCLUDE,
...sharedTest,
pool: "vmThreads",
isolate: false,
// 本地 pool/isolate 取值原因同 fast 项目
pool: process.env.CI ? "vmThreads" : "threads",
isolate: !process.env.CI,
// UI renders and V8 coverage are CPU-bound; leave headroom for the fast/scripts projects
// so the fixed 850ms per-test budget measures the test rather than worker starvation.
maxWorkers: process.env.CI ? "50%" : 1,
Expand Down
Loading