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
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/transport/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | undefined>;

beforeEach(() => {
Expand Down
13 changes: 7 additions & 6 deletions src/transport/rest-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ function buildClient(http: ReturnType<typeof fakeHttpClient>, 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();
};
}
Expand Down
57 changes: 34 additions & 23 deletions src/uploads/upload.archive.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,12 +23,36 @@ function namesIn(buffer: Buffer): string[] {
.sort();
}

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(() => {
root = mkdtempSync(join(tmpdir(), 'launch-archive-'));
});

afterEach(() => {
jest.restoreAllMocks();
rmSync(root, { recursive: true, force: true });
});

Expand Down Expand Up @@ -203,19 +228,12 @@ describe('project archive', () => {
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 failure = (() => {
try {
archiveDirectory(root);
return undefined;
} catch (error) {
return error;
}
})();
const secret = join(root, 'secret.txt');
const readFile = denyAccessTo('readFileSync', secret);

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');
Expand All @@ -224,22 +242,15 @@ describe('project archive', () => {

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 failure = (() => {
try {
archiveDirectory(root);
return undefined;
} catch (error) {
return error;
}
})();
const locked = join(root, 'locked');
const readDirectory = denyAccessTo('readdirSync', locked);

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');
});
Expand Down
Loading