mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
becbe7085d
With this commit we add a new helper function that recursively turns the runtime configuration into a flat key/value map that is human-readable, using the dot notation for nested values that is also used in the config file or command line flags.
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package lnd
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/lightningnetwork/lnd/chainreg"
|
|
"github.com/lightningnetwork/lnd/routing"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var (
|
|
testPassword = "testpassword"
|
|
redactedPassword = "[redacted]"
|
|
)
|
|
|
|
// TestConfigToFlatMap tests that the configToFlatMap function works as
|
|
// expected on the default configuration.
|
|
func TestConfigToFlatMap(t *testing.T) {
|
|
cfg := DefaultConfig()
|
|
cfg.BitcoindMode.RPCPass = testPassword
|
|
cfg.BtcdMode.RPCPass = testPassword
|
|
cfg.Tor.Password = testPassword
|
|
cfg.DB.Etcd.Pass = testPassword
|
|
cfg.DB.Postgres.Dsn = testPassword
|
|
|
|
result, err := configToFlatMap(cfg)
|
|
require.NoError(t, err)
|
|
|
|
// Pick a couple of random values to check.
|
|
require.Equal(t, DefaultLndDir, result["lnddir"])
|
|
require.Equal(
|
|
t, fmt.Sprintf("%v", chainreg.DefaultBitcoinTimeLockDelta),
|
|
result["bitcoin.timelockdelta"],
|
|
)
|
|
require.Equal(
|
|
t, fmt.Sprintf("%v", routing.DefaultAprioriWeight),
|
|
result["routerrpc.apriori.weight"],
|
|
)
|
|
require.Contains(t, result, "routerrpc.routermacaroonpath")
|
|
|
|
// Check that sensitive values are not included.
|
|
require.Equal(t, redactedPassword, result["bitcoind.rpcpass"])
|
|
require.Equal(t, redactedPassword, result["btcd.rpcpass"])
|
|
require.Equal(t, redactedPassword, result["tor.password"])
|
|
require.Equal(t, redactedPassword, result["db.etcd.pass"])
|
|
require.Equal(t, redactedPassword, result["db.postgres.dsn"])
|
|
}
|