Commit 14655b1
committed
ttrpc: Add extension framework unit tests and integration tests
The extension framework introduces 10 injection points for wire-format
transforms across the client-server lifecycle. Without dedicated tests,
regressions in transform ordering (e.g., double-transform on the
streaming_client=false path) or missing injection points would silently
produce incorrect payload bytes.
Add comprehensive test coverage for all 10 injection points:
Unit tests (src/extension.rs, 20 tests):
- PayloadTransform::transform_inbound / transform_outbound with XOR-0xA5A5
- transform_inbound_msg / transform_outbound_msg on GenMessage
- AcceptHook::on_accept with mock TCP socket
- ConnectHook::on_connect with mock TCP connection
- ConnectionContext helpers (transform_*_msg delegation)
- File descriptor passthrough via ConnectionContext
- Asymmetric transform (distinct inbound/outbound keys)
- Empty payload edge case
Integration tests (tests/hook_integration_unix.rs, 19 tests):
- Symmetric client/server hooks with data and transform
- XOR transform on the wire (end-to-end encryption)
- Streaming with XOR transform (chunked encrypt/decrypt)
- streaming_client=false path (server creates faked DATA)
- streaming_server=false path (rejects DATA, unary only)
- Multiple concurrent streams on one connection
- Multiple concurrent connections with transform
- Unary request timeout
- Server-initiated stream close
- Server shutdown during active stream
- Connect hook called and receives valid raw fd
- Connect hook rejection fails connection
- Accept hook called on connection
- Accept hook rejects connection
- Connection data propagated to handler
- No-hook plaintext passthrough (baseline)
Also adds a unit test in src/asynchronous/client.rs verifying that
Client::with_hook fails when the Socket has no raw fd, preventing a
silent downgrade to an untransformed connection.
Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>1 parent 1638836 commit 14655b1
3 files changed
Lines changed: 1301 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
107 | | - | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
376 | 375 | | |
377 | 376 | | |
378 | 377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 65 | | |
71 | 66 | | |
72 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
| |||
0 commit comments