Skip to content

Commit b3e139e

Browse files
committed
fix(tests): use a temp file instead of /etc/hosts in the local-path guard test
/etc/hosts does not exist on Windows runners, so the allow_local_paths assertion received null instead of an UploadedFile. A test-created temp file also proves the default rejection against a genuinely readable file.
1 parent 1869756 commit b3e139e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

tests/MCP/McpServerHardeningTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,20 @@ public function fields(RestifyRequest $request): array
211211
}
212212
};
213213

214-
$this->assertNull($repository->resolveUploadedFileFromInput('/etc/hosts'));
215-
$this->assertFalse($repository::isSafePublicUrl('/etc/hosts'));
214+
$localFile = tempnam(sys_get_temp_dir(), 'restify-mcp');
215+
file_put_contents($localFile, 'local file content');
216+
217+
$this->assertNull($repository->resolveUploadedFileFromInput($localFile));
218+
$this->assertFalse($repository::isSafePublicUrl($localFile));
216219

217220
config(['restify.mcp.files.allow_local_paths' => true]);
218221

219222
$this->assertInstanceOf(
220223
UploadedFile::class,
221-
$repository->resolveUploadedFileFromInput('/etc/hosts')
224+
$repository->resolveUploadedFileFromInput($localFile)
222225
);
226+
227+
unlink($localFile);
223228
}
224229

225230
public function test_private_and_reserved_ip_urls_are_rejected(): void

0 commit comments

Comments
 (0)