|
1 | | -import { afterEach, beforeEach, describe, expect, it } from "bun:test"; |
| 1 | +import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test"; |
2 | 2 | import * as fsPromises from "node:fs/promises"; |
3 | 3 | import * as os from "node:os"; |
4 | 4 | import * as path from "node:path"; |
@@ -69,6 +69,23 @@ describe("EventSoundAssetService", () => { |
69 | 69 | ); |
70 | 70 | }); |
71 | 71 |
|
| 72 | + it("checks file size metadata before reading oversized local imports", async () => { |
| 73 | + const sourcePath = path.join(tempMuxHome, "oversize-by-metadata.wav"); |
| 74 | + await fsPromises.writeFile(sourcePath, ""); |
| 75 | + await fsPromises.truncate(sourcePath, MAX_AUDIO_FILE_SIZE_BYTES + 1); |
| 76 | + |
| 77 | + const readFileSpy = spyOn(fsPromises, "readFile"); |
| 78 | + try { |
| 79 | + await expectRejects( |
| 80 | + service.importFromLocalPath(sourcePath), |
| 81 | + "Audio file exceeds maximum allowed size" |
| 82 | + ); |
| 83 | + expect(readFileSpy).not.toHaveBeenCalled(); |
| 84 | + } finally { |
| 85 | + readFileSpy.mockRestore(); |
| 86 | + } |
| 87 | + }); |
| 88 | + |
72 | 89 | it("rejects local imports with unsupported extensions", async () => { |
73 | 90 | const sourcePath = path.join(tempMuxHome, "not-audio.txt"); |
74 | 91 | await fsPromises.writeFile(sourcePath, "not audio"); |
|
0 commit comments