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

feat(auth): allow passwords with empty usernames #10088

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abn
Copy link
Member

@abn abn commented Jan 21, 2025

This change largely reverts the decision made in b544ed5 as it seems that it is commonplace, albeit not best practice, for private indices to require or document that users use an empty username. The change in behaviour seems to surprise users migrating from 1.x (#10085).

Summary by Sourcery

Allow empty usernames for private repositories.

Bug Fixes:

  • Fix unexpected behavior when migrating from Poetry 1.x with private indices requiring empty usernames.

Enhancements:

  • Improve compatibility with private indices that require or document empty usernames for authentication.

@abn abn requested a review from a team January 21, 2025 14:30
Copy link

sourcery-ai bot commented Jan 21, 2025

Reviewer's Guide by Sourcery

This pull request allows the use of empty usernames when authenticating against a repository. This is done by storing the password in the keyring with a special username if the username is empty. This change also updates the documentation to reflect this change.

Sequence diagram for password retrieval with empty username

sequenceDiagram
    participant Client
    participant PasswordManager
    participant Keyring

    Client->>PasswordManager: get_password(name, username='')
    alt username is empty
        PasswordManager->>Keyring: get_password(name, '__poetry_source_empty_username__')
    else username is not empty
        PasswordManager->>Keyring: get_password(name, username)
    end
    Keyring-->>PasswordManager: password
    PasswordManager-->>Client: password
Loading

Class diagram for password manager changes

classDiagram
    class PoetryKeyring {
        -_namespace: str
        -_EMPTY_USERNAME_KEY: str
        +get_credential(name: str, username: str)
        +get_password(name: str, username: str)
        +set_password(name: str, username: str, password: str)
        +delete_password(name: str, username: str)
    }
    note for PoetryKeyring "Added _EMPTY_USERNAME_KEY constant
Modified methods to handle empty usernames"

    class HTTPAuthCredential {
        +username: str
        +password: str
    }
    note for HTTPAuthCredential "Now accepts empty username"
Loading

Flow diagram for password handling logic

flowchart TD
    A[Start] --> B{Username empty?}
    B -->|Yes| C[Use _EMPTY_USERNAME_KEY]
    B -->|No| D[Use provided username]
    C --> E[Store/retrieve password in keyring]
    D --> E
    E --> F[Return result]
    F --> G[End]
Loading

File-Level Changes

Change Details Files
Allow empty usernames when authenticating against a repository.
  • Added a special key to use when storing passwords with empty usernames in the keyring.
  • Modified the get_password, set_password, and delete_password methods to use the special key when the username is empty.
  • Modified the get_http_auth method to allow empty usernames.
src/poetry/utils/password_manager.py
Updated tests to reflect the change in behaviour.
  • Updated the tests to assert that empty usernames are allowed.
  • Updated the tests to assert that the correct username is used when authenticating against a repository.
tests/utils/test_password_manager.py
tests/utils/test_authenticator.py
Updated documentation to reflect the change in behaviour.
  • Updated the documentation to state that empty usernames are allowed, but discouraged.
  • Updated the documentation to explain how empty usernames are handled when storing passwords in the keyring.
docs/repositories.md
Added a fixture for the PoetryKeyring class.
  • Added a fixture for the PoetryKeyring class to be used in tests.
tests/conftest.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@abn abn added area/docs Documentation issues/improvements impact/docs Contains or requires documentation changes area/auth Related to the authenticator and keyring area/auth/keyring labels Jan 21, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @abn - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

tests/utils/test_password_manager.py Show resolved Hide resolved
Copy link

github-actions bot commented Jan 21, 2025

Deploy preview for website ready!

✅ Preview
https://website-90o28npim-python-poetry.vercel.app

Built with commit 6a49590.
This pull request is being automatically deployed with vercel-action

This change largely reverts the decision made in b544ed5 as it seems
that it is commonplace, albeit not best practice, for private indices
to require or document that users use an empty username. The change in
behaviour seems to surprise users migrating from 1.x (python-poetry#10085).
@abn abn force-pushed the fix/allow-empty-passwords branch from 8de076b to 6a49590 Compare January 21, 2025 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/auth/keyring area/auth Related to the authenticator and keyring area/docs Documentation issues/improvements impact/docs Contains or requires documentation changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant