Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for 'ipfs config replace' #3073

Merged
merged 8 commits into from
Oct 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions test/sharness/t0021-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ test_config_cmd() {
grep "\"beep3\": false," actual
'

test_expect_success "setup for config replace test" '
cp "$IPFS_PATH/config" newconfig.json &&
sed -i"~" -e /PrivKey/d -e s/10GB/11GB/ newconfig.json &&
sed -i"~" -e '"'"'/PeerID/ {'"'"' -e '"'"' s/,$// '"'"' -e '"'"' } '"'"' newconfig.json
'

test_expect_success "run 'ipfs config replace'" '
ipfs config replace - < newconfig.json
'

test_expect_success "check resulting config after 'ipfs config replace'" '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whyd you remove this comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nvm, i see that you moved it up

sed -e /PrivKey/d "$IPFS_PATH/config" > replconfig.json &&
sed -i"~" -e '"'"'/PeerID/ {'"'"' -e '"'"' s/,$// '"'"' -e '"'"' } '"'"' replconfig.json &&
test_cmp replconfig.json newconfig.json
'

# SECURITY
# Those tests are here to prevent exposing the PrivKey on the network

test_expect_success "'ipfs config Identity' fails" '
test_expect_code 1 ipfs config Identity 2> ident_out
'
Expand All @@ -81,8 +100,6 @@ test_config_cmd() {
test_cmp ident_exp ident_out
'

# SECURITY
# Those tests are here to prevent exposing the PrivKey on the network
test_expect_success "'ipfs config Identity.PrivKey' fails" '
test_expect_code 1 ipfs config Identity.PrivKey 2> ident_out
'
Expand All @@ -92,7 +109,7 @@ test_config_cmd() {
'

test_expect_success "lower cased PrivKey" '
sed -i -e '\''s/PrivKey/privkey/'\'' "$IPFS_PATH/config" &&
sed -i"~" -e '\''s/PrivKey/privkey/'\'' "$IPFS_PATH/config" &&
test_expect_code 1 ipfs config Identity.privkey 2> ident_out
'

Expand All @@ -101,7 +118,7 @@ test_config_cmd() {
'

test_expect_success "fix it back" '
sed -i -e '\''s/privkey/PrivKey/'\'' "$IPFS_PATH/config"
sed -i"~" -e '\''s/privkey/PrivKey/'\'' "$IPFS_PATH/config"
'

test_expect_success "'ipfs config show' doesn't include privkey" '
Expand All @@ -111,7 +128,7 @@ test_config_cmd() {

test_expect_success "'ipfs config replace' injects privkey back" '
ipfs config replace show_config &&
grep "\"PrivKey\":" "$IPFS_PATH/config" | grep -e ": \".\+\"" >/dev/null
grep "\"PrivKey\":" "$IPFS_PATH/config" | grep -e ": \".\+\"" >/dev/null
'

test_expect_success "'ipfs config replace' with privkey erors out" '
Expand Down