| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2017 Jeromy Johnson |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test out the urlstore functionality" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | |
| 12 | test_expect_success "create some random files" ' |
| 13 | random-data -size=2222 -seed=7 > file1 && |
| 14 | random-data -size=500000 -seed=7 > file2 && |
| 15 | random-data -size=50000000 -seed=7 > file3 |
| 16 | ' |
| 17 | |
| 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_without_network |
| 30 | |
| 31 | test_expect_success "make sure files can be retrieved 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_without_network |
| 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 | bafkreiconmdoujderxi757nf4wjpo4ukbhlo6mmxs6pg3yl53ln3ykldvi 2222 http://127.0.0.1:$GWAY_PORT/ipfs/QmUNEBSK2uPLSZU3Dj6XbSHjdGze4huWxESx2R4Ef1cKRW 0 |
| 73 | bafkreifybqsfcheqkxzlhuuvoi3u6wz42kic4yqohvkia2i5fg3mpkqt3i 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmTgZc5bhTHUcqGN8rRP9oTJBv1UeJVWufPMPiUfbP9Ghs 0 |
| 74 | bafkreigxuuyoickqhwxu4kjckmgfqb7ygd426qiakryvvstixy523imym4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmTgZc5bhTHUcqGN8rRP9oTJBv1UeJVWufPMPiUfbP9Ghs 262144 |
| 75 | EOF |
| 76 | |
| 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 | |
| 82 | cat <<EOF | sort > verify_expect |
| 83 | ok bafkreifybqsfcheqkxzlhuuvoi3u6wz42kic4yqohvkia2i5fg3mpkqt3i 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmTgZc5bhTHUcqGN8rRP9oTJBv1UeJVWufPMPiUfbP9Ghs 0 |
| 84 | ok bafkreigxuuyoickqhwxu4kjckmgfqb7ygd426qiakryvvstixy523imym4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmTgZc5bhTHUcqGN8rRP9oTJBv1UeJVWufPMPiUfbP9Ghs 262144 |
| 85 | ok bafkreiconmdoujderxi757nf4wjpo4ukbhlo6mmxs6pg3yl53ln3ykldvi 2222 http://127.0.0.1:$GWAY_PORT/ipfs/QmUNEBSK2uPLSZU3Dj6XbSHjdGze4huWxESx2R4Ef1cKRW 0 |
| 86 | EOF |
| 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 "gateway 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 bafkreifybqsfcheqkxzlhuuvoi3u6wz42kic4yqohvkia2i5fg3mpkqt3i 262144 http://127.0.0.1:$GWAY_PORT/ipfs/QmTgZc5bhTHUcqGN8rRP9oTJBv1UeJVWufPMPiUfbP9Ghs 0 |
| 120 | error bafkreigxuuyoickqhwxu4kjckmgfqb7ygd426qiakryvvstixy523imym4 237856 http://127.0.0.1:$GWAY_PORT/ipfs/QmTgZc5bhTHUcqGN8rRP9oTJBv1UeJVWufPMPiUfbP9Ghs 262144 |
| 121 | EOF |
| 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 cannot 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 cannot 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 add -q --nocopy --cid-version=1 |
| 195 | |
| 196 | test_done |