|
| 1 | +import { create } from '../../../__tests__/util'; |
| 2 | + |
| 3 | +describe('chmod 0 permission issue reproduction', () => { |
| 4 | + // ❌ FAILURE - should return false but returns true |
| 5 | + test('chmod on file and existsSync', () => { |
| 6 | + // Arrange |
| 7 | + const vol = create({ '/path/to/file.txt': 'some text' }); |
| 8 | + vol.chmodSync('/path/to/file.txt', 0o0000); |
| 9 | + |
| 10 | + // Act |
| 11 | + const exists = vol.existsSync('/path/to/file.txt'); |
| 12 | + |
| 13 | + // Assert |
| 14 | + expect(exists).toBe(false); |
| 15 | + }); |
| 16 | + |
| 17 | + // ✅ SUCCESS - this should already work |
| 18 | + test('chmod on directory and existsSync', () => { |
| 19 | + // Arrange |
| 20 | + const vol = create({ '/path/to/file.txt': 'some text' }); |
| 21 | + vol.chmodSync('/path/to/', 0o0000); |
| 22 | + |
| 23 | + // Act |
| 24 | + const exists = vol.existsSync('/path/to/file.txt'); |
| 25 | + |
| 26 | + // Assert |
| 27 | + expect(exists).toBe(false); |
| 28 | + }); |
| 29 | + |
| 30 | + // ❌ FAILURE - should throw but doesn't throw |
| 31 | + test.each([4 /* R_OK */, 2 /* W_OK */])('chmod on file and access mode %d', mode => { |
| 32 | + // Arrange |
| 33 | + const vol = create({ '/path/to/file.txt': 'some text' }); |
| 34 | + vol.chmodSync('/path/to/file.txt', 0o0000); |
| 35 | + |
| 36 | + // Act & Assert |
| 37 | + expect(() => { |
| 38 | + vol.accessSync('/path/to/file.txt', mode); |
| 39 | + }).toThrow(); |
| 40 | + }); |
| 41 | + |
| 42 | + // ✅ SUCCESS - this should already work |
| 43 | + test.each([4 /* R_OK */, 2 /* W_OK */])('chmod on directory and access mode %d', mode => { |
| 44 | + // Arrange |
| 45 | + const vol = create({ '/path/to/file.txt': 'some text' }); |
| 46 | + vol.chmodSync('/path/to/', 0o0000); |
| 47 | + |
| 48 | + // Act & Assert |
| 49 | + expect(() => { |
| 50 | + vol.accessSync('/path/to/file.txt', mode); |
| 51 | + }).toThrow(); |
| 52 | + }); |
| 53 | + |
| 54 | + // F_OK should NOT throw - it just checks existence |
| 55 | + test('chmod on file and access F_OK should not throw', () => { |
| 56 | + const vol = create({ '/path/to/file.txt': 'some text' }); |
| 57 | + vol.chmodSync('/path/to/file.txt', 0o0000); |
| 58 | + |
| 59 | + // F_OK should not throw - file exists |
| 60 | + expect(() => { |
| 61 | + vol.accessSync('/path/to/file.txt', 0 /* F_OK */); |
| 62 | + }).not.toThrow(); |
| 63 | + }); |
| 64 | + |
| 65 | + // Test the exact scenario from the issue using promises API and fs constants |
| 66 | + test('chmod on file and promises access with fs.constants', async () => { |
| 67 | + const vol = create({ '/path/to/file.txt': 'some text' }); |
| 68 | + |
| 69 | + await vol.promises.chmod('/path/to/file.txt', 0o0000); |
| 70 | + |
| 71 | + // Should throw for R_OK and W_OK |
| 72 | + await expect(vol.promises.access('/path/to/file.txt', 4 /* R_OK */)).rejects.toThrow(); |
| 73 | + await expect(vol.promises.access('/path/to/file.txt', 2 /* W_OK */)).rejects.toThrow(); |
| 74 | + |
| 75 | + // F_OK should NOT throw - it just checks existence, which it does exist |
| 76 | + await expect(vol.promises.access('/path/to/file.txt', 0 /* F_OK */)).resolves.toBeUndefined(); |
| 77 | + }); |
| 78 | +}); |
0 commit comments