mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
Validate bitcoin-s.wallet.walletName config option (#4336)
This commit is contained in:
parent
d60d984a6b
commit
341c712563
@ -214,4 +214,18 @@ class KeyManagerAppConfigTest extends BitcoinSAsyncTest {
|
||||
appConfig1.toBip39KeyManager
|
||||
}
|
||||
}
|
||||
|
||||
it must "validate a wallet name" in {
|
||||
assert(KeyManagerAppConfig.validateWalletName(""))
|
||||
assert(KeyManagerAppConfig.validateWalletName("old-wallet"))
|
||||
|
||||
//weird whitespace
|
||||
assert(!KeyManagerAppConfig.validateWalletName(" "))
|
||||
assert(!KeyManagerAppConfig.validateWalletName(" old-wallet"))
|
||||
|
||||
//no non alpha-numeric
|
||||
assert(!KeyManagerAppConfig.validateWalletName("@@@"))
|
||||
assert(!KeyManagerAppConfig.validateWalletName("old-wallet."))
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,10 @@ case class KeyManagerAppConfig(
|
||||
lazy val networkParameters: NetworkParameters = chain.network
|
||||
|
||||
lazy val walletNameOpt: Option[String] = {
|
||||
config.getStringOrNone(s"bitcoin-s.wallet.walletName")
|
||||
val nameOpt = config.getStringOrNone(s"bitcoin-s.wallet.walletName")
|
||||
require(nameOpt.map(KeyManagerAppConfig.validateWalletName).getOrElse(true),
|
||||
s"Invalid wallet name, only alphanumeric with _, got=$nameOpt")
|
||||
nameOpt
|
||||
}
|
||||
|
||||
lazy val seedFolder: Path = baseDatadir
|
||||
@ -215,4 +218,10 @@ object KeyManagerAppConfig extends AppConfigFactory[KeyManagerAppConfig] {
|
||||
override def fromDatadir(datadir: Path, confs: Vector[Config])(implicit
|
||||
ec: ExecutionContext): KeyManagerAppConfig =
|
||||
KeyManagerAppConfig(datadir, confs)
|
||||
|
||||
def validateWalletName(walletName: String): Boolean = {
|
||||
walletName.forall { char =>
|
||||
char.isLetterOrDigit || char == '-' || char == '_'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,5 +404,4 @@ object WalletAppConfig
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user