core/commands/config: error out if config replace contains privkey
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jul 8, 2016 at 16:51 UTC
2b682f95d07a00d54e83fb8dc9c48ff35a3406a8
2 files changed
+15
-1
core/commands/config.go
+4
-1
@@ -273,7 +273,10 @@ func editConfig(filename string) error {
273
func replaceConfig(r repo.Repo, file io.Reader) error {
274
var cfg config.Config
275
if err := json.NewDecoder(file).Decode(&cfg); err != nil {
276
- return errors.New("Failed to decode file as config")
276
+ return errors.New("failed to decode file as config")
277
+ }
278
+ if len(cfg.Identity.PrivKey) != 0 {
279
+ return errors.New("setting private key with API is not supported")
280
}
281
282
keyF, err := getConfig(r, "Identity.PrivKey")
test/sharness/t0021-config.sh
+11
@@ -100,6 +100,17 @@ test_config_cmd() {
100
ipfs config replace show_config &&
101
grep PrivKey "$IPFS_PATH/config" | grep -v ": null" >/dev/null
102
'
103
+
104
+ test_expect_success "'ipfs config replace' with privkey erors out" '
105
+ cp "$IPFS_PATH/config" real_config &&
106
+ test_expect_code 1 ipfs config replace - < real_config 2> replace_out
107
+ '
108
+
109
+ test_expect_success "output looks good" '
110
+ echo "Error: setting private key with API is not supported" > replace_expected
111
+ test_cmp replace_out replace_expected
112
+ '
113
+
114
}
115
116
test_init_ipfs