@@ -586,12 +586,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
586
586
t .Run ("gRPC super macaroon auth check" , func (tt * testing.T ) {
587
587
cfg := net .Alice .Cfg
588
588
589
- superMacFile , err := bakeSuperMacaroon (cfg , true )
590
- require .NoError (tt , err )
591
-
592
- defer func () {
593
- _ = os .Remove (superMacFile )
594
- }()
589
+ superMacFile := bakeSuperMacaroon (tt , cfg , true )
595
590
596
591
for _ , endpoint := range endpoints {
597
592
endpoint := endpoint
@@ -686,12 +681,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
686
681
return
687
682
}
688
683
689
- superMacFile , err := bakeSuperMacaroon (cfg , false )
690
- require .NoError (tt , err )
691
-
692
- defer func () {
693
- _ = os .Remove (superMacFile )
694
- }()
684
+ superMacFile := bakeSuperMacaroon (tt , cfg , false )
695
685
696
686
ht := newHarnessTest (tt , net )
697
687
runAccountSystemTest (
@@ -1391,30 +1381,26 @@ func connectRPC(ctx context.Context, hostPort,
1391
1381
return grpc .DialContext (ctx , hostPort , opts ... )
1392
1382
}
1393
1383
1394
- func bakeSuperMacaroon (cfg * LitNodeConfig , readOnly bool ) ( string , error ) {
1384
+ func bakeSuperMacaroon (t * testing. T , cfg * LitNodeConfig , readOnly bool ) string {
1395
1385
lndAdminMac := lndMacaroonFn (cfg )
1396
1386
1397
1387
ctxb := context .Background ()
1398
1388
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
1399
1389
defer cancel ()
1400
1390
1401
1391
rawConn , err := connectRPC (ctxt , cfg .RPCAddr (), cfg .TLSCertPath )
1402
- if err != nil {
1403
- return "" , err
1404
- }
1392
+ require .NoError (t , err )
1393
+
1405
1394
defer rawConn .Close ()
1406
1395
1407
- lndAdminMacBytes , err := ioutil .ReadFile (lndAdminMac )
1408
- if err != nil {
1409
- return "" , err
1410
- }
1396
+ lndAdminMacBytes , err := os .ReadFile (lndAdminMac )
1397
+ require .NoError (t , err )
1398
+
1411
1399
lndAdminCtx := macaroonContext (ctxt , lndAdminMacBytes )
1412
1400
lndConn := lnrpc .NewLightningClient (rawConn )
1413
1401
1414
1402
permsMgr , err := perms .NewManager (false )
1415
- if err != nil {
1416
- return "" , err
1417
- }
1403
+ require .NoError (t , err )
1418
1404
1419
1405
permsMgr .RegisterSubServer (
1420
1406
subservers .LOOP , loop .RequiredPermissions , nil ,
@@ -1438,25 +1424,18 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
1438
1424
lndAdminCtx , lndConn , session .NewSuperMacaroonRootKeyID (nullID ),
1439
1425
superMacPermissions , nil ,
1440
1426
)
1441
- if err != nil {
1442
- return "" , err
1443
- }
1427
+ require .NoError (t , err )
1444
1428
1445
1429
// The BakeSuperMacaroon function just hex encoded the macaroon, we know
1446
1430
// it's valid.
1447
1431
superMacBytes , _ := hex .DecodeString (superMacHex )
1448
1432
1449
- tempFile , err := os .CreateTemp ("" , "lit-super-macaroon" )
1450
- if err != nil {
1451
- _ = os .Remove (tempFile .Name ())
1452
- return "" , err
1453
- }
1433
+ tempDir := t .TempDir ()
1434
+ tempFile , err := os .CreateTemp (tempDir , "lit-super-macaroon" )
1435
+ require .NoError (t , err )
1454
1436
1455
1437
err = os .WriteFile (tempFile .Name (), superMacBytes , 0644 )
1456
- if err != nil {
1457
- _ = os .Remove (tempFile .Name ())
1458
- return "" , err
1459
- }
1438
+ require .NoError (t , err )
1460
1439
1461
- return tempFile .Name (), nil
1440
+ return tempFile .Name ()
1462
1441
}
0 commit comments