@cryptotaxi247 / kubo / commits / 21c085549

urlstore: test ipfs add --nocopy URL

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

Steven Allen committed Mar 28, 2019 at 19:45 UTC 21c085549ae7fb3a52c88c0d3d32e78513ae0ffb
1 file changed +165 -152
test/sharness/t0272-urlstore.sh
+165 -152
@@ -8,7 +8,6 @@ test_description="Test out the urlstore functionality"
8
9 . lib/test-lib.sh
10
11 -test_init_ipfs
11
12 test_expect_success "create some random files" '
13 random 2222 7 > file1 &&
@@ -16,169 +15,183 @@ test_expect_success "create some random files" '
15 random 50000000 7 > file3
16 '
17
19 -test_expect_success "add files using trickle dag format without raw leaves" '
20 - HASH1a=$(ipfs add -q --trickle --raw-leaves=false file1) &&
21 - HASH2a=$(ipfs add -q --trickle --raw-leaves=false file2) &&
22 - HASH3a=$(ipfs add -q --trickle --raw-leaves=false file3)
23 -'
24 -test_launch_ipfs_daemon --offline
25 -
26 -test_expect_success "make sure files can be retrived via the gateway" '
27 - curl http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a -o file1.actual &&
28 - test_cmp file1 file1.actual &&
29 - curl http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a -o file2.actual &&
30 - test_cmp file2 file2.actual &&
31 - curl http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a -o file3.actual &&
32 - test_cmp file3 file3.actual
33 -'
34 -
35 -test_expect_success "add files without enabling url store" '
36 - test_must_fail ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a &&
37 - test_must_fail ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a
38 -'
39 -
40 -test_kill_ipfs_daemon
41 -
42 -test_expect_success "enable urlstore" '
43 - ipfs config --json Experimental.UrlstoreEnabled true
44 -'
45 -
46 -test_launch_ipfs_daemon --offline
47 -
48 -test_expect_success "add files using gateway address via url store" '
49 - HASH1=$(ipfs urlstore add --pin=false http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
50 - HASH2=$(ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
51 -'
52 -
53 -test_expect_success "make sure hashes are different" '
54 - test $HASH1a != $HASH1 &&
55 - test $HASH2a != $HASH2
56 -'
57 -
58 -test_expect_success "get files via urlstore" '
59 - rm -f file1.actual file2.actual &&
60 - ipfs get $HASH1 -o file1.actual &&
61 - test_cmp file1 file1.actual &&
62 - ipfs get $HASH2 -o file2.actual &&
63 - test_cmp file2 file2.actual
64 -'
65 -
66 -cat <<EOF | sort > ls_expect
18 +test_urlstore() {
19 + ADD_CMD="${@}"
20 +
21 + test_init_ipfs
22 +
23 + test_expect_success "add files using trickle dag format without raw leaves" '
24 + HASH1a=$(ipfs add -q --trickle --raw-leaves=false file1) &&
25 + HASH2a=$(ipfs add -q --trickle --raw-leaves=false file2) &&
26 + HASH3a=$(ipfs add -q --trickle --raw-leaves=false file3)
27 + '
28 +
29 + test_launch_ipfs_daemon --offline
30 +
31 + test_expect_success "make sure files can be retrived via the gateway" '
32 + curl http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a -o file1.actual &&
33 + test_cmp file1 file1.actual &&
34 + curl http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a -o file2.actual &&
35 + test_cmp file2 file2.actual &&
36 + curl http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a -o file3.actual &&
37 + test_cmp file3 file3.actual
38 + '
39 +
40 + test_expect_success "add files without enabling url store using $ADD_CMD" '
41 + test_must_fail ipfs $ADD_CMD http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a &&
42 + test_must_fail ipfs $ADD_CMD http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a
43 + '
44 +
45 + test_kill_ipfs_daemon
46 +
47 + test_expect_success "enable urlstore" '
48 + ipfs config --json Experimental.UrlstoreEnabled true
49 + '
50 +
51 + test_launch_ipfs_daemon --offline
52 +
53 + test_expect_success "add files using gateway address via url store using $ADD_CMD" '
54 + HASH1=$(ipfs $ADD_CMD --pin=false http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
55 + HASH2=$(ipfs $ADD_CMD http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
56 + '
57 +
58 + test_expect_success "make sure hashes are different" '
59 + test $HASH1a != $HASH1 &&
60 + test $HASH2a != $HASH2
61 + '
62 +
63 + test_expect_success "get files via urlstore" '
64 + rm -f file1.actual file2.actual &&
65 + ipfs get $HASH1 -o file1.actual &&
66 + test_cmp file1 file1.actual &&
67 + ipfs get $HASH2 -o file2.actual &&
68 + test_cmp file2 file2.actual
69 + '
70 +
71 + cat <<EOF | sort > ls_expect
72 zb2rhX1q5oFFzEkPNsTe1Y8osUdFqSQGjUWRZsqC9fbY6WVSk 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 0
73 zb2rhYbKFn1UWGHXaAitcdVTkDGTykX8RFpGWzRFuLpoe9VE4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 262144
74 zb2rhjddJ5DNzBrFu8G6CP1ApY25BukwCeskXHzN1H18CiVVZ 2222 http://127.0.0.1:$GWAY_PORT/ipfs/QmcHm3BL2cXuQ6rJdKQgPrmT9suqGkfy2KzH3MkXPEBXU6 0
75 EOF
76
72 -test_expect_success "ipfs filestore ls works with urls" '
73 - ipfs filestore ls | sort > ls_actual &&
74 - test_cmp ls_expect ls_actual
75 -'
77 + test_expect_success "ipfs filestore ls works with urls" '
78 + ipfs filestore ls | sort > ls_actual &&
79 + test_cmp ls_expect ls_actual
80 + '
81
77 -cat <<EOF | sort > verify_expect
82 + cat <<EOF | sort > verify_expect
83 ok zb2rhX1q5oFFzEkPNsTe1Y8osUdFqSQGjUWRZsqC9fbY6WVSk 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 0
84 ok zb2rhYbKFn1UWGHXaAitcdVTkDGTykX8RFpGWzRFuLpoe9VE4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 262144
85 ok zb2rhjddJ5DNzBrFu8G6CP1ApY25BukwCeskXHzN1H18CiVVZ 2222 http://127.0.0.1:$GWAY_PORT/ipfs/QmcHm3BL2cXuQ6rJdKQgPrmT9suqGkfy2KzH3MkXPEBXU6 0
86 EOF
82 -
83 -test_expect_success "ipfs filestore verify works with urls" '
84 - ipfs filestore verify | sort > verify_actual &&
85 - test_cmp verify_expect verify_actual
86 -'
87 -
88 -test_expect_success "garbage collect file1 from the urlstore" '
89 - ipfs repo gc > /dev/null
90 -'
91 -
92 -test_expect_success "can no longer retrieve file1 from urlstore" '
93 - rm -f file1.actual &&
94 - test_must_fail ipfs get $HASH1 -o file1.actual
95 -'
96 -
97 -test_expect_success "can still retrieve file2 from urlstore" '
98 - rm -f file2.actual &&
99 - ipfs get $HASH2 -o file2.actual &&
100 - test_cmp file2 file2.actual
101 -'
102 -
103 -test_expect_success "remove original hashes from local gateway" '
104 - ipfs pin rm $HASH1a $HASH2a &&
105 - ipfs repo gc > /dev/null
106 -'
107 -
108 -test_expect_success "gatway no longer has files" '
109 - test_must_fail curl -f http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a -o file1.actual
110 - test_must_fail curl -f http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a -o file2.actual
111 -'
112 -
113 -cat <<EOF | sort > verify_expect_2
87 +
88 + test_expect_success "ipfs filestore verify works with urls" '
89 + ipfs filestore verify | sort > verify_actual &&
90 + test_cmp verify_expect verify_actual
91 + '
92 +
93 + test_expect_success "garbage collect file1 from the urlstore" '
94 + ipfs repo gc > /dev/null
95 + '
96 +
97 + test_expect_success "can no longer retrieve file1 from urlstore" '
98 + rm -f file1.actual &&
99 + test_must_fail ipfs get $HASH1 -o file1.actual
100 + '
101 +
102 + test_expect_success "can still retrieve file2 from urlstore" '
103 + rm -f file2.actual &&
104 + ipfs get $HASH2 -o file2.actual &&
105 + test_cmp file2 file2.actual
106 + '
107 +
108 + test_expect_success "remove original hashes from local gateway" '
109 + ipfs pin rm $HASH1a $HASH2a &&
110 + ipfs repo gc > /dev/null
111 + '
112 +
113 + test_expect_success "gatway no longer has files" '
114 + test_must_fail curl -f http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a -o file1.actual
115 + test_must_fail curl -f http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a -o file2.actual
116 + '
117 +
118 + cat <<EOF | sort > verify_expect_2
119 error zb2rhX1q5oFFzEkPNsTe1Y8osUdFqSQGjUWRZsqC9fbY6WVSk 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 0
120 error zb2rhYbKFn1UWGHXaAitcdVTkDGTykX8RFpGWzRFuLpoe9VE4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmUow2T4P69nEsqTQDZCt8yg9CPS8GFmpuDAr5YtsPhTdM 262144
121 EOF
117 -
118 -test_expect_success "ipfs filestore verify is correct" '
119 - ipfs filestore verify | sort > verify_actual_2 &&
120 - test_cmp verify_expect_2 verify_actual_2
121 -'
122 -
123 -test_expect_success "files can not be retrieved via the urlstore" '
124 - test_must_fail ipfs cat $HASH1 > /dev/null &&
125 - test_must_fail ipfs cat $HASH2 > /dev/null
126 -'
127 -
128 -test_expect_success "remove broken files" '
129 - ipfs pin rm $HASH2 &&
130 - ipfs repo gc > /dev/null
131 -'
132 -
133 -test_expect_success "add large file using gateway address via url store" '
134 - HASH3=$(ipfs urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a)
135 -'
136 -
137 -test_expect_success "make sure hashes are different" '
138 - test $HASH3a != $HASH3
139 -'
140 -
141 -test_expect_success "get large file via urlstore" '
142 - rm -f file3.actual &&
143 - ipfs get $HASH3 -o file3.actual &&
144 - test_cmp file3 file3.actual
145 -'
146 -
147 -test_expect_success "check that the trickle option works" '
148 - HASHat=$(ipfs add -q --cid-version=1 --raw-leaves=true -n --trickle file3) &&
149 - HASHut=$(ipfs urlstore add --trickle http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a) &&
150 - test $HASHat = $HASHut
151 -'
152 -
153 -test_expect_success "add files using gateway address via url store using --cid-base=base32" '
154 - HASH1a=$(ipfs add -q --trickle --raw-leaves=false file1) &&
155 - HASH2a=$(ipfs add -q --trickle --raw-leaves=false file2) &&
156 - HASH1b32=$(ipfs --cid-base=base32 urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
157 - HASH2b32=$(ipfs --cid-base=base32 urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
158 -'
159 -
160 -test_kill_ipfs_daemon
161 -
162 -test_expect_success "files can not be retrieved via the urlstore" '
163 - test_must_fail ipfs cat $HASH1 > /dev/null &&
164 - test_must_fail ipfs cat $HASH2 > /dev/null &&
165 - test_must_fail ipfs cat $HASH3 > /dev/null
166 -'
167 -
168 -test_expect_success "check that the hashes were correct" '
169 - HASH1e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file1) &&
170 - HASH2e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file2) &&
171 - HASH3e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file3) &&
172 - test $HASH1e = $HASH1 &&
173 - test $HASH2e = $HASH2 &&
174 - test $HASH3e = $HASH3
175 -'
176 -
177 -test_expect_success "check that the base32 hashes were correct" '
178 - HASH1e32=$(ipfs cid base32 $HASH1e)
179 - HASH2e32=$(ipfs cid base32 $HASH2e)
180 - test $HASH1e32 = $HASH1b32 &&
181 - test $HASH2e32 = $HASH2b32
182 -'
122 +
123 + test_expect_success "ipfs filestore verify is correct" '
124 + ipfs filestore verify | sort > verify_actual_2 &&
125 + test_cmp verify_expect_2 verify_actual_2
126 + '
127 +
128 + test_expect_success "files can not be retrieved via the urlstore" '
129 + test_must_fail ipfs cat $HASH1 > /dev/null &&
130 + test_must_fail ipfs cat $HASH2 > /dev/null
131 + '
132 +
133 + test_expect_success "remove broken files" '
134 + ipfs pin rm $HASH2 &&
135 + ipfs repo gc > /dev/null
136 + '
137 +
138 + test_expect_success "add large file using gateway address via url store" '
139 + HASH3=$(ipfs ${ADD_CMD[@]} http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a)
140 + '
141 +
142 + test_expect_success "make sure hashes are different" '
143 + test $HASH3a != $HASH3
144 + '
145 +
146 + test_expect_success "get large file via urlstore" '
147 + rm -f file3.actual &&
148 + ipfs get $HASH3 -o file3.actual &&
149 + test_cmp file3 file3.actual
150 + '
151 +
152 + test_expect_success "check that the trickle option works" '
153 + HASHat=$(ipfs add -q --cid-version=1 --raw-leaves=true -n --trickle file3) &&
154 + HASHut=$(ipfs $ADD_CMD --trickle http://127.0.0.1:$GWAY_PORT/ipfs/$HASH3a) &&
155 + test $HASHat = $HASHut
156 + '
157 +
158 + test_expect_success "add files using gateway address via url store using --cid-base=base32" '
159 + HASH1a=$(ipfs add -q --trickle --raw-leaves=false file1) &&
160 + HASH2a=$(ipfs add -q --trickle --raw-leaves=false file2) &&
161 + HASH1b32=$(ipfs --cid-base=base32 $ADD_CMD http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
162 + HASH2b32=$(ipfs --cid-base=base32 $ADD_CMD http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
163 + '
164 +
165 + test_kill_ipfs_daemon
166 +
167 + test_expect_success "files can not be retrieved via the urlstore" '
168 + test_must_fail ipfs cat $HASH1 > /dev/null &&
169 + test_must_fail ipfs cat $HASH2 > /dev/null &&
170 + test_must_fail ipfs cat $HASH3 > /dev/null
171 + '
172 +
173 + test_expect_success "check that the hashes were correct" '
174 + HASH1e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file1) &&
175 + HASH2e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file2) &&
176 + HASH3e=$(ipfs add -q -n --cid-version=1 --raw-leaves=true file3) &&
177 + test $HASH1e = $HASH1 &&
178 + test $HASH2e = $HASH2 &&
179 + test $HASH3e = $HASH3
180 + '
181 +
182 + test_expect_success "check that the base32 hashes were correct" '
183 + HASH1e32=$(ipfs cid base32 $HASH1e)
184 + HASH2e32=$(ipfs cid base32 $HASH2e)
185 + test $HASH1e32 = $HASH1b32 &&
186 + test $HASH2e32 = $HASH2b32
187 + '
188 +
189 + test_expect_success "ipfs cleanup" '
190 + rm -rf "$IPFS_PATH" && rmdir ipfs ipns mountdir
191 + '
192 +}
193 +
194 +test_urlstore urlstore add
195 +test_urlstore add -q --nocopy --cid-version=1
196
197 test_done