Skip to content

Add unit tests for wolfSSHD_AuthReducePermissionsUser#994

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5578
Open

Add unit tests for wolfSSHD_AuthReducePermissionsUser#994
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5578

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

This PR adds unit tests for wolfSSHD_AuthReducePermissionsUser so that this can prevent any mutations against user privilege drop calls on that.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Jun 1, 2026
Copilot AI review requested due to automatic review settings June 1, 2026 05:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds unit tests around wolfSSHD_AuthReducePermissionsUser() to prevent regressions/mutations in the privilege-drop flow by validating the expected setregid()/setreuid() call behavior (success path and failure paths). To enable deterministic testing, the PR introduces unit-test-only indirection via function pointers so tests can stub the underlying syscalls.

Changes:

  • Added unit tests for wolfSSHD_AuthReducePermissionsUser() covering success, GID failure, and UID failure paths (non-Windows only).
  • Added unit-test-only callback hooks (wsshd_setregid_cb, wsshd_setreuid_cb) and used them inside wolfSSHD_AuthReducePermissionsUser() when WOLFSSHD_UNIT_TEST is enabled.
  • Exposed the callback hooks via auth.h for the test binary to install/restore stubs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.

File Description
apps/wolfsshd/test/test_configuration.c Adds POSIX-only unit tests that stub privilege-drop syscalls and assert expected call behavior.
apps/wolfsshd/auth.h Exposes unit-test-only extern hooks for syscall indirection used by the new tests.
apps/wolfsshd/auth.c Adds unit-test-only syscall indirection and switches wolfSSHD_AuthReducePermissionsUser() to use it under test builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/wolfsshd/auth.c Outdated
Comment thread apps/wolfsshd/auth.h
Comment thread apps/wolfsshd/test/test_configuration.c Outdated
Comment thread apps/wolfsshd/test/test_configuration.c Outdated
Comment thread apps/wolfsshd/auth.c Outdated
Comment thread apps/wolfsshd/test/test_configuration.c Outdated
Comment thread apps/wolfsshd/auth.c Outdated
Comment thread apps/wolfsshd/auth.h
Comment thread apps/wolfsshd/test/test_configuration.c Outdated
Comment thread apps/wolfsshd/test/test_configuration.c Outdated
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #994

Scan targets checked: wolfssh-bugs, wolfssh-src

No new issues found in the changed files. ✅

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.

4 participants