Add MP_LIBSSH-based PlainSSHSession and related tests - #5105
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends Multipass’ SSH unit test coverage by consolidating libssh-mocked PlainSSHSession tests into the main suite and adding a new unit test suite for PlainSSHProcess, with corresponding test target updates.
Changes:
- Migrate/merge libssh-mocked
PlainSSHSessiontests intotest_plain_ssh_session.cppand remove the separate mocked-libssh test file. - Add a new
PlainSSHProcessunit test suite using the libssh wrapper mock. - Update the unit test CMake target sources accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/unit/test_plain_ssh_session.cpp | Merges mocked-libssh coverage into the main PlainSSHSession unit tests and expands move/exec/error-path assertions. |
| tests/unit/test_plain_ssh_session_mocked_libssh.cpp | Removes the now-redundant standalone mocked-libssh test suite. |
| tests/unit/test_plain_ssh_process.cpp | Adds new unit tests for PlainSSHProcess error paths using mocked libssh wrapper calls. |
| tests/unit/CMakeLists.txt | Registers the new process test and drops the removed mocked-libssh session test file. |
Comments suppressed due to low confidence (1)
tests/unit/test_plain_ssh_session.cpp:156
other_sessionis also initialized from a fabricated address and later becomes the underlying session forexec_plain(), which bindsssh_session_struct&via dereference. Use a realssh_session(e.g. from::ssh_new()) to avoid undefined behavior.
auto other_session = reinterpret_cast<ssh_session>(bad_addr_too);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## sftp-session-api #5105 +/- ##
====================================================
+ Coverage 73.04% 73.04% +0.01%
====================================================
Files 336 336
Lines 18092 18093 +1
====================================================
+ Hits 13213 13214 +1
Misses 4879 4879 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Marking this ready for review, but we should probably hold merging until the base branches are merged. |
Test the successful SFTP session path, which covers channel and session borrowing.
Verify that the PlainSSHProcess throws at construction if the session is not connected. Replaces coverage of the old, premock-based TestPlainSSHSession.execThrowsIfSshIsDead, which was mistakenly scoped to the session.
Replaces coverage of the old, premock-based test.
In preparation for removal.
Switch from reference to pointer param for the opaque libssh session handle, to avoid requiring a callers to dereference it. This helps tests avoid undefined behavior. Document and assert the non-null precondition instead.
Description
Related Issue(s)
MULTI-2747
Checklist