From 4a7bdf98f7c17a67776ac79da6be18cc2ed90124 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 06:59:34 +0000 Subject: [PATCH 1/2] test: make the proxy and unreadable-file tests independent of the environment The transport tests cleared HTTPS_PROXY and HTTP_PROXY but not their lowercase forms, which the proxy resolver also reads, so a shell with https_proxy set failed four of them. The unreadable-file archive tests rely on chmod 000 denying access, which root ignores, so they now skip when run as root. --- .talismanrc | 4 ++-- src/transport/errors.test.ts | 2 +- src/transport/rest-client.test.ts | 13 +++++++------ src/uploads/upload.archive.test.ts | 6 ++++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.talismanrc b/.talismanrc index eb94737d..4c986bc9 100644 --- a/.talismanrc +++ b/.talismanrc @@ -14,7 +14,7 @@ fileignoreconfig: - filename: src/transport/rest-client.ts checksum: 3e44b756be0647422309cb14137bc18f5707cd42de6dd638abd2e0b625fda894 - filename: src/transport/rest-client.test.ts - checksum: 8f08eb868bb8d608a0d31800c103f7b257f8f414d0fdc6b06ef4ab62acfffd85 + checksum: 17bc7bde3433ca57a787917be15ff15ef36ab48f0a20b41a1f668f6ac0796a7b - filename: src/transport/cma-client.ts checksum: 87b8399a9b84ea60fe322802c2e5270772858ba85ac33c436941fe7cf40afc38 - filename: src/transport/auth-strategy.test.ts @@ -297,7 +297,7 @@ fileignoreconfig: - filename: src/functions/function.errors.test.ts checksum: ac0a55e5bee974fefa9fb95541adba63e9a2c2c6e6c47b87c8ca1022542e75f0 - filename: src/transport/errors.test.ts - checksum: 72bd1e9af33dbb9dd4e86803534ebadbda37af5f0aeeefb4f99734cf027c7f39 + checksum: 75f4d651c4dc1889309e3016fd2b1d1431bd4e7e92e186635c61cf5e1344c310 - filename: src/transport/auth-strategy.ts checksum: 6fe87def1b508cb67203d4445d9bd889570e512ed4194dfc4fdd3182bc8b87b2 - filename: src/functions/function.logger.test.ts diff --git a/src/transport/errors.test.ts b/src/transport/errors.test.ts index 5ab9d21a..a3156083 100644 --- a/src/transport/errors.test.ts +++ b/src/transport/errors.test.ts @@ -271,7 +271,7 @@ describe('LaunchApiError exit code', () => { }); describe('diagnoseTransportError', () => { - const PROXY_ENV_KEYS = ['HTTPS_PROXY', 'HTTP_PROXY']; + const PROXY_ENV_KEYS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy']; let saved: Record; beforeEach(() => { diff --git a/src/transport/rest-client.test.ts b/src/transport/rest-client.test.ts index b6bbdafa..aaf38f03 100644 --- a/src/transport/rest-client.test.ts +++ b/src/transport/rest-client.test.ts @@ -87,16 +87,17 @@ function buildClient(http: ReturnType, overrides = {}) { }); } +const PROXY_ENV_KEYS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy']; + function withoutProxy(): () => void { const configSpy = jest.spyOn(configHandler, 'get').mockImplementation(() => undefined); - const savedHttps = process.env.HTTPS_PROXY; - const savedHttp = process.env.HTTP_PROXY; - delete process.env.HTTPS_PROXY; - delete process.env.HTTP_PROXY; + const saved = PROXY_ENV_KEYS.map((key) => [key, process.env[key]] as const); + PROXY_ENV_KEYS.forEach((key) => delete process.env[key]); return () => { - if (savedHttps !== undefined) process.env.HTTPS_PROXY = savedHttps; - if (savedHttp !== undefined) process.env.HTTP_PROXY = savedHttp; + saved.forEach(([key, value]) => { + if (value !== undefined) process.env[key] = value; + }); configSpy.mockRestore(); }; } diff --git a/src/uploads/upload.archive.test.ts b/src/uploads/upload.archive.test.ts index 8a59a70b..4254832e 100644 --- a/src/uploads/upload.archive.test.ts +++ b/src/uploads/upload.archive.test.ts @@ -22,6 +22,8 @@ function namesIn(buffer: Buffer): string[] { .sort(); } +const itUnlessRoot = process.getuid?.() === 0 ? it.skip : it; + describe('project archive', () => { beforeEach(() => { root = mkdtempSync(join(tmpdir(), 'launch-archive-')); @@ -200,7 +202,7 @@ describe('project archive', () => { ); }); - it('refuses with a usage error naming a file it could not read', () => { + itUnlessRoot('refuses with a usage error naming a file it could not read', () => { file('index.html'); file('secret.txt'); chmodSync(join(root, 'secret.txt'), 0o000); @@ -222,7 +224,7 @@ describe('project archive', () => { expect((failure as UsageError).message).toContain('cannot be read'); }); - it('refuses with a usage error naming a directory it could not list', () => { + itUnlessRoot('refuses with a usage error naming a directory it could not list', () => { file('index.html'); mkdirSync(join(root, 'locked')); file('locked/a.txt'); From 4a44ddc2f78e0b69d03f0f1b53cceeb2a82797f4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 09:04:04 +0000 Subject: [PATCH 2/2] test: deny archive reads with an EACCES mock instead of chmod The unreadable-file and unreadable-directory tests relied on chmod 000, which root ignores, so the previous commit skipped them as root. Make readFileSync and readdirSync throw EACCES for the one path instead, so both tests run, and can fail, for every user. They assert the denied path was read and the UsageError the user gets. --- src/uploads/upload.archive.test.ts | 61 +++++++++++++++++------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/uploads/upload.archive.test.ts b/src/uploads/upload.archive.test.ts index 4254832e..abd9b067 100644 --- a/src/uploads/upload.archive.test.ts +++ b/src/uploads/upload.archive.test.ts @@ -1,4 +1,5 @@ import AdmZip from 'adm-zip'; +import fs from 'node:fs'; import { chmodSync, mkdtempSync, mkdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; @@ -22,7 +23,28 @@ function namesIn(buffer: Buffer): string[] { .sort(); } -const itUnlessRoot = process.getuid?.() === 0 ? it.skip : it; +function permissionDenied(path: string): NodeJS.ErrnoException { + return Object.assign(new Error(`EACCES: permission denied, '${path}'`), { code: 'EACCES', errno: -13, path }); +} + +function denyAccessTo(method: 'readFileSync' | 'readdirSync', denied: string): jest.SpyInstance { + const real = fs[method] as (...args: unknown[]) => unknown; + return jest.spyOn(fs, method).mockImplementation(((path: unknown, ...rest: unknown[]) => { + if (path === denied) { + throw permissionDenied(denied); + } + return real(path, ...rest); + }) as never); +} + +function thrownBy(run: () => unknown): unknown { + try { + run(); + return undefined; + } catch (error) { + return error; + } +} describe('project archive', () => { beforeEach(() => { @@ -30,6 +52,7 @@ describe('project archive', () => { }); afterEach(() => { + jest.restoreAllMocks(); rmSync(root, { recursive: true, force: true }); }); @@ -202,46 +225,32 @@ describe('project archive', () => { ); }); - itUnlessRoot('refuses with a usage error naming a file it could not read', () => { + it('refuses with a usage error naming a file it could not read', () => { file('index.html'); file('secret.txt'); - chmodSync(join(root, 'secret.txt'), 0o000); + const secret = join(root, 'secret.txt'); + const readFile = denyAccessTo('readFileSync', secret); - const failure = (() => { - try { - archiveDirectory(root); - return undefined; - } catch (error) { - return error; - } - })(); - - chmodSync(join(root, 'secret.txt'), 0o644); + const failure = thrownBy(() => archiveDirectory(root)); + expect(readFile).toHaveBeenCalledWith(secret); expect(failure).toBeInstanceOf(UsageError); expect((failure as UsageError).exitCode).toBe(2); expect((failure as UsageError).message).toContain('secret.txt'); expect((failure as UsageError).message).toContain('cannot be read'); }); - itUnlessRoot('refuses with a usage error naming a directory it could not list', () => { + it('refuses with a usage error naming a directory it could not list', () => { file('index.html'); - mkdirSync(join(root, 'locked')); file('locked/a.txt'); - chmodSync(join(root, 'locked'), 0o000); + const locked = join(root, 'locked'); + const readDirectory = denyAccessTo('readdirSync', locked); - const failure = (() => { - try { - archiveDirectory(root); - return undefined; - } catch (error) { - return error; - } - })(); - - chmodSync(join(root, 'locked'), 0o755); + const failure = thrownBy(() => archiveDirectory(root)); + expect(readDirectory).toHaveBeenCalledWith(locked); expect(failure).toBeInstanceOf(UsageError); + expect((failure as UsageError).exitCode).toBe(2); expect((failure as UsageError).message).toContain('locked'); expect((failure as UsageError).message).toContain('cannot be read'); });