Skip to content

Add Linux and Windows integration tests for sendmail path handling #4805

Open

Description

@coderabbitai

Summary

Add integration tests for sendmail executable-path handling on Linux and Windows. The current validation and configuration tests do not establish that Email_lib::sendEmail() executes the intended program safely on both operating systems.

app/Libraries/Email_lib.php passes the configured mailpath through escapeshellarg() before CodeIgniter builds the sendmail command. PHP and shell behavior differ across platforms. The tests must exercise the actual execution boundary, not just validate Windows-style strings on Linux.

Required coverage

Use a controlled sendmail fixture instead of a real mail server. Run the tests with protocol set to sendmail, using isolated temporary directories and cleanup. Use a native executable fixture on Windows.

  • Run the fixture from paths with and without spaces. Verify that the intended executable runs and receives the expected CodeIgniter arguments and message on standard input.
  • Append a harmless extra argument to the configured path. Verify that the argument is not passed as a separate argument and that no unintended executable runs.
  • Test harmless shell payloads that would create a temporary marker if interpreted. Check validation for inputs the rule is intended to reject, then bypass validation to test the execution boundary separately. Verify that no marker is created.
  • Exercise a missing executable and a fixture that exits with a nonzero status. Check whether the failure is reported through sendEmail() and investigate any framework limitations that prevent reliable failure reporting.
  • Save and reload a valid executable path containing spaces. Verify that the stored path remains unchanged and that the intended executable runs.
  • Align path-validation test expectations with the intended treatment of paths with spaces. Do not assume a character-based rule can distinguish a path containing spaces from a path followed by arguments.

Run the execution tests on both Linux and a separate Windows environment. A skipped test, including one skipped because popen() is unavailable, does not verify execution on that platform.

Affected areas

  • app/Libraries/Email_lib.php
  • app/Config/Validation/OSPOSRules.php
  • tests/Config/Validation/OSPOSRulesTest.php
  • tests/Controllers/ConfigControllerTest.php

Acceptance criteria

  • The integration tests exercise the real sendmail execution path on Linux and Windows and cover the cases above.
  • Legitimate executable paths containing spaces remain supported.
  • Test results record any failure-reporting limitation instead of assuming that the subprocess exit status reaches sendEmail().
  • Validation assertions match the intended behavior, and fixtures are cleaned up after each test.

Requested by @objecttothis.

Related PR: #4797
Related review discussion: #4797 (comment)

Activity

  1. objecttothis commented on Nov 9, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Assessment: Still present in master (not yet implemented).

    Checked tests/Config/Validation/OSPOSRulesTest.php on master (260483d): it only contains unit tests for OSPOSRules::valid_path_strict() string-validation behavior (the validPathStrictProvider data set covering injection payloads, Windows/Linux path strings, etc.) plus unrelated login-flow tests. There is no fixture-driven execution-boundary test that actually invokes Email_lib::sendEmail() with protocol = sendmail and a controlled sendmail fixture binary.

    A repo-wide code search for popen / sendEmail combined with test fixtures returned no results, and tests/Controllers/ConfigControllerTest.php likewise has no sendmail execution coverage. None of this matches the required coverage described in the issue (spaces-in-path execution, argument-injection bypass, shell-payload bypass, missing-executable/nonzero-exit handling, Linux+Windows runs).

    No merged PR implementing this was found; this looks like an open task still awaiting implementation.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions