itest: add test for multiple read-only rpc mw
What changed, and why it matters
This commit only adds a new integration test that checks whether two read-only RPC middlewares can be registered at the same time and both receive copies of the same RPC traffic. It does not change any production code, so it cannot introduce or fix a security vulnerability on its own.
No security action needed. Treat as a normal test-coverage change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is limited to itest/lnd_rpc_middleware_interceptor_test.go. It adds a sub-test named ‘multiple read-only middlewares’ plus a helper function multipleReadOnlyMiddlewareTest that registers two read-only middlewares, issues a ListChannels call, and asserts both interceptors receive the same response. No implementation logic in lnd is modified.
Changed components
itest/lnd_rpc_middleware_interceptor_test.goInspect captured patch +69 / −0
diff --git a/itest/lnd_rpc_middleware_interceptor_test.go b/itest/lnd_rpc_middleware_interceptor_test.go
index 5b16da0..e0409af 100644
--- a/itest/lnd_rpc_middleware_interceptor_test.go
+++ b/itest/lnd_rpc_middleware_interceptor_test.go
@@ -78,6 +78,19 @@ func testRPCMiddlewareInterceptor(ht *lntest.HarnessTest) {
)
})
+ // Test that multiple read-only middlewares can be registered at the
+ // same time and that both receive intercept messages.
+ //
+ // NOTE: we restart the node here to make sure the old interceptor is
+ // removed from registration.
+ ht.RestartNode(alice)
+ ht.EnsureConnected(alice, bob)
+ ht.Run("multiple read-only middlewares", func(tt *testing.T) {
+ multipleReadOnlyMiddlewareTest(
+ tt, alice, readonlyMac,
+ )
+ })
+
// We've manually disconnected Bob from Alice in the previous test, make
// sure they're connected again.
//
@@ -207,6 +220,62 @@ func middlewareRegistrationRestrictionTests(t *testing.T,
}
}
+// multipleReadOnlyMiddlewareTest verifies that multiple read-only middlewares
+// can be registered simultaneously and that both receive intercept messages for
+// the same RPC call.
+func multipleReadOnlyMiddlewareTest(t *testing.T,
+ node *node.HarnessNode, userMac *macaroon.Macaroon) {
+
+ t.Helper()
+
+ ctxb := t.Context()
+ ctxc, cancel := context.WithTimeout(ctxb, defaultTimeout)
+ defer cancel()
+
+ // Register two read-only middlewares with different names.
+ reg1 := registerMiddleware(
+ t, node, &lnrpc.MiddlewareRegistration{
+ MiddlewareName: "itest-readonly-one",
+ ReadOnlyMode: true,
+ }, true,
+ )
+ defer reg1.cancel()
+
+ reg2 := registerMiddleware(
+ t, node, &lnrpc.MiddlewareRegistration{
+ MiddlewareName: "itest-readonly-two",
+ ReadOnlyMode: true,
+ }, true,
+ )
+ defer reg2.cancel()
+
+ // Create a client connection to simulate a user request.
+ cleanup, client := macaroonClient(t, node, userMac)
+ defer cleanup()
+
+ // Send a simple RPC request listing all channels to trigger the rpc
+ // interceptors. We need to invoke the intercept logic in a goroutine
+ // because we'd block the execution of the main task otherwise.
+ req := &lnrpc.ListChannelsRequest{ActiveOnly: true}
+ go reg1.interceptUnary(
+ "/lnrpc.Lightning/ListChannels", req, nil, true, false,
+ nil,
+ )
+ go reg2.interceptUnary(
+ "/lnrpc.Lightning/ListChannels", req, nil, true, false,
+ nil,
+ )
+
+ // Do the actual call now and wait for both interceptors to process.
+ resp, err := client.ListChannels(ctxc, req)
+ require.NoError(t, err)
+
+ // Since both middlewares are read-only, they cannot replace the
+ // response. Verify that both received the same response as the client.
+ assertInterceptedType(t, resp, <-reg1.responsesChan)
+ assertInterceptedType(t, resp, <-reg2.responsesChan)
+}
+
// middlewareInterceptionTest tests that unary and streaming requests can be
// intercepted. It also makes sure that depending on the mode (read-only or
// custom macaroon caveat) a middleware only gets access to the requests it
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.