@@ -225,6 +225,7 @@ var (
225
225
restWebURI string
226
226
restPOST bool
227
227
canDisable bool
228
+ isSubServer bool
228
229
229
230
// noAuth is true if the call does not require a macaroon.
230
231
noAuth bool
@@ -277,6 +278,7 @@ var (
277
278
grpcWebURI : "/frdrpc.FaradayServer/RevenueReport" ,
278
279
restWebURI : "/v1/faraday/revenue" ,
279
280
canDisable : true ,
281
+ isSubServer : true ,
280
282
}, {
281
283
name : "looprpc" ,
282
284
macaroonFn : loopMacaroonFn ,
@@ -287,6 +289,7 @@ var (
287
289
grpcWebURI : "/looprpc.SwapClient/ListSwaps" ,
288
290
restWebURI : "/v1/loop/swaps" ,
289
291
canDisable : true ,
292
+ isSubServer : true ,
290
293
}, {
291
294
name : "poolrpc" ,
292
295
macaroonFn : poolMacaroonFn ,
@@ -297,6 +300,7 @@ var (
297
300
grpcWebURI : "/poolrpc.Trader/GetInfo" ,
298
301
restWebURI : "/v1/pool/info" ,
299
302
canDisable : true ,
303
+ isSubServer : true ,
300
304
}, {
301
305
name : "taprpc" ,
302
306
macaroonFn : tapMacaroonFn ,
@@ -307,6 +311,7 @@ var (
307
311
grpcWebURI : "/taprpc.TaprootAssets/ListAssets" ,
308
312
restWebURI : "/v1/taproot-assets/assets" ,
309
313
canDisable : true ,
314
+ isSubServer : true ,
310
315
}, {
311
316
name : "taprpc-whitelist" ,
312
317
macaroonFn : emptyMacaroonFn ,
@@ -318,6 +323,7 @@ var (
318
323
restWebURI : "/v1/taproot-assets/universe/info" ,
319
324
canDisable : true ,
320
325
noAuth : true ,
326
+ isSubServer : true ,
321
327
}, {
322
328
name : "litrpc-sessions" ,
323
329
macaroonFn : litMacaroonFn ,
@@ -494,6 +500,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
494
500
endpoint .successPattern ,
495
501
endpointDisabled || endpoint .litOnly ,
496
502
"Unimplemented desc = unknown service" ,
503
+ endpoint .isSubServer , false ,
497
504
)
498
505
})
499
506
@@ -506,47 +513,18 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
506
513
endpoint .successPattern ,
507
514
endpointDisabled ,
508
515
endpoint .disabledPattern ,
516
+ endpoint .isSubServer ,
517
+ false ,
509
518
)
510
519
})
511
520
}
512
521
})
513
522
514
523
t .Run ("UI password auth check" , func (tt * testing.T ) {
515
- cfg := net .Alice .Cfg
516
-
517
- for _ , endpoint := range endpoints {
518
- endpoint := endpoint
519
- endpointDisabled := subServersDisabled &&
520
- endpoint .canDisable
521
-
522
- tt .Run (endpoint .name + " lnd port" , func (ttt * testing.T ) {
523
- runUIPasswordCheck (
524
- ttt , cfg .RPCAddr (), cfg .TLSCertPath ,
525
- cfg .UIPassword , endpoint .requestFn ,
526
- endpoint .noAuth ,
527
- true , endpoint .successPattern ,
528
- endpointDisabled || endpoint .litOnly ,
529
- "Unimplemented desc = unknown service" ,
530
- )
531
- })
532
-
533
- tt .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
534
- shouldFailWithoutMacaroon := false
535
- if withoutUIPassword {
536
- shouldFailWithoutMacaroon = true
537
- }
538
-
539
- runUIPasswordCheck (
540
- ttt , cfg .LitAddr (), cfg .LitTLSCertPath ,
541
- cfg .UIPassword , endpoint .requestFn ,
542
- endpoint .noAuth ,
543
- shouldFailWithoutMacaroon ,
544
- endpoint .successPattern ,
545
- endpointDisabled ,
546
- endpoint .disabledPattern ,
547
- )
548
- })
549
- }
524
+ uiPasswordAuthCheck (
525
+ tt , net .Alice .Cfg , subServersDisabled ,
526
+ withoutUIPassword , false ,
527
+ )
550
528
})
551
529
552
530
t .Run ("UI index page fallback" , func (tt * testing.T ) {
@@ -576,37 +554,10 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
576
554
})
577
555
578
556
t .Run ("gRPC super macaroon auth check" , func (tt * testing.T ) {
579
- cfg := net .Alice .Cfg
580
-
581
- superMacFile := bakeSuperMacaroon (tt , cfg , true )
582
-
583
- for _ , endpoint := range endpoints {
584
- endpoint := endpoint
585
- endpointDisabled := subServersDisabled &&
586
- endpoint .canDisable
587
-
588
- tt .Run (endpoint .name + " lnd port" , func (ttt * testing.T ) {
589
- runGRPCAuthTest (
590
- ttt , cfg .RPCAddr (), cfg .TLSCertPath ,
591
- superMacFile , endpoint .noAuth ,
592
- endpoint .requestFn ,
593
- endpoint .successPattern ,
594
- endpointDisabled || endpoint .litOnly ,
595
- "Unimplemented desc = unknown service" ,
596
- )
597
- })
598
-
599
- tt .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
600
- runGRPCAuthTest (
601
- ttt , cfg .LitAddr (), cfg .LitTLSCertPath ,
602
- superMacFile , endpoint .noAuth ,
603
- endpoint .requestFn ,
604
- endpoint .successPattern ,
605
- endpointDisabled ,
606
- endpoint .disabledPattern ,
607
- )
608
- })
609
- }
557
+ superMacaroonAuth (
558
+ tt , net .Alice .Cfg , subServersDisabled , false ,
559
+ getLiTMacFromFile ,
560
+ )
610
561
})
611
562
612
563
t .Run ("REST auth" , func (tt * testing.T ) {
@@ -673,7 +624,9 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
673
624
return
674
625
}
675
626
676
- superMacFile := bakeSuperMacaroon (tt , cfg , false )
627
+ superMacFile := bakeSuperMacaroon (
628
+ tt , cfg , getLiTMacFromFile , false ,
629
+ )
677
630
678
631
ht := newHarnessTest (tt , net )
679
632
runAccountSystemTest (
@@ -740,6 +693,48 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
740
693
})
741
694
}
742
695
696
+ func uiPasswordAuthCheck (t * testing.T , cfg * LitNodeConfig , subServersDisabled ,
697
+ withoutUIPassword , statelessInit bool ) {
698
+
699
+ for _ , endpoint := range endpoints {
700
+ endpoint := endpoint
701
+ endpointDisabled := subServersDisabled &&
702
+ endpoint .canDisable
703
+
704
+ t .Run (endpoint .name + " lnd port" , func (ttt * testing.T ) {
705
+ runUIPasswordCheck (
706
+ ttt , cfg .RPCAddr (), cfg .TLSCertPath ,
707
+ cfg .UIPassword , endpoint .requestFn ,
708
+ endpoint .noAuth ,
709
+ true ,
710
+ endpoint .successPattern ,
711
+ endpointDisabled || endpoint .litOnly ,
712
+ "Unimplemented desc = unknown service" ,
713
+ endpoint .isSubServer ,
714
+ statelessInit ,
715
+ )
716
+ })
717
+
718
+ t .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
719
+ shouldFailWithoutMacaroon := false
720
+ if withoutUIPassword {
721
+ shouldFailWithoutMacaroon = true
722
+ }
723
+
724
+ runUIPasswordCheck (
725
+ ttt , cfg .LitAddr (), cfg .LitTLSCertPath ,
726
+ cfg .UIPassword , endpoint .requestFn ,
727
+ endpoint .noAuth ,
728
+ shouldFailWithoutMacaroon ,
729
+ endpoint .successPattern ,
730
+ endpointDisabled ,
731
+ endpoint .disabledPattern ,
732
+ endpoint .isSubServer , statelessInit ,
733
+ )
734
+ })
735
+ }
736
+ }
737
+
743
738
// setUpLNCConn creates a new LNC session and then creates a connection to that
744
739
// session via the mailbox that the session was created with.
745
740
func setUpLNCConn (ctx context.Context , t * testing.T , hostPort , tlsCertPath ,
@@ -778,6 +773,43 @@ func setUpLNCConn(ctx context.Context, t *testing.T, hostPort, tlsCertPath,
778
773
return rawLNCConn
779
774
}
780
775
776
+ func superMacaroonAuth (t * testing.T , cfg * LitNodeConfig ,
777
+ subServersDisabled , statelessInit bool ,
778
+ getMac func (* testing.T , * LitNodeConfig ) []byte ) {
779
+
780
+ superMacFile := bakeSuperMacaroon (t , cfg , getMac , true )
781
+
782
+ for _ , endpoint := range endpoints {
783
+ endpoint := endpoint
784
+ endpointDisabled := subServersDisabled &&
785
+ endpoint .canDisable
786
+
787
+ t .Run (endpoint .name + " lnd port" , func (ttt * testing.T ) {
788
+ runGRPCAuthTest (
789
+ ttt , cfg .RPCAddr (), cfg .TLSCertPath ,
790
+ superMacFile , endpoint .noAuth ,
791
+ endpoint .requestFn ,
792
+ endpoint .successPattern ,
793
+ endpointDisabled || endpoint .litOnly ,
794
+ "Unimplemented desc = unknown service" ,
795
+ endpoint .isSubServer , statelessInit ,
796
+ )
797
+ })
798
+
799
+ t .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
800
+ runGRPCAuthTest (
801
+ ttt , cfg .LitAddr (), cfg .LitTLSCertPath ,
802
+ superMacFile , endpoint .noAuth ,
803
+ endpoint .requestFn ,
804
+ endpoint .successPattern ,
805
+ endpointDisabled ,
806
+ endpoint .disabledPattern ,
807
+ endpoint .isSubServer , statelessInit ,
808
+ )
809
+ })
810
+ }
811
+ }
812
+
781
813
// runCertificateCheck checks that the TLS certificates presented to clients are
782
814
// what we expect them to be.
783
815
func runCertificateCheck (t * testing.T , node * HarnessNode ) {
@@ -799,7 +831,7 @@ func runCertificateCheck(t *testing.T, node *HarnessNode) {
799
831
// runGRPCAuthTest tests authentication of the given gRPC interface.
800
832
func runGRPCAuthTest (t * testing.T , hostPort , tlsCertPath , macPath string ,
801
833
noMac bool , makeRequest requestFn , successContent string , disabled bool ,
802
- disabledErr string ) {
834
+ disabledErr string , isSubServer , statelessInit bool ) {
803
835
804
836
ctxb := context .Background ()
805
837
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -833,13 +865,27 @@ func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
833
865
// Add dummy data as the macaroon, that should fail as well.
834
866
ctxm := macaroonContext (ctxt , []byte ("dummy" ))
835
867
_ , err = makeRequest (ctxm , rawConn )
836
- require .ErrorContains (t , err , "packet too short" )
868
+ if statelessInit && isSubServer {
869
+ // Some sub-servers have slightly different structured
870
+ // errors but all of them contain these two words/phrases.
871
+ require .ErrorContains (t , err , "macaroon service" )
872
+ require .ErrorContains (t , err , "initialised" )
873
+ } else {
874
+ require .ErrorContains (t , err , "packet too short" )
875
+ }
837
876
838
877
// Add a macaroon that can be parsed but that's not issued by lnd, which
839
878
// should also fail.
840
879
ctxm = macaroonContext (ctxt , dummyMacBytes )
841
880
_ , err = makeRequest (ctxm , rawConn )
842
- require .ErrorContains (t , err , "invalid ID" )
881
+ if statelessInit && isSubServer {
882
+ // Some sub-servers have slightly different structured
883
+ // errors but all of them contain these two words/phrases.
884
+ require .ErrorContains (t , err , "macaroon service" )
885
+ require .ErrorContains (t , err , "initialised" )
886
+ } else {
887
+ require .ErrorContains (t , err , "invalid ID" )
888
+ }
843
889
844
890
// Then finally we try with the correct macaroon which should now
845
891
// succeed, as long as it is not for a disabled sub-server.
@@ -861,7 +907,8 @@ func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
861
907
// runUIPasswordCheck tests UI password authentication.
862
908
func runUIPasswordCheck (t * testing.T , hostPort , tlsCertPath , uiPassword string ,
863
909
makeRequest requestFn , noAuth , shouldFailWithoutMacaroon bool ,
864
- successContent string , disabled bool , disabledErr string ) {
910
+ successContent string , disabled bool , disabledErr string ,
911
+ isSubServer , statelessInit bool ) {
865
912
866
913
ctxb := context .Background ()
867
914
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -903,9 +950,15 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
903
950
// shouldn't be allowed and result in an error.
904
951
ctxm = uiPasswordContext (ctxt , "foobar" , true )
905
952
_ , err = makeRequest (ctxm , rawConn )
906
- if disabled {
953
+ switch {
954
+ case disabled :
907
955
require .ErrorContains (t , err , disabledErr )
908
- } else {
956
+ case statelessInit && isSubServer :
957
+ // Some sub-servers have slightly different structured
958
+ // errors but all of them contain these two words/phrases.
959
+ require .ErrorContains (t , err , "macaroon service" )
960
+ require .ErrorContains (t , err , "initialised" )
961
+ default :
909
962
require .ErrorContains (t , err , "invalid ID" )
910
963
}
911
964
@@ -931,9 +984,16 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
931
984
ctxm = uiPasswordContext (ctxt , uiPassword , true )
932
985
_ , err = makeRequest (ctxm , rawConn )
933
986
934
- if disabled {
987
+ switch {
988
+ case disabled :
935
989
require .ErrorContains (t , err , disabledErr )
936
- } else {
990
+ case statelessInit && isSubServer :
991
+ // Some sub-servers have slightly different structured
992
+ // errors but all of them contain these two
993
+ // words/phrases.
994
+ require .ErrorContains (t , err , "macaroon service" )
995
+ require .ErrorContains (t , err , "initialised" )
996
+ default :
937
997
require .ErrorContains (t , err , "invalid ID" )
938
998
}
939
999
@@ -1373,8 +1433,16 @@ func connectRPC(ctx context.Context, hostPort,
1373
1433
return grpc .DialContext (ctx , hostPort , opts ... )
1374
1434
}
1375
1435
1376
- func bakeSuperMacaroon (t * testing.T , cfg * LitNodeConfig , readOnly bool ) string {
1436
+ func getLiTMacFromFile (t * testing.T , cfg * LitNodeConfig ) [] byte {
1377
1437
litMac := litMacaroonFn (cfg )
1438
+ litMacBytes , err := os .ReadFile (litMac )
1439
+ require .NoError (t , err )
1440
+
1441
+ return litMacBytes
1442
+ }
1443
+
1444
+ func bakeSuperMacaroon (t * testing.T , cfg * LitNodeConfig ,
1445
+ getMac func (* testing.T , * LitNodeConfig ) []byte , readOnly bool ) string {
1378
1446
1379
1447
ctxb := context .Background ()
1380
1448
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -1385,14 +1453,11 @@ func bakeSuperMacaroon(t *testing.T, cfg *LitNodeConfig, readOnly bool) string {
1385
1453
1386
1454
defer rawConn .Close ()
1387
1455
1388
- litMacBytes , err := os .ReadFile (litMac )
1389
- require .NoError (t , err )
1390
-
1391
- litMacCtx := macaroonContext (ctxt , litMacBytes )
1456
+ macCtx := macaroonContext (ctxt , getMac (t , cfg ))
1392
1457
litConn := litrpc .NewProxyClient (rawConn )
1393
1458
1394
1459
bakeMacResp , err := litConn .BakeSuperMacaroon (
1395
- litMacCtx , & litrpc.BakeSuperMacaroonRequest {
1460
+ macCtx , & litrpc.BakeSuperMacaroonRequest {
1396
1461
RootKeyIdSuffix : 0 ,
1397
1462
ReadOnly : readOnly ,
1398
1463
},
0 commit comments