Skip to content

Commit b76832a

Browse files
committed
itest: add a stateless_init test
Extract some of the tests used for the integrated and remote mode tests and re-use them in a new test that runs them against a node stareted in state-less init mode.
1 parent 70cacf0 commit b76832a

File tree

4 files changed

+223
-83
lines changed

4 files changed

+223
-83
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 146 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ var (
225225
restWebURI string
226226
restPOST bool
227227
canDisable bool
228+
isSubServer bool
228229

229230
// noAuth is true if the call does not require a macaroon.
230231
noAuth bool
@@ -277,6 +278,7 @@ var (
277278
grpcWebURI: "/frdrpc.FaradayServer/RevenueReport",
278279
restWebURI: "/v1/faraday/revenue",
279280
canDisable: true,
281+
isSubServer: true,
280282
}, {
281283
name: "looprpc",
282284
macaroonFn: loopMacaroonFn,
@@ -287,6 +289,7 @@ var (
287289
grpcWebURI: "/looprpc.SwapClient/ListSwaps",
288290
restWebURI: "/v1/loop/swaps",
289291
canDisable: true,
292+
isSubServer: true,
290293
}, {
291294
name: "poolrpc",
292295
macaroonFn: poolMacaroonFn,
@@ -297,6 +300,7 @@ var (
297300
grpcWebURI: "/poolrpc.Trader/GetInfo",
298301
restWebURI: "/v1/pool/info",
299302
canDisable: true,
303+
isSubServer: true,
300304
}, {
301305
name: "taprpc",
302306
macaroonFn: tapMacaroonFn,
@@ -307,6 +311,7 @@ var (
307311
grpcWebURI: "/taprpc.TaprootAssets/ListAssets",
308312
restWebURI: "/v1/taproot-assets/assets",
309313
canDisable: true,
314+
isSubServer: true,
310315
}, {
311316
name: "taprpc-whitelist",
312317
macaroonFn: emptyMacaroonFn,
@@ -318,6 +323,7 @@ var (
318323
restWebURI: "/v1/taproot-assets/universe/info",
319324
canDisable: true,
320325
noAuth: true,
326+
isSubServer: true,
321327
}, {
322328
name: "litrpc-sessions",
323329
macaroonFn: litMacaroonFn,
@@ -494,6 +500,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
494500
endpoint.successPattern,
495501
endpointDisabled || endpoint.litOnly,
496502
"Unimplemented desc = unknown service",
503+
endpoint.isSubServer, false,
497504
)
498505
})
499506

@@ -506,47 +513,18 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
506513
endpoint.successPattern,
507514
endpointDisabled,
508515
endpoint.disabledPattern,
516+
endpoint.isSubServer,
517+
false,
509518
)
510519
})
511520
}
512521
})
513522

514523
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+
)
550528
})
551529

552530
t.Run("UI index page fallback", func(tt *testing.T) {
@@ -576,37 +554,10 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
576554
})
577555

578556
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+
)
610561
})
611562

612563
t.Run("REST auth", func(tt *testing.T) {
@@ -673,7 +624,9 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
673624
return
674625
}
675626

676-
superMacFile := bakeSuperMacaroon(tt, cfg, false)
627+
superMacFile := bakeSuperMacaroon(
628+
tt, cfg, getLiTMacFromFile, false,
629+
)
677630

678631
ht := newHarnessTest(tt, net)
679632
runAccountSystemTest(
@@ -740,6 +693,48 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
740693
})
741694
}
742695

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+
743738
// setUpLNCConn creates a new LNC session and then creates a connection to that
744739
// session via the mailbox that the session was created with.
745740
func setUpLNCConn(ctx context.Context, t *testing.T, hostPort, tlsCertPath,
@@ -778,6 +773,43 @@ func setUpLNCConn(ctx context.Context, t *testing.T, hostPort, tlsCertPath,
778773
return rawLNCConn
779774
}
780775

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+
781813
// runCertificateCheck checks that the TLS certificates presented to clients are
782814
// what we expect them to be.
783815
func runCertificateCheck(t *testing.T, node *HarnessNode) {
@@ -799,7 +831,7 @@ func runCertificateCheck(t *testing.T, node *HarnessNode) {
799831
// runGRPCAuthTest tests authentication of the given gRPC interface.
800832
func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
801833
noMac bool, makeRequest requestFn, successContent string, disabled bool,
802-
disabledErr string) {
834+
disabledErr string, isSubServer, statelessInit bool) {
803835

804836
ctxb := context.Background()
805837
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -833,13 +865,27 @@ func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
833865
// Add dummy data as the macaroon, that should fail as well.
834866
ctxm := macaroonContext(ctxt, []byte("dummy"))
835867
_, 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+
}
837876

838877
// Add a macaroon that can be parsed but that's not issued by lnd, which
839878
// should also fail.
840879
ctxm = macaroonContext(ctxt, dummyMacBytes)
841880
_, 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+
}
843889

844890
// Then finally we try with the correct macaroon which should now
845891
// 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,
861907
// runUIPasswordCheck tests UI password authentication.
862908
func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
863909
makeRequest requestFn, noAuth, shouldFailWithoutMacaroon bool,
864-
successContent string, disabled bool, disabledErr string) {
910+
successContent string, disabled bool, disabledErr string,
911+
isSubServer, statelessInit bool) {
865912

866913
ctxb := context.Background()
867914
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -903,9 +950,15 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
903950
// shouldn't be allowed and result in an error.
904951
ctxm = uiPasswordContext(ctxt, "foobar", true)
905952
_, err = makeRequest(ctxm, rawConn)
906-
if disabled {
953+
switch {
954+
case disabled:
907955
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:
909962
require.ErrorContains(t, err, "invalid ID")
910963
}
911964

@@ -931,9 +984,16 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
931984
ctxm = uiPasswordContext(ctxt, uiPassword, true)
932985
_, err = makeRequest(ctxm, rawConn)
933986

934-
if disabled {
987+
switch {
988+
case disabled:
935989
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:
937997
require.ErrorContains(t, err, "invalid ID")
938998
}
939999

@@ -1373,8 +1433,16 @@ func connectRPC(ctx context.Context, hostPort,
13731433
return grpc.DialContext(ctx, hostPort, opts...)
13741434
}
13751435

1376-
func bakeSuperMacaroon(t *testing.T, cfg *LitNodeConfig, readOnly bool) string {
1436+
func getLiTMacFromFile(t *testing.T, cfg *LitNodeConfig) []byte {
13771437
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 {
13781446

13791447
ctxb := context.Background()
13801448
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1385,14 +1453,11 @@ func bakeSuperMacaroon(t *testing.T, cfg *LitNodeConfig, readOnly bool) string {
13851453

13861454
defer rawConn.Close()
13871455

1388-
litMacBytes, err := os.ReadFile(litMac)
1389-
require.NoError(t, err)
1390-
1391-
litMacCtx := macaroonContext(ctxt, litMacBytes)
1456+
macCtx := macaroonContext(ctxt, getMac(t, cfg))
13921457
litConn := litrpc.NewProxyClient(rawConn)
13931458

13941459
bakeMacResp, err := litConn.BakeSuperMacaroon(
1395-
litMacCtx, &litrpc.BakeSuperMacaroonRequest{
1460+
macCtx, &litrpc.BakeSuperMacaroonRequest{
13961461
RootKeyIdSuffix: 0,
13971462
ReadOnly: readOnly,
13981463
},

0 commit comments

Comments
 (0)