From 47c1ca0613ad0c83188f3974b56d4e93cca2326b Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Thu, 30 Apr 2026 11:13:55 +0300 Subject: [PATCH] Add a test checking that it is not possible to write outside of a current directory Signed-off-by: Ruslans Tarasovs --- .../src/stages/generate/helpers.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index 67b534417f..4285a26657 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -584,6 +584,43 @@ describe('helpers', () => { ).rejects.toThrow(/not allowed to refer to a location outside/i); }, ); + + it.each(['README.md', 'readme.md'])( + 'should write %s to a symlink docs directory if docs/index.md does not exist', + async fileName => { + mockDir.setContent({ + 'target/docs': {}, + docs: ctx => ctx.symlink('./target/docs'), + [fileName]: `${fileName} content`, + }); + + await patchIndexPreBuild({ + inputDir: mockDir.path, + logger: mockLogger, + }); + + await expect( + fs.readFile(mockDir.resolve('docs/index.md'), 'utf-8'), + ).resolves.toEqual(`${fileName} content`); + }, + ); + + it.each(['README.md', 'readme.md'])( + 'should reject writing %s if targe symlink points outside of the current directory', + async fileName => { + const anotherMockDir = createMockDirectory(); + + mockDir.setContent({ + docs: ctx => ctx.symlink(anotherMockDir.path), + 'information.md': 'information.md content', + [fileName]: `${fileName} content`, + }); + + await expect( + patchIndexPreBuild({ inputDir: mockDir.path, logger: mockLogger }), + ).rejects.toThrow(/not allowed to refer to a location outside/i); + }, + ); }); describe('addBuildTimestampMetadata', () => {