itest: refactor testDeleteMacaroonID
This commit is contained in:
3 files changed
+27
-27
No files matched your search
@@ -353,4 +353,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "bake macaroon",
|
Name: "bake macaroon",
|
||||||
TestFunc: testBakeMacaroon,
|
TestFunc: testBakeMacaroon,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "delete macaroon id",
|
||||||
|
TestFunc: testDeleteMacaroonID,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -520,26 +520,26 @@ func testBakeMacaroon(ht *lntemp.HarnessTest) {
|
|||||||
// specified ID and invalidates all macaroons derived from the key with that ID.
|
// specified ID and invalidates all macaroons derived from the key with that ID.
|
||||||
// Also, it checks deleting the reserved marcaroon ID, DefaultRootKeyID or is
|
// Also, it checks deleting the reserved marcaroon ID, DefaultRootKeyID or is
|
||||||
// forbidden.
|
// forbidden.
|
||||||
func testDeleteMacaroonID(net *lntest.NetworkHarness, t *harnessTest) {
|
func testDeleteMacaroonID(ht *lntemp.HarnessTest) {
|
||||||
var (
|
var (
|
||||||
ctxb = context.Background()
|
ctxb = ht.Context()
|
||||||
testNode = net.Alice
|
testNode = ht.Alice
|
||||||
)
|
)
|
||||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Use admin macaroon to create a connection.
|
// Use admin macaroon to create a connection.
|
||||||
adminMac, err := testNode.ReadMacaroon(
|
adminMac, err := testNode.ReadMacaroon(
|
||||||
testNode.AdminMacPath(), defaultTimeout,
|
testNode.Cfg.AdminMacPath, defaultTimeout,
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
cleanup, client := macaroonClientOld(t.t, testNode, adminMac)
|
cleanup, client := macaroonClient(ht.T, testNode, adminMac)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// Record the number of macaroon IDs before creation.
|
// Record the number of macaroon IDs before creation.
|
||||||
listReq := &lnrpc.ListMacaroonIDsRequest{}
|
listReq := &lnrpc.ListMacaroonIDsRequest{}
|
||||||
listResp, err := client.ListMacaroonIDs(ctxt, listReq)
|
listResp, err := client.ListMacaroonIDs(ctxt, listReq)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
numMacIDs := len(listResp.RootKeyIds)
|
numMacIDs := len(listResp.RootKeyIds)
|
||||||
|
|
||||||
// Create macaroons for testing.
|
// Create macaroons for testing.
|
||||||
@@ -554,17 +554,17 @@ func testDeleteMacaroonID(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
resp, err := client.BakeMacaroon(ctxt, req)
|
resp, err := client.BakeMacaroon(ctxt, req)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
macList = append(macList, resp.Macaroon)
|
macList = append(macList, resp.Macaroon)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the creation is successful.
|
// Check that the creation is successful.
|
||||||
listReq = &lnrpc.ListMacaroonIDsRequest{}
|
listReq = &lnrpc.ListMacaroonIDsRequest{}
|
||||||
listResp, err = client.ListMacaroonIDs(ctxt, listReq)
|
listResp, err = client.ListMacaroonIDs(ctxt, listReq)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
// The number of macaroon IDs should be increased by len(rootKeyIDs).
|
// The number of macaroon IDs should be increased by len(rootKeyIDs).
|
||||||
require.Equal(t.t, numMacIDs+len(rootKeyIDs), len(listResp.RootKeyIds))
|
require.Equal(ht, numMacIDs+len(rootKeyIDs), len(listResp.RootKeyIds))
|
||||||
|
|
||||||
// First test: check deleting the DefaultRootKeyID returns an error.
|
// First test: check deleting the DefaultRootKeyID returns an error.
|
||||||
defaultID, _ := strconv.ParseUint(
|
defaultID, _ := strconv.ParseUint(
|
||||||
@@ -574,38 +574,38 @@ func testDeleteMacaroonID(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
RootKeyId: defaultID,
|
RootKeyId: defaultID,
|
||||||
}
|
}
|
||||||
_, err = client.DeleteMacaroonID(ctxt, req)
|
_, err = client.DeleteMacaroonID(ctxt, req)
|
||||||
require.Error(t.t, err)
|
require.Error(ht, err)
|
||||||
require.Contains(
|
require.Contains(ht, err.Error(),
|
||||||
t.t, err.Error(), macaroons.ErrDeletionForbidden.Error(),
|
macaroons.ErrDeletionForbidden.Error())
|
||||||
)
|
|
||||||
|
|
||||||
// Second test: check deleting the customized ID returns success.
|
// Second test: check deleting the customized ID returns success.
|
||||||
req = &lnrpc.DeleteMacaroonIDRequest{
|
req = &lnrpc.DeleteMacaroonIDRequest{
|
||||||
RootKeyId: rootKeyIDs[0],
|
RootKeyId: rootKeyIDs[0],
|
||||||
}
|
}
|
||||||
resp, err := client.DeleteMacaroonID(ctxt, req)
|
resp, err := client.DeleteMacaroonID(ctxt, req)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
require.True(t.t, resp.Deleted)
|
require.True(ht, resp.Deleted)
|
||||||
|
|
||||||
// Check that the deletion is successful.
|
// Check that the deletion is successful.
|
||||||
listReq = &lnrpc.ListMacaroonIDsRequest{}
|
listReq = &lnrpc.ListMacaroonIDsRequest{}
|
||||||
listResp, err = client.ListMacaroonIDs(ctxt, listReq)
|
listResp, err = client.ListMacaroonIDs(ctxt, listReq)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
// The number of macaroon IDs should be decreased by 1.
|
// The number of macaroon IDs should be decreased by 1.
|
||||||
require.Equal(t.t, numMacIDs+len(rootKeyIDs)-1, len(listResp.RootKeyIds))
|
require.Equal(ht, numMacIDs+len(rootKeyIDs)-1, len(listResp.RootKeyIds))
|
||||||
|
|
||||||
// Check that the deleted macaroon can no longer access macaroon:read.
|
// Check that the deleted macaroon can no longer access macaroon:read.
|
||||||
deletedMac, err := readMacaroonFromHex(macList[0])
|
deletedMac, err := readMacaroonFromHex(macList[0])
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
cleanup, client = macaroonClientOld(t.t, testNode, deletedMac)
|
cleanup, client = macaroonClient(ht.T, testNode, deletedMac)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
// Because the macaroon is deleted, it will be treated as an invalid one.
|
// Because the macaroon is deleted, it will be treated as an invalid
|
||||||
|
// one.
|
||||||
listReq = &lnrpc.ListMacaroonIDsRequest{}
|
listReq = &lnrpc.ListMacaroonIDsRequest{}
|
||||||
_, err = client.ListMacaroonIDs(ctxt, listReq)
|
_, err = client.ListMacaroonIDs(ctxt, listReq)
|
||||||
require.Error(t.t, err)
|
require.Error(ht, err)
|
||||||
require.Contains(t.t, err.Error(), "cannot get macaroon")
|
require.Contains(ht, err.Error(), "cannot get macaroon")
|
||||||
}
|
}
|
||||||
|
|
||||||
// testStatelessInit checks that the stateless initialization of the daemon
|
// testStatelessInit checks that the stateless initialization of the daemon
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "cpfp",
|
name: "cpfp",
|
||||||
test: testCPFP,
|
test: testCPFP,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "delete macaroon id",
|
|
||||||
test: testDeleteMacaroonID,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "psbt channel funding",
|
name: "psbt channel funding",
|
||||||
test: testPsbtChanFunding,
|
test: testPsbtChanFunding,
|
||||||
|
|||||||
Reference in new issue
Block a user