Skip to content

Commit ee35686

Browse files
committed
fixup! multi: validate macaroons for lit calls
1 parent 9093a3f commit ee35686

File tree

2 files changed

+41
-111
lines changed

2 files changed

+41
-111
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 41 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -139,79 +139,55 @@ var (
139139
}
140140

141141
endpoints = []struct {
142-
name string
143-
macaroonFn macaroonFn
144-
requestFn requestFn
145-
successPattern string
146-
supportsMacAuthOnLndPort bool
147-
supportsMacAuthOnLitPort bool
148-
supportsUIPasswordOnLndPort bool
149-
supportsUIPasswordOnLitPort bool
150-
allowedThroughLNC bool
151-
grpcWebURI string
152-
restWebURI string
142+
name string
143+
macaroonFn macaroonFn
144+
requestFn requestFn
145+
successPattern string
146+
allowedThroughLNC bool
147+
grpcWebURI string
148+
restWebURI string
153149
}{{
154-
name: "lnrpc",
155-
macaroonFn: lndMacaroonFn,
156-
requestFn: lndRequestFn,
157-
successPattern: "\"identity_pubkey\":\"0",
158-
supportsMacAuthOnLndPort: true,
159-
supportsMacAuthOnLitPort: true,
160-
supportsUIPasswordOnLndPort: false,
161-
supportsUIPasswordOnLitPort: true,
162-
allowedThroughLNC: true,
163-
grpcWebURI: "/lnrpc.Lightning/GetInfo",
164-
restWebURI: "/v1/getinfo",
150+
name: "lnrpc",
151+
macaroonFn: lndMacaroonFn,
152+
requestFn: lndRequestFn,
153+
successPattern: "\"identity_pubkey\":\"0",
154+
allowedThroughLNC: true,
155+
grpcWebURI: "/lnrpc.Lightning/GetInfo",
156+
restWebURI: "/v1/getinfo",
165157
}, {
166-
name: "frdrpc",
167-
macaroonFn: faradayMacaroonFn,
168-
requestFn: faradayRequestFn,
169-
successPattern: "\"reports\":[]",
170-
supportsMacAuthOnLndPort: true,
171-
supportsMacAuthOnLitPort: true,
172-
supportsUIPasswordOnLndPort: false,
173-
supportsUIPasswordOnLitPort: true,
174-
allowedThroughLNC: true,
175-
grpcWebURI: "/frdrpc.FaradayServer/RevenueReport",
176-
restWebURI: "/v1/faraday/revenue",
158+
name: "frdrpc",
159+
macaroonFn: faradayMacaroonFn,
160+
requestFn: faradayRequestFn,
161+
successPattern: "\"reports\":[]",
162+
allowedThroughLNC: true,
163+
grpcWebURI: "/frdrpc.FaradayServer/RevenueReport",
164+
restWebURI: "/v1/faraday/revenue",
177165
}, {
178-
name: "looprpc",
179-
macaroonFn: loopMacaroonFn,
180-
requestFn: loopRequestFn,
181-
successPattern: "\"swaps\":[]",
182-
supportsMacAuthOnLndPort: true,
183-
supportsMacAuthOnLitPort: true,
184-
supportsUIPasswordOnLndPort: false,
185-
supportsUIPasswordOnLitPort: true,
186-
allowedThroughLNC: true,
187-
grpcWebURI: "/looprpc.SwapClient/ListSwaps",
188-
restWebURI: "/v1/loop/swaps",
166+
name: "looprpc",
167+
macaroonFn: loopMacaroonFn,
168+
requestFn: loopRequestFn,
169+
successPattern: "\"swaps\":[]",
170+
allowedThroughLNC: true,
171+
grpcWebURI: "/looprpc.SwapClient/ListSwaps",
172+
restWebURI: "/v1/loop/swaps",
189173
}, {
190-
name: "poolrpc",
191-
macaroonFn: poolMacaroonFn,
192-
requestFn: poolRequestFn,
193-
successPattern: "\"accounts_active\":0",
194-
supportsMacAuthOnLndPort: true,
195-
supportsMacAuthOnLitPort: true,
196-
supportsUIPasswordOnLndPort: false,
197-
supportsUIPasswordOnLitPort: true,
198-
allowedThroughLNC: true,
199-
grpcWebURI: "/poolrpc.Trader/GetInfo",
200-
restWebURI: "/v1/pool/info",
174+
name: "poolrpc",
175+
macaroonFn: poolMacaroonFn,
176+
requestFn: poolRequestFn,
177+
successPattern: "\"accounts_active\":0",
178+
allowedThroughLNC: true,
179+
grpcWebURI: "/poolrpc.Trader/GetInfo",
180+
restWebURI: "/v1/pool/info",
201181
}, {
202182
name: "litrpc",
203183
macaroonFn: litMacaroonFn,
204184
requestFn: litRequestFn,
205185
// In some test cases we actually expect some sessions, so we
206186
// don't explicitly check for an empty array but just the
207187
// existence of the array in the response.
208-
successPattern: "\"sessions\":[",
209-
supportsMacAuthOnLndPort: true,
210-
supportsMacAuthOnLitPort: true,
211-
supportsUIPasswordOnLndPort: false,
212-
supportsUIPasswordOnLitPort: false,
213-
allowedThroughLNC: false,
214-
grpcWebURI: "/litrpc.Sessions/ListSessions",
188+
successPattern: "\"sessions\":[",
189+
allowedThroughLNC: false,
190+
grpcWebURI: "/litrpc.Sessions/ListSessions",
215191
}}
216192
)
217193

@@ -239,10 +215,6 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
239215
for _, endpoint := range endpoints {
240216
endpoint := endpoint
241217
tt.Run(endpoint.name+" lnd port", func(ttt *testing.T) {
242-
if !endpoint.supportsMacAuthOnLndPort {
243-
return
244-
}
245-
246218
runGRPCAuthTest(
247219
ttt, cfg.RPCAddr(), cfg.TLSCertPath,
248220
endpoint.macaroonFn(cfg),
@@ -252,10 +224,6 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
252224
})
253225

254226
tt.Run(endpoint.name+" lit port", func(ttt *testing.T) {
255-
if !endpoint.supportsMacAuthOnLitPort {
256-
return
257-
}
258-
259227
runGRPCAuthTest(
260228
ttt, cfg.LitAddr(), cfg.TLSCertPath,
261229
endpoint.macaroonFn(cfg),
@@ -275,8 +243,7 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
275243
runUIPasswordCheck(
276244
ttt, cfg.RPCAddr(), cfg.TLSCertPath,
277245
cfg.UIPassword,
278-
endpoint.requestFn, true,
279-
!endpoint.supportsUIPasswordOnLndPort,
246+
endpoint.requestFn,
280247
endpoint.successPattern,
281248
)
282249
})
@@ -285,8 +252,7 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
285252
runUIPasswordCheck(
286253
ttt, cfg.LitAddr(), cfg.TLSCertPath,
287254
cfg.UIPassword,
288-
endpoint.requestFn, false,
289-
!endpoint.supportsUIPasswordOnLitPort,
255+
endpoint.requestFn,
290256
endpoint.successPattern,
291257
)
292258
})
@@ -324,10 +290,6 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
324290
for _, endpoint := range endpoints {
325291
endpoint := endpoint
326292
tt.Run(endpoint.name+" lnd port", func(ttt *testing.T) {
327-
if !endpoint.supportsMacAuthOnLndPort {
328-
return
329-
}
330-
331293
runGRPCAuthTest(
332294
ttt, cfg.RPCAddr(), cfg.TLSCertPath,
333295
superMacFile,
@@ -337,10 +299,6 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
337299
})
338300

339301
tt.Run(endpoint.name+" lit port", func(ttt *testing.T) {
340-
if !endpoint.supportsMacAuthOnLitPort {
341-
return
342-
}
343-
344302
runGRPCAuthTest(
345303
ttt, cfg.LitAddr(), cfg.TLSCertPath,
346304
superMacFile,
@@ -457,8 +415,7 @@ func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
457415

458416
// runUIPasswordCheck tests UI password authentication.
459417
func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
460-
makeRequest requestFn, shouldFailWithoutMacaroon,
461-
shouldFailWithDummyMacaroon bool, successContent string) {
418+
makeRequest requestFn, successContent string) {
462419

463420
ctxb := context.Background()
464421
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -493,28 +450,6 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
493450
ctxm = uiPasswordContext(ctxt, uiPassword, false)
494451
resp, err := makeRequest(ctxm, rawConn)
495452

496-
// On lnd's gRPC interface we don't support using the UI password.
497-
if shouldFailWithoutMacaroon {
498-
require.Error(t, err)
499-
require.Contains(t, err.Error(), "expected 1 macaroon, got 0")
500-
501-
// Sending a dummy macaroon will allow us to not get an error in
502-
// case of the litrpc calls, where we don't support macaroons
503-
// but have the extraction call in the validator anyway. So we
504-
// provide a dummy macaroon but still the UI password must be
505-
// correct to pass.
506-
ctxm = uiPasswordContext(ctxt, uiPassword, true)
507-
resp, err = makeRequest(ctxm, rawConn)
508-
509-
if shouldFailWithDummyMacaroon {
510-
require.Error(t, err)
511-
require.Contains(
512-
t, err.Error(), "cannot get macaroon: root",
513-
)
514-
return
515-
}
516-
}
517-
518453
// We expect the call to succeed.
519454
require.NoError(t, err)
520455

itest/litd_mode_remote_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ func testModeRemote(net *NetworkHarness, t *harnessTest) {
4343
for _, endpoint := range endpoints {
4444
endpoint := endpoint
4545
tt.Run(endpoint.name+" lit port", func(ttt *testing.T) {
46-
if !endpoint.supportsMacAuthOnLitPort {
47-
return
48-
}
49-
5046
runGRPCAuthTest(
5147
ttt, cfg.LitAddr(), cfg.LitTLSCertPath,
5248
endpoint.macaroonFn(cfg),
@@ -67,7 +63,6 @@ func testModeRemote(net *NetworkHarness, t *harnessTest) {
6763
ttt, cfg.LitAddr(), cfg.LitTLSCertPath,
6864
cfg.UIPassword,
6965
endpoint.requestFn, false,
70-
!endpoint.supportsUIPasswordOnLitPort,
7166
endpoint.successPattern,
7267
)
7368
})

0 commit comments

Comments
 (0)