Skip to content

Add tests for IPv4/IPv6 with CIDR mask in sudoHost#32

Open
shridhargadekar wants to merge 1 commit into
RedHat-SP-Security:masterfrom
shridhargadekar:sudo_ipv4_masked
Open

Add tests for IPv4/IPv6 with CIDR mask in sudoHost#32
shridhargadekar wants to merge 1 commit into
RedHat-SP-Security:masterfrom
shridhargadekar:sudo_ipv4_masked

Conversation

@shridhargadekar
Copy link
Copy Markdown
Collaborator

@shridhargadekar shridhargadekar commented May 15, 2026

  • test_sudo__host_ipv4_ipv6_with_mask_allowed: allowed access when client IP matches sudoHost (IPv4 with mask, IPv6, IPv6 with mask)

  • test_sudo__host_ipv4_ipv6_with_mask_denied: Tests denied access when client IP doesn't match sudoHost

Each test is parameterized to cover 3 scenarios (6 total test runs). Tests verify that sudoHost works correctly with IPv4/IPv6 addresses and CIDR notation

Summary by Sourcery

Add critical sudoHost IP-based sudo rule tests covering IPv4/IPv6 address and CIDR mask handling for allowed and denied access scenarios.

Tests:

  • Add parameterized tests verifying sudo access is allowed when client IP matches sudoHost IPv4/IPv6 addresses and CIDR masks.
  • Add parameterized tests verifying sudo access is denied when client IP does not match sudoHost IPv4/IPv6 addresses and CIDR masks.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 15, 2026

Reviewer's Guide

Adds two critical BareLDAP sudo tests that validate sudoHost behavior for IPv4/IPv6 addresses with and without CIDR masks, covering both allowed and denied access cases based on client IP matching.

File-Level Changes

Change Details Files
Add positive sudoHost IP matching test covering IPv4/IPv6 with and without CIDR masks.
  • Introduce parameterized test that runs three scenarios (IPv4 with mask, IPv6, IPv6 with mask) using ip/ip -6 to assign the test IP to loopback.
  • Create LDAP user and IP-based sudorule, enable SSSD sudo responder, and start SSSD within the test setup.
  • Assert that sudo rule listing and sudo command execution both succeed when client IP matches sudoHost and ensure IP cleanup in a finally block.
pytest/tests/test_sudo.py
Add negative sudoHost IP mismatch test covering IPv4/IPv6 with non-matching addresses and CIDR masks.
  • Introduce parameterized test with three non-matching IP scenarios to validate denial behavior for sudoHost with IPv4 mask, bare IPv6, and IPv6 with mask.
  • Reuse the same LDAP user and sudorule creation plus SSSD configuration, but assert that sudo list and command execution both fail.
  • Ensure added IP addresses (IPv4/IPv6) are removed from loopback in a finally block to avoid cross-test interference.
pytest/tests/test_sudo.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

Copy link
Copy Markdown

@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 - I've left some high level feedback:

  • The two tests share a lot of setup/teardown logic (configuring client IP, adding user/sudorule, starting SSSD, and deleting IP); consider extracting this into a helper or fixture and parameterizing only the expected outcome to reduce duplication and make future changes easier.
  • Using if "ipv6" in ip_type to decide whether to use IPv6-specific commands is a bit fragile; switching to an explicit enum or boolean flag (e.g., is_ipv6) in the parametrization would make the logic clearer and less error-prone if additional IP types are added later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The two tests share a lot of setup/teardown logic (configuring client IP, adding user/sudorule, starting SSSD, and deleting IP); consider extracting this into a helper or fixture and parameterizing only the expected outcome to reduce duplication and make future changes easier.
- Using `if "ipv6" in ip_type` to decide whether to use IPv6-specific commands is a bit fragile; switching to an explicit enum or boolean flag (e.g., `is_ipv6`) in the parametrization would make the logic clearer and less error-prone if additional IP types are added later.

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.

- test_sudo__host_ipv4_ipv6_with_mask_allowed:
    allowed access when client IP matches sudoHost
    (IPv4 with mask, IPv6, IPv6 with mask)

- test_sudo__host_ipv4_ipv6_with_mask_denied:
    Tests denied access when client IP doesn't match sudoHost

Each test is parameterized to cover 3 scenarios (6 total test runs).
Tests verify that sudoHost works correctly with IPv4/IPv6 addresses and CIDR notation

Signed-off-by: shridhargadekar <shridhar.always@gmail.com>
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