macaroons: futher abstract NewService from root key store impl

In this commit, we modify the `macaroons.NewService` consturctor to
accept the main interface rather than the raw DB. This allows us to use
other backends other than bolt or the kvdb interface to store the
macaroon root keys.

We also create a new ExtendedRootKeyStore interface that implements some
of the more advanced features we use such as macaroon encryption and
password rotation.
This commit is contained in:
Olaoluwa Osuntokun committed 2022-07-06 18:59:50 -07:00
1 parent 947639bb60
commit e073b1d343
5 files changed
+91 -24

No files matched your search

+13 -4
View File
@@ -59,10 +59,13 @@ func TestNewService(t *testing.T) {
tempDir, db := setupTestRootKeyStorage(t)
defer os.RemoveAll(tempDir)
rootKeyStore, err := macaroons.NewRootKeyStorage(db)
require.NoError(t, err)
// Second, create the new service instance, unlock it and pass in a
// checker that we expect it to add to the bakery.
service, err := macaroons.NewService(
db, "lnd", false, macaroons.IPLockChecker,
rootKeyStore, "lnd", false, macaroons.IPLockChecker,
)
require.NoError(t, err, "Error creating new service")
defer service.Close()
@@ -106,8 +109,10 @@ func TestValidateMacaroon(t *testing.T) {
// First, initialize the service and unlock it.
tempDir, db := setupTestRootKeyStorage(t)
defer os.RemoveAll(tempDir)
rootKeyStore, err := macaroons.NewRootKeyStorage(db)
require.NoError(t, err)
service, err := macaroons.NewService(
db, "lnd", false, macaroons.IPLockChecker,
rootKeyStore, "lnd", false, macaroons.IPLockChecker,
)
require.NoError(t, err, "Error creating new service")
defer service.Close()
@@ -154,8 +159,10 @@ func TestListMacaroonIDs(t *testing.T) {
// Second, create the new service instance, unlock it and pass in a
// checker that we expect it to add to the bakery.
rootKeyStore, err := macaroons.NewRootKeyStorage(db)
require.NoError(t, err)
service, err := macaroons.NewService(
db, "lnd", false, macaroons.IPLockChecker,
rootKeyStore, "lnd", false, macaroons.IPLockChecker,
)
require.NoError(t, err, "Error creating new service")
defer service.Close()
@@ -186,8 +193,10 @@ func TestDeleteMacaroonID(t *testing.T) {
// Second, create the new service instance, unlock it and pass in a
// checker that we expect it to add to the bakery.
rootKeyStore, err := macaroons.NewRootKeyStorage(db)
require.NoError(t, err)
service, err := macaroons.NewService(
db, "lnd", false, macaroons.IPLockChecker,
rootKeyStore, "lnd", false, macaroons.IPLockChecker,
)
require.NoError(t, err, "Error creating new service")
defer service.Close()