Skip to content

Conversation

@jakub-vavra-cz
Copy link
Contributor

@jakub-vavra-cz jakub-vavra-cz commented Nov 19, 2025

Add test for 'sudo passes SHELL twice'
Add tests for regex in command.
Add some basic sudo tests.

Depends on SSSD/sssd-test-framework#222

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 19, 2025

Reviewer's Guide

Introduces a new pytest to verify that SSSD’s sudo responder does not duplicate the SHELL environment variable, leveraging the existing test framework roles and topologies and addressing related JIRA tickets.

File-Level Changes

Change Details Files
Add new pytest test to verify SHELL is passed only once by the SSSD sudo responder
  • Create pytest/tests/test_misc_issues.py file
  • Import Client, GenericProvider, KnownTopology, and pytest
  • Define test__env_shell_once with setup (zsh install, user and sudorule creation), execution, and assertions
  • Annotate test with pytest marks for importance, topology variants, and JIRA tickets
pytest/tests/test_misc_issues.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@jakub-vavra-cz jakub-vavra-cz marked this pull request as draft November 19, 2025 09:38
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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `pytest/tests/test_misc_issues.py:43` </location>
<code_context>
+    client.sssd.start()
+    result = client.auth.sudo.run("user-1", "Secret123", command="/usr/bin/env")
+    assert result.returncode == 0, "Sudo command failed!"
+    assert result.stdout.count("SHELL") == 1, "Variable SHELL is duplicated!"
</code_context>

<issue_to_address>
**suggestion:** Assertion could be more robust by checking for the exact environment variable format.

Instead of counting 'SHELL' occurrences, check for the exact line 'SHELL=/bin/zsh' or use a regex to verify the variable is present once and correctly formatted.
</issue_to_address>

### Comment 2
<location> `pytest/tests/test_misc_issues.py:35-37` </location>
<code_context>
+        2. Variable SHELL is present only once
+    :customerscenario: True
+    """
+    client.host.ssh.run("dnf install zsh -y")
+    u = provider.user("user-1").add(uid=10001, gid=10001, shell="/bin/zsh")
+    provider.sudorule("test").add(user=u, host="ALL", command="/bin/env")
</code_context>

<issue_to_address>
**suggestion (testing):** Test setup could be made more robust by checking installation success.

Please add an assertion to check the return code of the installation command to confirm zsh was installed successfully before proceeding with the test.

```suggestion
    install_result = client.host.ssh.run("dnf install zsh -y")
    assert install_result.returncode == 0, "Failed to install zsh!"
    u = provider.user("user-1").add(uid=10001, gid=10001, shell="/bin/zsh")
    provider.sudorule("test").add(user=u, host="ALL", command="/bin/env")
```
</issue_to_address>

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.

@jakub-vavra-cz jakub-vavra-cz force-pushed the rebase_1_9_17 branch 3 times, most recently from b4e1e76 to 5c0b987 Compare November 24, 2025 14:45
@jakub-vavra-cz jakub-vavra-cz force-pushed the rebase_1_9_17 branch 3 times, most recently from cfccb80 to 2517069 Compare December 2, 2025 09:37
Add new tests for basic sudo functionality.
Move/refactor basic tests from test_sudo suite.
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.

1 participant