@@ -335,9 +335,8 @@ func testModeIntegrated(net *NetworkHarness, t *harnessTest) {
335335 endpoint := endpoint
336336 tt .Run (endpoint .name + " lit port" , func (ttt * testing.T ) {
337337 runLNCAuthTest (
338- ttt , cfg .LitAddr (), cfg .UIPassword ,
339- cfg .TLSCertPath ,
340- endpoint .requestFn ,
338+ ttt , cfg .LitAddr (), cfg .TLSCertPath ,
339+ cfg .LitMacPath , endpoint .requestFn ,
341340 endpoint .successPattern ,
342341 endpoint .allowedThroughLNC ,
343342 )
@@ -583,7 +582,7 @@ func runRESTAuthTest(t *testing.T, hostPort, uiPassword, macaroonPath, restURI,
583582
584583// runLNCAuthTest tests authentication of the given interface when connecting
585584// through Lightning Node Connect.
586- func runLNCAuthTest (t * testing.T , hostPort , uiPassword , tlsCertPath string ,
585+ func runLNCAuthTest (t * testing.T , hostPort , tlsCertPath , macPath string ,
587586 makeRequest requestFn , successContent string , callAllowed bool ) {
588587
589588 ctxb := context .Background ()
@@ -593,11 +592,14 @@ func runLNCAuthTest(t *testing.T, hostPort, uiPassword, tlsCertPath string,
593592 rawConn , err := connectRPC (ctxt , hostPort , tlsCertPath )
594593 require .NoError (t , err )
595594
595+ macBytes , err := ioutil .ReadFile (macPath )
596+ require .NoError (t , err )
597+ ctxlm := macaroonContext (ctxt , macBytes )
598+
596599 // We first need to create an LNC session that we can use to connect.
597600 // We use the UI password to create the session.
598- ctxm := uiPasswordContext (ctxt , uiPassword , true )
599601 litClient := litrpc .NewSessionsClient (rawConn )
600- sessResp , err := litClient .AddSession (ctxm , & litrpc.AddSessionRequest {
602+ sessResp , err := litClient .AddSession (ctxlm , & litrpc.AddSessionRequest {
601603 Label : "integration-test" ,
602604 SessionType : litrpc .SessionType_TYPE_MACAROON_READONLY ,
603605 ExpiryTimestampSeconds : uint64 (
@@ -611,13 +613,14 @@ func runLNCAuthTest(t *testing.T, hostPort, uiPassword, tlsCertPath string,
611613 connectPhrase := strings .Split (
612614 sessResp .Session .PairingSecretMnemonic , " " ,
613615 )
614- rawLNCConn , err := connectMailbox (ctxt , connectPhrase )
616+ rawLNCConn , macBytes , err := connectMailbox (ctxt , connectPhrase )
615617 require .NoError (t , err )
616618
617619 // We should be able to make a request via LNC to the given RPC
618620 // endpoint, unless it is explicitly disallowed (we currently don't want
619621 // to support creating more sessions through LNC until we have all
620622 // macaroon permissions properly set up).
623+ ctxm := macaroonContext (ctxt , macBytes )
621624 resp , err := makeRequest (ctxm , rawLNCConn )
622625
623626 // Is this a disallowed call?
@@ -719,7 +722,7 @@ func getServerCertificates(hostPort string) ([]*x509.Certificate, error) {
719722// connectMailbox tries to establish a connection through LNC using the given
720723// connect phrase and the test mailbox server.
721724func connectMailbox (ctx context.Context ,
722- connectPhrase []string ) (grpc.ClientConnInterface , error ) {
725+ connectPhrase []string ) (grpc.ClientConnInterface , [] byte , error ) {
723726
724727 var mnemonicWords [mailbox .NumPasswordWords ]string
725728 copy (mnemonicWords [:], connectPhrase )
@@ -729,13 +732,13 @@ func connectMailbox(ctx context.Context,
729732
730733 privKey , err := btcec .NewPrivateKey (btcec .S256 ())
731734 if err != nil {
732- return nil , err
735+ return nil , nil , err
733736 }
734737 ecdh := & keychain.PrivKeyECDH {PrivKey : privKey }
735738
736739 transportConn , err := mailbox .NewClient (ctx , sid )
737740 if err != nil {
738- return nil , err
741+ return nil , nil , err
739742 }
740743
741744 noiseConn := mailbox .NewNoiseGrpcConn (ecdh , nil , password [:])
@@ -744,9 +747,25 @@ func connectMailbox(ctx context.Context,
744747 grpc .WithContextDialer (transportConn .Dial ),
745748 grpc .WithTransportCredentials (noiseConn ),
746749 grpc .WithPerRPCCredentials (noiseConn ),
750+ grpc .WithBlock (),
751+ }
752+
753+ conn , err := grpc .DialContext (ctx , mailboxServerAddr , dialOpts ... )
754+ if err != nil {
755+ return nil , nil , err
756+ }
757+
758+ md , err := noiseConn .GetRequestMetadata (nil , "" )
759+ if err != nil {
760+ return nil , nil , err
761+ }
762+
763+ macStr , ok := md [terminal .HeaderMacaroon ]
764+ if ! ok {
765+ return nil , nil , fmt .Errorf ("no macaroon found in the authdata" )
747766 }
748767
749- return grpc . DialContext ( ctx , mailboxServerAddr , dialOpts ... )
768+ return conn , [] byte ( macStr ), nil
750769}
751770
752771func macaroonContext (ctx context.Context , macBytes []byte ) context.Context {
0 commit comments