@@ -26,6 +26,8 @@ import (
26
26
"github.com/lightninglabs/pool/poolrpc"
27
27
"github.com/lightningnetwork/lnd/keychain"
28
28
"github.com/lightningnetwork/lnd/lnrpc"
29
+ "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
30
+ "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
29
31
"github.com/stretchr/testify/require"
30
32
"golang.org/x/net/http2"
31
33
"google.golang.org/grpc"
@@ -81,17 +83,33 @@ var (
81
83
// gRPC request. One byte version and then 4 bytes content length.
82
84
emptyGrpcWebRequest = []byte {0 , 0 , 0 , 0 , 0 }
83
85
84
- lndRequestFn = func (ctx context.Context ,
86
+ lnrpcRequestFn = func (ctx context.Context ,
85
87
c grpc.ClientConnInterface ) (proto.Message , error ) {
86
88
87
- lndConn := lnrpc .NewLightningClient (c )
88
- return lndConn .GetInfo (
89
+ lnrpcConn := lnrpc .NewLightningClient (c )
90
+ return lnrpcConn .GetInfo (
89
91
ctx , & lnrpc.GetInfoRequest {},
90
92
)
91
93
}
92
94
lndMacaroonFn = func (cfg * LitNodeConfig ) string {
93
95
return cfg .AdminMacPath
94
96
}
97
+ routerrpcRequestFn = func (ctx context.Context ,
98
+ c grpc.ClientConnInterface ) (proto.Message , error ) {
99
+
100
+ routerrpcConn := routerrpc .NewRouterClient (c )
101
+ return routerrpcConn .GetMissionControlConfig (
102
+ ctx , & routerrpc.GetMissionControlConfigRequest {},
103
+ )
104
+ }
105
+ walletrpcRequestFn = func (ctx context.Context ,
106
+ c grpc.ClientConnInterface ) (proto.Message , error ) {
107
+
108
+ walletrpcConn := walletrpc .NewWalletKitClient (c )
109
+ return walletrpcConn .ListUnspent (
110
+ ctx , & walletrpc.ListUnspentRequest {},
111
+ )
112
+ }
95
113
faradayRequestFn = func (ctx context.Context ,
96
114
c grpc.ClientConnInterface ) (proto.Message , error ) {
97
115
@@ -145,14 +163,32 @@ var (
145
163
allowedThroughLNC bool
146
164
grpcWebURI string
147
165
restWebURI string
166
+ restPOST bool
148
167
}{{
149
168
name : "lnrpc" ,
150
169
macaroonFn : lndMacaroonFn ,
151
- requestFn : lndRequestFn ,
170
+ requestFn : lnrpcRequestFn ,
152
171
successPattern : "\" identity_pubkey\" :\" 0" ,
153
172
allowedThroughLNC : true ,
154
173
grpcWebURI : "/lnrpc.Lightning/GetInfo" ,
155
174
restWebURI : "/v1/getinfo" ,
175
+ }, {
176
+ name : "routerrpc" ,
177
+ macaroonFn : lndMacaroonFn ,
178
+ requestFn : routerrpcRequestFn ,
179
+ successPattern : "\" config\" :{" ,
180
+ allowedThroughLNC : true ,
181
+ grpcWebURI : "/routerrpc.Router/GetMissionControlConfig" ,
182
+ restWebURI : "/v2/router/mccfg" ,
183
+ }, {
184
+ name : "walletrpc" ,
185
+ macaroonFn : lndMacaroonFn ,
186
+ requestFn : walletrpcRequestFn ,
187
+ successPattern : "\" utxos\" :[" ,
188
+ allowedThroughLNC : true ,
189
+ grpcWebURI : "/walletrpc.WalletKit/ListUnspent" ,
190
+ restWebURI : "/v2/wallet/utxos" ,
191
+ restPOST : true ,
156
192
}, {
157
193
name : "frdrpc" ,
158
194
macaroonFn : faradayMacaroonFn ,
@@ -322,6 +358,7 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
322
358
endpoint .macaroonFn (cfg ),
323
359
endpoint .restWebURI ,
324
360
endpoint .successPattern ,
361
+ endpoint .restPOST ,
325
362
)
326
363
})
327
364
}
@@ -529,7 +566,7 @@ func runGRPCWebAuthTest(t *testing.T, hostPort, uiPassword, grpcWebURI string) {
529
566
530
567
// runRESTAuthTest tests authentication of the given REST interface.
531
568
func runRESTAuthTest (t * testing.T , hostPort , uiPassword , macaroonPath , restURI ,
532
- successPattern string ) {
569
+ successPattern string , usePOST bool ) {
533
570
534
571
basicAuth := base64 .StdEncoding .EncodeToString (
535
572
[]byte (fmt .Sprintf ("%s:%s" , uiPassword , uiPassword )),
@@ -539,13 +576,19 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
539
576
}
540
577
url := fmt .Sprintf ("https://%s%s" , hostPort , restURI )
541
578
579
+ method := "GET"
580
+ if usePOST {
581
+ method = "POST"
582
+ }
583
+
542
584
// First test a REST call without authorization, which should fail.
543
- body , responseHeader , err := callURL (url , "GET" , nil , nil , false )
585
+ body , responseHeader , err := callURL (url , method , nil , nil , false )
544
586
require .NoError (t , err )
545
587
546
- require .Equal (
588
+ require .Equalf (
547
589
t , "application/grpc" ,
548
590
responseHeader .Get ("grpc-metadata-content-type" ),
591
+ "response headers: %v, body: %v" , responseHeader , body ,
549
592
)
550
593
require .Equal (
551
594
t , "application/json" ,
@@ -558,7 +601,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
558
601
559
602
// Now add the UI password which should make the request succeed.
560
603
body , responseHeader , err = callURL (
561
- url , "GET" , nil , basicAuthHeader , false ,
604
+ url , method , nil , basicAuthHeader , false ,
562
605
)
563
606
require .NoError (t , err )
564
607
require .Contains (t , body , successPattern )
@@ -573,7 +616,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
573
616
},
574
617
}
575
618
body , responseHeader , err = callURL (
576
- url , "GET" , nil , macaroonHeader , false ,
619
+ url , method , nil , macaroonHeader , false ,
577
620
)
578
621
require .NoError (t , err )
579
622
require .Contains (t , body , successPattern )
0 commit comments