From 6b97588266e53ba63586dba8a6bd7489d654d1fa Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 13 Jul 2016 18:44:17 +0100 Subject: [PATCH] cmd: include case where PrivKey is stored in lower case License: MIT Signed-off-by: Jakub Sztandera --- core/commands/config.go | 5 +++-- test/sharness/t0021-config.sh | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/commands/config.go b/core/commands/config.go index 196463b9c..d09d0fe15 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "os" "os/exec" + "strings" cmds "github.com/ipfs/go-ipfs/commands" repo "github.com/ipfs/go-ipfs/repo" @@ -59,8 +60,8 @@ Set the value of the 'datastore.path' key: key := args[0] // This is a temporary fix until we move the private key out of the config file - switch key { - case "Identity", "Identity.PrivKey": + switch strings.ToLower(key) { + case "identity", "identity.privkey": res.SetError(fmt.Errorf("cannot show or change private key through API"), cmds.ErrNormal) return default: diff --git a/test/sharness/t0021-config.sh b/test/sharness/t0021-config.sh index e3755c1e6..83a776e08 100755 --- a/test/sharness/t0021-config.sh +++ b/test/sharness/t0021-config.sh @@ -87,10 +87,19 @@ test_config_cmd() { test_expect_code 1 ipfs config Identity.PrivKey 2> ident_out ' + test_expect_success "lower cased PrivKey" ' + sed -i -e '\''s/PrivKey/privkey/'\'' "$IPFS_PATH/config" && + test_expect_code 1 ipfs config Identity.privkey 2> ident_out + ' + test_expect_success "output looks good" ' test_cmp ident_exp ident_out ' + test_expect_success "fix it back" ' + sed -i -e '\''s/privkey/PrivKey/'\'' "$IPFS_PATH/config" + ' + test_expect_success "'ipfs config show' doesn't include privkey" ' ipfs config show > show_config && test_expect_code 1 grep PrivKey show_config