Add unit test for VerifyMac#912
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds coverage for the MAC verification failure path by injecting a packet with a deliberately corrupted MAC and asserting DoReceive() fails with WS_FATAL_ERROR and ssh->error == WS_VERIFY_MAC_E. To make DoReceive() callable from tests without exposing internal static helpers, it introduces a test-only wrapper function guarded by WOLFSSH_TEST_INTERNAL.
Changes:
- Add
wolfSSH_TestDoReceive()(guarded byWOLFSSH_TEST_INTERNAL) as a test-only entrypoint toDoReceive(). - Add a unit test that builds a minimal SSH packet, computes its MAC, flips a MAC byte, and validates the expected failure.
- Update the unit test build to compile/link against the
libwolfssh_test.laconvenience library with-DWOLFSSH_TEST_INTERNAL.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
wolfssh/internal.h |
Declares the new test-only wolfSSH_TestDoReceive() API under WOLFSSH_TEST_INTERNAL. |
src/internal.c |
Implements wolfSSH_TestDoReceive() as a thin wrapper around DoReceive(). |
tests/unit.c |
Adds the corrupted-MAC unit test and wires it into the unit test runner. |
tests/include.am |
Builds unit tests with WOLFSSH_TEST_INTERNAL and links them against src/libwolfssh_test.la. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@yosuke-wolfssl please resolve merge conflicts. Thanks! |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a unit test that validates MAC verification failures in DoReceive() by injecting a packet with a corrupted MAC, enabled only under WOLFSSH_TEST_INTERNAL.
Changes:
- Expose a test-only wrapper
wolfSSH_TestDoReceive()for calling internalDoReceive(). - Add a unit test that crafts packets for multiple HMAC algorithms, corrupts the MAC, and asserts
WS_FATAL_ERROR+WS_VERIFY_MAC_E. - Adjust the unit-test build to compile with internal-test APIs and link against a test library.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| wolfssh/internal.h | Declares test-only wolfSSH_TestDoReceive() under WOLFSSH_TEST_INTERNAL. |
| src/internal.c | Implements the wolfSSH_TestDoReceive() wrapper around DoReceive(). |
| tests/unit.c | Adds DoReceive MAC-failure unit test and required includes. |
| tests/include.am | Builds unit tests with WOLFSSH_TEST_INTERNAL and links against libwolfssh_test.la. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR adds a unit test that verifies corrupted packet MACs are detected during receive processing, without exposing VerifyMac() (static) in the public API. It does so by adding a test-only exported wrapper for DoReceive() and updating the unit test build to link against the test-only library variant.
Changes:
- Add
wolfSSH_TestDoReceive()underWOLFSSH_TEST_INTERNALto callDoReceive()from tests. - Add a new unit test that builds a minimal packet, computes a correct HMAC, flips a MAC byte, and asserts
DoReceivefails withWS_VERIFY_MAC_E. - Update the unit test build to compile with
-DWOLFSSH_TEST_INTERNALand link againstsrc/libwolfssh_test.la.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
wolfssh/internal.h |
Declares the new test-only wolfSSH_TestDoReceive() hook under WOLFSSH_TEST_INTERNAL. |
src/internal.c |
Implements wolfSSH_TestDoReceive() as a thin wrapper around DoReceive() for test builds. |
tests/unit.c |
Adds test_DoReceive_VerifyMacFailure() covering MAC verification failures across enabled HMAC algorithms. |
tests/include.am |
Switches unit.test to use -DWOLFSSH_TEST_INTERNAL and link against src/libwolfssh_test.la. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR adds the unit test that injects a packet with a corrupted MAC (e.g., flip one byte in the MAC region of a captured packet buffer) and verify that DoReceive returns WS_FATAL_ERROR with ssh->error == WS_VERIFY_MAC_E.
We can't call VerifyMac() directly because it's static function in src/internal.c.
That's why I introduced wolfSSH_TestDoReceive() under the WOLFSSH_TEST_INTERNAL guard so that this would be compiled for tests only.