Skip to content

Fixed an issue where getpass.getuser() contained illegal characters for file directories #8365

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

Conversation

symonk
Copy link
Member

@symonk symonk commented Feb 22, 2021

closes #8317. It is possible that getpass.getuser() can be illegal characters not appropriate for a directory name (platform dependent etc). This PR addresses that by attempting it normally and backing off to use the default -of-unknown when it occurs. This is consistent when getuser() is not Truthy.

Appreciate the feed back, thanks again.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.


@pytest.fixture
def invalid_get_user(monkeypatch: MonkeyPatch) -> None:
Copy link
Member Author

@symonk symonk Feb 22, 2021

Choose a reason for hiding this comment

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

I'm not sure this works as I expected, seems OK locally for me, os/agnostic should be an invalid dirname on win/linux/darwin etc, will revisit! (it appears running from pycharm was A-OK and CLI was A-not-OK)


@pytest.fixture
def invalid_get_user(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setattr("getpass.getuser", lambda: "os/agnostic")
Copy link
Member

Choose a reason for hiding this comment

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

Cool, you might want to throw a few other characters there too:

Suggested change
monkeypatch.setattr("getpass.getuser", lambda: "os/agnostic")
monkeypatch.setattr("getpass.getuser", lambda: "os/:?*agnostic")

Copy link
Member Author

@symonk symonk Feb 23, 2021

Choose a reason for hiding this comment

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

thanks, @nicoddemus - any idea why the monkeypatch here is applied when running a single test from pycharm but not when running via pytest testing/tmp_dir.py or via tox -e py38 etc? Will update this after work later

Copy link
Member

Choose a reason for hiding this comment

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

I think it might be because the base temp directory is cached? I suggest to manually reset the base temp directory inside the test, or better yet, just extract the functionality from getbasetemp into a function and unittest that.

@symonk symonk marked this pull request as ready for review February 24, 2021 18:35
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks!

(Note to squash this before we merge it)

@symonk symonk merged commit b7f2d7c into pytest-dev:master Feb 25, 2021
@symonk symonk deleted the retry-dir-creation-on-illegal-dirname-characters branch February 25, 2021 08:29
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.

tmpdir creation fails when the username contains illegal characters for directory names
2 participants