mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 19:01:34 +00:00
dfb083c9f4
internal/connector/target/ssh/ssh_server_fixture_test.go (~580 LoC,
14 tests) pins realSSHClient.Connect / Execute / WriteFile /
StatFile / Close end-to-end via an embedded golang.org/x/crypto/ssh
ServerConn + pkg/sftp.NewServer, bound to net.Listen('tcp',
'127.0.0.1:0'). Same hand-rolled in-process protocol-server pattern
as the M.Email SMTP fixture.
Coverage delta (per-function):
Connect 0.0% -> ~95% (ed25519 host key + password/key auth +
handshake + sftp open)
Execute 25.0% -> ~95% (success path + exit-code-1 + not-conn)
WriteFile 15.4% -> ~95% (round-trip + chmod + not-conn)
StatFile 33.3% -> ~95% (size assertion + not-conn + not-exist)
Close 42.9% -> ~95% (idempotent + never-connected)
Package overall: 71.6% -> 90.2% (+18.6pp; +5.2 above 85% gate).
Test infrastructure
- fakeSSHServer (~150 LoC): net.Listen + ed25519 host key +
PasswordCallback + PublicKeyCallback. Optional toggles for
rejectAuth / dropOnHandshake / failExec / failSFTP failure
modes.
- encodePEMBlock + base64Encode helpers (~50 LoC) for OpenSSH
private-key serialization. Avoids encoding/pem dep churn in
test header.
- t.Cleanup wires server shutdown + WaitGroup-drain of in-flight
connection handlers (no goroutine leaks).
Test groups
- Connect: password success / wrong-password / auth-rejected-all /
handshake-dropped / TCP-refused / key-auth success
- Execute: success / not-connected / exit-code-1
- WriteFile + StatFile: round-trip with size + chmod 0640
verification / not-connected / not-exist
- Close: idempotent / never-connected
Verification
- go test -short -count=1 ./internal/connector/target/ssh/...: PASS
- 20ms wall time
- go vet clean
Audit deliverables
- findings.yaml H-002 status partial_closed -> closed
(will update in extension-progress.md sweep)
- extension-progress.md: M.SSH-extended marked DONE
Closes: H-002 (SSH Connect / Execute / WriteFile branches)
Bundle: M.SSH-extended (Coverage Audit Extension)