|
1 | 1 | import { execFileSync, spawnSync } from 'node:child_process' |
2 | | -import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' |
| 2 | +import { chmodSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs' |
3 | 3 | import { tmpdir } from 'node:os' |
4 | 4 | import { join } from 'node:path' |
5 | 5 | import { fileURLToPath } from 'node:url' |
@@ -447,6 +447,24 @@ describe('install-cli.sh install_binary', () => { |
447 | 447 | } |
448 | 448 | }) |
449 | 449 |
|
| 450 | + // A shared install must stay readable by other users, whatever the installer's umask. |
| 451 | + it.skipIf(process.platform === 'win32')( |
| 452 | + 'installs a 0600 source as mode 0755 under umask 077', |
| 453 | + () => { |
| 454 | + const dir = mkdtempSync(join(tmpdir(), 'difyctl-install-')) |
| 455 | + try { |
| 456 | + const src = join(dir, 'new') |
| 457 | + const dest = join(dir, 'bin-difyctl') |
| 458 | + writeFileSync(src, 'new build', { mode: 0o600 }) |
| 459 | + const r = runLib(`umask 077; install_binary "${src}" "${dest}"`) |
| 460 | + expect(r.code).toBe(0) |
| 461 | + expect(statSync(dest).mode & 0o777).toBe(0o755) |
| 462 | + } finally { |
| 463 | + rmSync(dir, { recursive: true, force: true }) |
| 464 | + } |
| 465 | + }, |
| 466 | + ) |
| 467 | + |
450 | 468 | it('dies without touching the old binary when the folder is not writable', () => { |
451 | 469 | const r = runLib('install_binary /nonexistent/src /nonexistent-dir/difyctl') |
452 | 470 | expect(r.code).not.toBe(0) |
|
0 commit comments