mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
core/commands/config: error out if config replace contains privkey
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
@ -273,7 +273,10 @@ func editConfig(filename string) error {
|
||||
func replaceConfig(r repo.Repo, file io.Reader) error {
|
||||
var cfg config.Config
|
||||
if err := json.NewDecoder(file).Decode(&cfg); err != nil {
|
||||
return errors.New("Failed to decode file as config")
|
||||
return errors.New("failed to decode file as config")
|
||||
}
|
||||
if len(cfg.Identity.PrivKey) != 0 {
|
||||
return errors.New("setting private key with API is not supported")
|
||||
}
|
||||
|
||||
keyF, err := getConfig(r, "Identity.PrivKey")
|
||||
|
@ -100,6 +100,17 @@ test_config_cmd() {
|
||||
ipfs config replace show_config &&
|
||||
grep PrivKey "$IPFS_PATH/config" | grep -v ": null" >/dev/null
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs config replace' with privkey erors out" '
|
||||
cp "$IPFS_PATH/config" real_config &&
|
||||
test_expect_code 1 ipfs config replace - < real_config 2> replace_out
|
||||
'
|
||||
|
||||
test_expect_success "output looks good" '
|
||||
echo "Error: setting private key with API is not supported" > replace_expected
|
||||
test_cmp replace_out replace_expected
|
||||
'
|
||||
|
||||
}
|
||||
|
||||
test_init_ipfs
|
||||
|
Reference in New Issue
Block a user