Skip to content

Conversation

withinboredom
Copy link
Member

This one is interesting — though I’m not sure the best way to provide a test. I will have to look into maybe an integration test because it is a careful dance between how we resolve paths in the Caddy module vs. workers. I looked into making a proper change (literally using the same logic everywhere), but I think it is best to wait until #1646 is merged.

But anyway, this change deals with some interesting edge cases. I will use gherkin to describe them:

Feature: FrankenPHP symlinked edge cases
  Background: 
    Given a `test` folder
    And a `public` folder linked to `test`
    And a worker script located at `test/index.php`
    And a `test/nested` folder
    And a worker script located at `test/nested/index.php`
  Scenario: neighboring worker script
    Given frankenphp located in the test folder
    When I execute `frankenphp php-server --listen localhost:8080 -w index.php` from `public`
    Then I expect to see the worker script executed successfully
  Scenario: nested worker script
    Given frankenphp located in the test folder
    When I execute `frankenphp --listen localhost:8080 -w nested/index.php` from `public`
    Then I expect to see the worker script executed successfully
  Scenario: outside the symlinked folder
    Given frankenphp located in the root folder
    When I execute `frankenphp --listen localhost:8080 -w public/index.php` from the root folder
    Then I expect to see the worker script executed successfully
  Scenario: specified root directory
    Given frankenphp located in the root folder
    When I execute `frankenphp --listen localhost:8080 -w public/index.php -r public` from the root folder
    Then I expect to see the worker script executed successfully    

Trying to write that out in regular English would be more complex IMHO.

These scenarios should all pass now with this PR.

Comment on lines +81 to +84
absFileName, err := filepath.EvalSymlinks(o.fileName)
if err != nil {
return nil, fmt.Errorf("worker filename is invalid %q: %w", o.fileName, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍 explicitly checking if a worker exists is something I actually wanted to do for a long time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or wait, evalSymlinks will just evaluate symlinks. In that case it would also be nice to error right away if there's no file there. Can also be done in another PR though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it errors if the file doesn't exist (I had to update a failing test -- haven't pushed the commit yet)

//If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
//resolve to a different directory than the one we are currently in.
//This is especially important if there are workers running.
documentRootOption = frankenphp.WithRequestDocumentRoot(documentRoot, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking for symlinks here seems like it might break some setups. Definitely would be nice to test all the edge cases somehow (should be possible with caddy_tests?).

Tbh though, I don't know what the current edge cases with symlinks are

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m pretty sure we don’t want to evaluate symlinks here. In the case where a document root was expressly given (such as prod setups), we will never even enter this branch. In the case where a document root isn’t given, we need to be compatible with how we resolve workers. There is an edge case here that I didn’t cover, and I’m working out how to handle it: chained symlinks.

I suspect I’ll have to go back to the drawing board.

@henderkes
Copy link
Contributor

do the edge cases only affect workers, not regular php requests?

Comment on lines +151 to +153
//If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
//resolve to a different directory than the one we are currently in.
//This is especially important if there are workers running.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
//resolve to a different directory than the one we are currently in.
//This is especially important if there are workers running.
// If we do not have a resolved document root, then we cannot resolve the symlink of our cwd because it may
// resolve to a different directory than the one we are currently in.
// This is especially important if there are workers running.

Comment on lines +78 to +80
//Order is important!
//This order ensures that FrankenPHP started from inside a symlinked directory will properly resolve any paths.
//If it is started from outside a symlinked directory, it is resolved to the same path that we use in the Caddy module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Order is important!
//This order ensures that FrankenPHP started from inside a symlinked directory will properly resolve any paths.
//If it is started from outside a symlinked directory, it is resolved to the same path that we use in the Caddy module.
// Order is important!
// This order ensures that FrankenPHP started from inside a symlinked directory will properly resolve any paths.
// If it is started from outside a symlinked directory, it is resolved to the same path that we use in the Caddy module.

@withinboredom
Copy link
Member Author

@henderkes yes, only workers. I should have a nice test suite this weekend. Manually testing this is annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants