Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs_permissions does not work with symlinked paths #6981

Closed
2 tasks
oveddan opened this issue Feb 1, 2024 · 1 comment
Closed
2 tasks

fs_permissions does not work with symlinked paths #6981

oveddan opened this issue Feb 1, 2024 · 1 comment
Labels
T-bug Type: bug

Comments

@oveddan
Copy link

oveddan commented Feb 1, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (2b2a499 2024-01-31T17:46:44.163875000Z)

What command(s) is the bug in?

any forge scripting or test commands

Operating System

macOS (Apple Silicon)

Describe the bug

A fully reproduceable example of this issue can be seen in this github repo

I have a monorepo setup, where I want to be able to import a package within the same monorepo, and read some files from it in forge scripts. For a basic example of this kind of setup:

My folder structure is:

packages/imported/files/config.json
packages/contracts/test/ImportTest.t.sol

The imported project is installed via npm packages, and as a result is symlinked within the node_modules folder of the contracts project:

packages/contracts/node_modules/@repo/imported/files/config.json -> packages/imported/files/config.json

To see if this file can be loaded I created a simple test in:
packages/contracts/test/ImportTest.t.sol:

import "forge-std/Test.sol";

contract ImportTest is Test {
    function test_can_import_file_from_node_modules() public {
        string memory jsonString = vm.readFile(
            "node_modules/@repo/imported/files/config.json"
        );
    }
}

my packages/contracts/foundry.toml is configured to allow these paths:

fs_permissions = [
  { access = "read", path = "./node_modules/@repo/imported/files/config.json" },
  { access = "read", path = "./node_modules/@repo/imported/files" },
  { access = "read", path = "../imported/files" },
  { access = "read", path = "../imported/files/config.json" },
]

Yet when I run this test I get an error "[FAIL. Reason: the path node_modules/@repo/imported/files/config.json is not allowed to be accessed for read operations]"

If I manually copy the folder into the same exact location, with the commands:
cd packages/contracts && rm -r node_modules/@repo/imported && cp -r ../imported node_modules/@repo/imported

Then I can run the tests successfully.

I believe the cause is that the path is symlinked and forge may be treating the path as one outside the project folder.

This is not an issue with code imported from those symlinked folders

@oveddan oveddan added the T-bug Type: bug label Feb 1, 2024
@oveddan oveddan changed the title fs_permissions does not work with symlinked paths or paths below the root fs_permissions does not work with symlinked paths Feb 1, 2024
mattsse pushed a commit that referenced this issue Feb 9, 2024
* - find permission for resolved sym links

* Use dunce to canonicalize permission path

* Add integration tests
- for default fs permissions config
- for parsing custom fs permissions
- to resolve symlink permissions

* Fix clippy target
@DaniPopes
Copy link
Member

#7022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Status: Completed
Development

No branches or pull requests

2 participants