@@ -26,6 +26,8 @@ import (
2626 "github.com/lightninglabs/pool/poolrpc"
2727 "github.com/lightningnetwork/lnd/keychain"
2828 "github.com/lightningnetwork/lnd/lnrpc"
29+ "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
30+ "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2931 "github.com/stretchr/testify/require"
3032 "golang.org/x/net/http2"
3133 "google.golang.org/grpc"
@@ -81,17 +83,33 @@ var (
8183 // gRPC request. One byte version and then 4 bytes content length.
8284 emptyGrpcWebRequest = []byte {0 , 0 , 0 , 0 , 0 }
8385
84- lndRequestFn = func (ctx context.Context ,
86+ lnrpcRequestFn = func (ctx context.Context ,
8587 c grpc.ClientConnInterface ) (proto.Message , error ) {
8688
87- lndConn := lnrpc .NewLightningClient (c )
88- return lndConn .GetInfo (
89+ lnrpcConn := lnrpc .NewLightningClient (c )
90+ return lnrpcConn .GetInfo (
8991 ctx , & lnrpc.GetInfoRequest {},
9092 )
9193 }
9294 lndMacaroonFn = func (cfg * LitNodeConfig ) string {
9395 return cfg .AdminMacPath
9496 }
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+ }
95113 faradayRequestFn = func (ctx context.Context ,
96114 c grpc.ClientConnInterface ) (proto.Message , error ) {
97115
@@ -145,14 +163,32 @@ var (
145163 allowedThroughLNC bool
146164 grpcWebURI string
147165 restWebURI string
166+ restPOST bool
148167 }{{
149168 name : "lnrpc" ,
150169 macaroonFn : lndMacaroonFn ,
151- requestFn : lndRequestFn ,
170+ requestFn : lnrpcRequestFn ,
152171 successPattern : "\" identity_pubkey\" :\" 0" ,
153172 allowedThroughLNC : true ,
154173 grpcWebURI : "/lnrpc.Lightning/GetInfo" ,
155174 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 ,
156192 }, {
157193 name : "frdrpc" ,
158194 macaroonFn : faradayMacaroonFn ,
@@ -322,6 +358,7 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
322358 endpoint .macaroonFn (cfg ),
323359 endpoint .restWebURI ,
324360 endpoint .successPattern ,
361+ endpoint .restPOST ,
325362 )
326363 })
327364 }
@@ -529,7 +566,7 @@ func runGRPCWebAuthTest(t *testing.T, hostPort, uiPassword, grpcWebURI string) {
529566
530567// runRESTAuthTest tests authentication of the given REST interface.
531568func runRESTAuthTest (t * testing.T , hostPort , uiPassword , macaroonPath , restURI ,
532- successPattern string ) {
569+ successPattern string , usePOST bool ) {
533570
534571 basicAuth := base64 .StdEncoding .EncodeToString (
535572 []byte (fmt .Sprintf ("%s:%s" , uiPassword , uiPassword )),
@@ -539,13 +576,19 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
539576 }
540577 url := fmt .Sprintf ("https://%s%s" , hostPort , restURI )
541578
579+ method := "GET"
580+ if usePOST {
581+ method = "POST"
582+ }
583+
542584 // 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 )
544586 require .NoError (t , err )
545587
546- require .Equal (
588+ require .Equalf (
547589 t , "application/grpc" ,
548590 responseHeader .Get ("grpc-metadata-content-type" ),
591+ "response headers: %v, body: %v" , responseHeader , body ,
549592 )
550593 require .Equal (
551594 t , "application/json" ,
@@ -558,7 +601,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
558601
559602 // Now add the UI password which should make the request succeed.
560603 body , responseHeader , err = callURL (
561- url , "GET" , nil , basicAuthHeader , false ,
604+ url , method , nil , basicAuthHeader , false ,
562605 )
563606 require .NoError (t , err )
564607 require .Contains (t , body , successPattern )
@@ -573,7 +616,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
573616 },
574617 }
575618 body , responseHeader , err = callURL (
576- url , "GET" , nil , macaroonHeader , false ,
619+ url , method , nil , macaroonHeader , false ,
577620 )
578621 require .NoError (t , err )
579622 require .Contains (t , body , successPattern )
@@ -834,7 +877,12 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
834877 lndAdminCtx := macaroonContext (ctxt , lndAdminMacBytes )
835878 lndConn := lnrpc .NewLightningClient (rawConn )
836879
837- superMacPermissions := terminal .GetAllPermissions (readOnly )
880+ permsMgr , err := terminal .NewPermissionsManager ()
881+ if err != nil {
882+ return "" , err
883+ }
884+
885+ superMacPermissions := permsMgr .ActivePermissions (readOnly )
838886 nullID := [4 ]byte {}
839887 superMacHex , err := terminal .BakeSuperMacaroon (
840888 lndAdminCtx , lndConn , session .NewSuperMacaroonRootKeyID (nullID ),
0 commit comments