Skip to content

Commit 5c212d3

Browse files
Merge pull request #3073 from ipfs/feat/test-config-replace
Add test for 'ipfs config replace'
2 parents c7a851b + 80a7762 commit 5c212d3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

test/sharness/t0021-config.sh

+21-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ test_config_cmd() {
7272
grep "\"beep3\": false," actual
7373
'
7474

75+
test_expect_success "setup for config replace test" '
76+
cp "$IPFS_PATH/config" newconfig.json &&
77+
sed -i"~" -e /PrivKey/d -e s/10GB/11GB/ newconfig.json &&
78+
sed -i"~" -e '"'"'/PeerID/ {'"'"' -e '"'"' s/,$// '"'"' -e '"'"' } '"'"' newconfig.json
79+
'
80+
81+
test_expect_success "run 'ipfs config replace'" '
82+
ipfs config replace - < newconfig.json
83+
'
84+
85+
test_expect_success "check resulting config after 'ipfs config replace'" '
86+
sed -e /PrivKey/d "$IPFS_PATH/config" > replconfig.json &&
87+
sed -i"~" -e '"'"'/PeerID/ {'"'"' -e '"'"' s/,$// '"'"' -e '"'"' } '"'"' replconfig.json &&
88+
test_cmp replconfig.json newconfig.json
89+
'
90+
91+
# SECURITY
92+
# Those tests are here to prevent exposing the PrivKey on the network
93+
7594
test_expect_success "'ipfs config Identity' fails" '
7695
test_expect_code 1 ipfs config Identity 2> ident_out
7796
'
@@ -81,8 +100,6 @@ test_config_cmd() {
81100
test_cmp ident_exp ident_out
82101
'
83102

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

94111
test_expect_success "lower cased PrivKey" '
95-
sed -i -e '\''s/PrivKey/privkey/'\'' "$IPFS_PATH/config" &&
112+
sed -i"~" -e '\''s/PrivKey/privkey/'\'' "$IPFS_PATH/config" &&
96113
test_expect_code 1 ipfs config Identity.privkey 2> ident_out
97114
'
98115

@@ -101,7 +118,7 @@ test_config_cmd() {
101118
'
102119

103120
test_expect_success "fix it back" '
104-
sed -i -e '\''s/privkey/PrivKey/'\'' "$IPFS_PATH/config"
121+
sed -i"~" -e '\''s/privkey/PrivKey/'\'' "$IPFS_PATH/config"
105122
'
106123

107124
test_expect_success "'ipfs config show' doesn't include privkey" '

0 commit comments

Comments
 (0)