@@ -367,12 +367,21 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
367
367
t .t .Run ("lnc auth" , func (tt * testing.T ) {
368
368
cfg := net .Alice .Cfg
369
369
370
+ ctx := context .Background ()
371
+ ctxt , cancel := context .WithTimeout (ctx , defaultTimeout )
372
+ defer cancel ()
373
+
374
+ rawLNCConn := setUpLNCConn (
375
+ ctxt , t .t , cfg .LitAddr (), cfg .TLSCertPath ,
376
+ cfg .LitMacPath ,
377
+ )
378
+ defer rawLNCConn .Close ()
379
+
370
380
for _ , endpoint := range endpoints {
371
381
endpoint := endpoint
372
382
tt .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
373
383
runLNCAuthTest (
374
- ttt , cfg .LitAddr (), cfg .TLSCertPath ,
375
- cfg .LitMacPath , endpoint .requestFn ,
384
+ ttt , rawLNCConn , endpoint .requestFn ,
376
385
endpoint .successPattern ,
377
386
endpoint .allowedThroughLNC ,
378
387
)
@@ -381,6 +390,41 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
381
390
})
382
391
}
383
392
393
+ // setUpLNCConn creates a new LNC session and then creates a connection to that
394
+ // session via the mailbox that the session was created with.
395
+ func setUpLNCConn (ctx context.Context , t * testing.T , hostPort , tlsCertPath ,
396
+ macPath string ) * grpc.ClientConn {
397
+
398
+ rawConn , err := connectRPC (ctx , hostPort , tlsCertPath )
399
+ require .NoError (t , err )
400
+
401
+ macBytes , err := ioutil .ReadFile (macPath )
402
+ require .NoError (t , err )
403
+ ctxm := macaroonContext (ctx , macBytes )
404
+
405
+ // We first need to create an LNC session that we can use to connect.
406
+ litClient := litrpc .NewSessionsClient (rawConn )
407
+ sessResp , err := litClient .AddSession (ctxm , & litrpc.AddSessionRequest {
408
+ Label : "integration-test" ,
409
+ SessionType : litrpc .SessionType_TYPE_MACAROON_READONLY ,
410
+ ExpiryTimestampSeconds : uint64 (
411
+ time .Now ().Add (5 * time .Minute ).Unix (),
412
+ ),
413
+ MailboxServerAddr : mailboxServerAddr ,
414
+ })
415
+ require .NoError (t , err )
416
+
417
+ // Try the LNC connection now.
418
+ connectPhrase := strings .Split (
419
+ sessResp .Session .PairingSecretMnemonic , " " ,
420
+ )
421
+
422
+ rawLNCConn , err := connectMailbox (ctx , connectPhrase )
423
+ require .NoError (t , err )
424
+
425
+ return rawLNCConn
426
+ }
427
+
384
428
// runCertificateCheck checks that the TLS certificates presented to clients are
385
429
// what we expect them to be.
386
430
func runCertificateCheck (t * testing.T , node * HarnessNode ) {
@@ -624,44 +668,14 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
624
668
625
669
// runLNCAuthTest tests authentication of the given interface when connecting
626
670
// through Lightning Node Connect.
627
- func runLNCAuthTest (t * testing.T , hostPort , tlsCertPath , macPath string ,
671
+ func runLNCAuthTest (t * testing.T , rawLNCConn grpc. ClientConnInterface ,
628
672
makeRequest requestFn , successContent string , callAllowed bool ) {
629
673
630
- ctxb := context .Background ()
631
- ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
632
- defer cancel ()
633
-
634
- rawConn , err := connectRPC (ctxt , hostPort , tlsCertPath )
635
- require .NoError (t , err )
636
-
637
- macBytes , err := ioutil .ReadFile (macPath )
638
- require .NoError (t , err )
639
- ctxm := macaroonContext (ctxt , macBytes )
640
-
641
- // We first need to create an LNC session that we can use to connect.
642
- // We use the UI password to create the session.
643
- litClient := litrpc .NewSessionsClient (rawConn )
644
- sessResp , err := litClient .AddSession (ctxm , & litrpc.AddSessionRequest {
645
- Label : "integration-test" ,
646
- SessionType : litrpc .SessionType_TYPE_MACAROON_READONLY ,
647
- ExpiryTimestampSeconds : uint64 (
648
- time .Now ().Add (5 * time .Minute ).Unix (),
649
- ),
650
- MailboxServerAddr : mailboxServerAddr ,
651
- })
652
- require .NoError (t , err )
653
-
654
- // Try the LNC connection now.
655
- connectPhrase := strings .Split (
656
- sessResp .Session .PairingSecretMnemonic , " " ,
674
+ ctxt , cancel := context .WithTimeout (
675
+ context .Background (), defaultTimeout ,
657
676
)
658
-
659
- ctxt , cancel = context .WithTimeout (ctxb , defaultTimeout )
660
677
defer cancel ()
661
678
662
- rawLNCConn , err := connectMailbox (ctxt , connectPhrase )
663
- require .NoError (t , err )
664
-
665
679
// We should be able to make a request via LNC to the given RPC
666
680
// endpoint, unless it is explicitly disallowed (we currently don't want
667
681
// to support creating more sessions through LNC until we have all
@@ -767,7 +781,7 @@ func getServerCertificates(hostPort string) ([]*x509.Certificate, error) {
767
781
// connectMailbox tries to establish a connection through LNC using the given
768
782
// connect phrase and the test mailbox server.
769
783
func connectMailbox (ctx context.Context ,
770
- connectPhrase []string ) (grpc.ClientConnInterface , error ) {
784
+ connectPhrase []string ) (* grpc.ClientConn , error ) {
771
785
772
786
var mnemonicWords [mailbox .NumPassphraseWords ]string
773
787
copy (mnemonicWords [:], connectPhrase )
0 commit comments