From 2b682f95d07a00d54e83fb8dc9c48ff35a3406a8 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Fri, 8 Jul 2016 16:51:35 +0200 Subject: [PATCH] core/commands/config: error out if config replace contains privkey License: MIT Signed-off-by: Jakub Sztandera --- core/commands/config.go | 5 ++++- test/sharness/t0021-config.sh | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/commands/config.go b/core/commands/config.go index 1b93bef6c..64edf1920 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -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") diff --git a/test/sharness/t0021-config.sh b/test/sharness/t0021-config.sh index 407447ed3..b30e17747 100755 --- a/test/sharness/t0021-config.sh +++ b/test/sharness/t0021-config.sh @@ -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