@cryptotaxi247 / kubo / commits / 417bd243e

test resolve recursion

License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Mar 16, 2019 at 12:42 UTC 417bd243e22c76436d9728acd8f38b8a167ceb0d
1 file changed +57 -44
test/sharness/t0160-resolve.sh
+57 -44
@@ -21,27 +21,26 @@ test_expect_success "resolve: prepare dag" '
21 dag_hash=$(ipfs dag put <<<"{\"i\": {\"j\": {\"k\": \"asdfasdfasdf\"}}}")
22 '
23
24 +test_expect_success "resolve: prepare keys" '
25 + self_hash=$(ipfs id -f="<id>") &&
26 + alt_hash=$(ipfs key gen -t rsa alt)
27 +'
28 +
29 test_resolve_setup_name() {
25 - ref=$1
26 -
27 - test_expect_success "resolve: prepare name" '
28 - id_hash=$(ipfs id -f="<id>") &&
29 - ipfs name publish --allow-offline "$ref" &&
30 - printf "$ref\n" >expected_nameval &&
31 - ipfs name resolve >actual_nameval &&
32 - test_cmp expected_nameval actual_nameval
30 + local key="$1"
31 + local ref="$2"
32 +
33 + test_expect_success "resolve: prepare $key" '
34 + ipfs name publish --key="$key" --allow-offline "$ref"
35 '
36 }
37
38 test_resolve_setup_name_fail() {
37 - ref=$1
38 -
39 - test_expect_failure "resolve: prepare name" '
40 - id_hash=$(ipfs id -f="<id>") &&
41 - ipfs name publish --allow-offline "$ref" &&
42 - printf "$ref" >expected_nameval &&
43 - ipfs name resolve >actual_nameval &&
44 - test_cmp expected_nameval actual_nameval
39 + local key="$1"
40 + local ref="$2"
41 +
42 + test_expect_failure "resolve: prepare $key" '
43 + ipfs name publish --key="$key" --allow-offline "$ref"
44 '
45 }
46
@@ -51,7 +50,7 @@ test_resolve() {
50 extra=$3
51
52 test_expect_success "resolve succeeds: $src" '
54 - ipfs resolve $extra -r "$src" >actual
53 + ipfs resolve $extra "$src" >actual
54 '
55
56 test_expect_success "resolved correctly: $src -> $dst" '
@@ -69,17 +68,31 @@ test_resolve_cmd() {
68 test_resolve "/ipld/$dag_hash/i/j" "/ipld/$dag_hash/i/j"
69 test_resolve "/ipld/$dag_hash/i" "/ipld/$dag_hash/i"
70
72 - test_resolve_setup_name "/ipfs/$a_hash"
73 - test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"
74 - test_resolve "/ipns/$id_hash/b" "/ipfs/$b_hash"
75 - test_resolve "/ipns/$id_hash/b/c" "/ipfs/$c_hash"
71 + test_resolve_setup_name "self" "/ipfs/$a_hash"
72 + test_resolve "/ipns/$self_hash" "/ipfs/$a_hash"
73 + test_resolve "/ipns/$self_hash/b" "/ipfs/$b_hash"
74 + test_resolve "/ipns/$self_hash/b/c" "/ipfs/$c_hash"
75
77 - test_resolve_setup_name "/ipfs/$b_hash"
78 - test_resolve "/ipns/$id_hash" "/ipfs/$b_hash"
79 - test_resolve "/ipns/$id_hash/c" "/ipfs/$c_hash"
76 + test_resolve_setup_name "self" "/ipfs/$b_hash"
77 + test_resolve "/ipns/$self_hash" "/ipfs/$b_hash"
78 + test_resolve "/ipns/$self_hash/c" "/ipfs/$c_hash"
79
81 - test_resolve_setup_name "/ipfs/$c_hash"
82 - test_resolve "/ipns/$id_hash" "/ipfs/$c_hash"
80 + test_resolve_setup_name "self" "/ipfs/$c_hash"
81 + test_resolve "/ipns/$self_hash" "/ipfs/$c_hash"
82 +
83 + # simple recursion succeeds
84 + test_resolve_setup_name "alt" "/ipns/$self_hash"
85 + test_resolve "/ipns/$alt_hash" "/ipfs/$c_hash"
86 +
87 + # partial resolve succeeds
88 + test_resolve "/ipns/$alt_hash" "/ipns/$self_hash" -r=false
89 +
90 + # infinite recursion fails
91 + test_resolve_setup_name "self" "/ipns/$self_hash"
92 + test_expect_success "recursive resolve terminates" '
93 + test_expect_code 1 ipfs resolve /ipns/$self_hash 2>recursion_error &&
94 + grep "recursion limit exceeded" recursion_error
95 + '
96 }
97
98 test_resolve_cmd_b32() {
@@ -92,17 +105,17 @@ test_resolve_cmd_b32() {
105
106 # flags needed passed in path does not contain cid to derive base
107
95 - test_resolve_setup_name "/ipfs/$a_hash_b32"
96 - test_resolve "/ipns/$id_hash" "/ipfs/$a_hash_b32" --cid-base=base32
97 - test_resolve "/ipns/$id_hash/b" "/ipfs/$b_hash_b32" --cid-base=base32
98 - test_resolve "/ipns/$id_hash/b/c" "/ipfs/$c_hash_b32" --cid-base=base32
108 + test_resolve_setup_name "self" "/ipfs/$a_hash_b32"
109 + test_resolve "/ipns/$self_hash" "/ipfs/$a_hash_b32" --cid-base=base32
110 + test_resolve "/ipns/$self_hash/b" "/ipfs/$b_hash_b32" --cid-base=base32
111 + test_resolve "/ipns/$self_hash/b/c" "/ipfs/$c_hash_b32" --cid-base=base32
112
100 - test_resolve_setup_name "/ipfs/$b_hash_b32" --cid-base=base32
101 - test_resolve "/ipns/$id_hash" "/ipfs/$b_hash_b32" --cid-base=base32
102 - test_resolve "/ipns/$id_hash/c" "/ipfs/$c_hash_b32" --cid-base=base32
113 + test_resolve_setup_name "self" "/ipfs/$b_hash_b32" --cid-base=base32
114 + test_resolve "/ipns/$self_hash" "/ipfs/$b_hash_b32" --cid-base=base32
115 + test_resolve "/ipns/$self_hash/c" "/ipfs/$c_hash_b32" --cid-base=base32
116
104 - test_resolve_setup_name "/ipfs/$c_hash_b32"
105 - test_resolve "/ipns/$id_hash" "/ipfs/$c_hash_b32" --cid-base=base32
117 + test_resolve_setup_name "self" "/ipfs/$c_hash_b32"
118 + test_resolve "/ipns/$self_hash" "/ipfs/$c_hash_b32" --cid-base=base32
119 }
120
121
@@ -131,17 +144,17 @@ test_resolve_cmd_fail() {
144 test_resolve "/ipld/$dag_hash/i/j" "/ipld/$dag_hash/i/j"
145 test_resolve "/ipld/$dag_hash/i" "/ipld/$dag_hash/i"
146
134 - test_resolve_setup_name_fail "/ipfs/$a_hash"
135 - test_resolve_fail "/ipns/$id_hash" "/ipfs/$a_hash"
136 - test_resolve_fail "/ipns/$id_hash/b" "/ipfs/$b_hash"
137 - test_resolve_fail "/ipns/$id_hash/b/c" "/ipfs/$c_hash"
147 + test_resolve_setup_name_fail "self" "/ipfs/$a_hash"
148 + test_resolve_fail "/ipns/$self_hash" "/ipfs/$a_hash"
149 + test_resolve_fail "/ipns/$self_hash/b" "/ipfs/$b_hash"
150 + test_resolve_fail "/ipns/$self_hash/b/c" "/ipfs/$c_hash"
151
139 - test_resolve_setup_name_fail "/ipfs/$b_hash"
140 - test_resolve_fail "/ipns/$id_hash" "/ipfs/$b_hash"
141 - test_resolve_fail "/ipns/$id_hash/c" "/ipfs/$c_hash"
152 + test_resolve_setup_name_fail "self" "/ipfs/$b_hash"
153 + test_resolve_fail "/ipns/$self_hash" "/ipfs/$b_hash"
154 + test_resolve_fail "/ipns/$self_hash/c" "/ipfs/$c_hash"
155
143 - test_resolve_setup_name_fail "/ipfs/$c_hash"
144 - test_resolve_fail "/ipns/$id_hash" "/ipfs/$c_hash"
156 + test_resolve_setup_name_fail "self" "/ipfs/$c_hash"
157 + test_resolve_fail "/ipns/$self_hash" "/ipfs/$c_hash"
158 }
159
160 # should work offline