| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2017 Jakub Sztandera |
| 4 | # MIT Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Cid Security" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | test_init_ipfs |
| 12 | |
| 13 | test_expect_success "adding using unsafe function fails with error" ' |
| 14 | echo foo | test_must_fail ipfs add --hash shake-128 2>add_out |
| 15 | ' |
| 16 | |
| 17 | test_expect_success "error reason is pointed out" ' |
| 18 | grep "potentially insecure hash functions not allowed" add_out || test_fsh cat add_out |
| 19 | ' |
| 20 | |
| 21 | test_expect_success "adding using too short of a hash function gives out an error" ' |
| 22 | echo foo | test_must_fail ipfs block put -f protobuf --mhlen 19 2>block_out |
| 23 | ' |
| 24 | |
| 25 | test_expect_success "error reason is pointed out" ' |
| 26 | grep "digest too small" block_out |
| 27 | ' |
| 28 | |
| 29 | |
| 30 | test_cat_get() { |
| 31 | |
| 32 | test_expect_success "ipfs cat fails with unsafe hash function" ' |
| 33 | test_must_fail ipfs cat bafksebhh7d53e 2>ipfs_cat |
| 34 | ' |
| 35 | |
| 36 | |
| 37 | test_expect_success "error reason is pointed out" ' |
| 38 | grep "potentially insecure hash functions not allowed" ipfs_cat |
| 39 | ' |
| 40 | |
| 41 | |
| 42 | test_expect_success "ipfs get fails with too short function" ' |
| 43 | test_must_fail ipfs get bafkreez3itiri7ghbbf6lzej7paxyxy2qznpw 2>ipfs_get |
| 44 | |
| 45 | ' |
| 46 | |
| 47 | test_expect_success "error reason is pointed out" ' |
| 48 | grep "digest too small" ipfs_get |
| 49 | ' |
| 50 | } |
| 51 | |
| 52 | |
| 53 | test_gc() { |
| 54 | test_expect_success "injecting insecure block" ' |
| 55 | mkdir -p "$IPFS_PATH/blocks/TS" && |
| 56 | cp -f ../t0275-cid-security-data/EICEM7ITSI.data "$IPFS_PATH/blocks/TS" |
| 57 | ' |
| 58 | |
| 59 | test_expect_success "gc works" 'ipfs repo gc > gc_out' |
| 60 | test_expect_success "gc removed bad block" ' |
| 61 | grep bafksebcgpujze gc_out |
| 62 | ' |
| 63 | } |
| 64 | |
| 65 | |
| 66 | # should work offline |
| 67 | test_cat_get |
| 68 | test_gc |
| 69 | |
| 70 | # should work online |
| 71 | test_launch_ipfs_daemon |
| 72 | test_cat_get |
| 73 | test_gc |
| 74 | |
| 75 | test_expect_success "add block linking to insecure" ' |
| 76 | mkdir -p "$IPFS_PATH/blocks/5X" && |
| 77 | cp -f "../t0275-cid-security-data/CIQG6PGTD2VV34S33BE4MNCQITBRFYUPYQLDXYARR3DQW37MOT7K5XI.data" "$IPFS_PATH/blocks/5X" |
| 78 | ' |
| 79 | |
| 80 | test_expect_success "ipfs cat fails with code 1 and not timeout" ' |
| 81 | test_expect_code 1 go-timeout 1 ipfs cat QmVpsktzNeJdfWEpyeix93QJdQaBSgRNxebSbYSo9SQPGx |
| 82 | ' |
| 83 | |
| 84 | test_kill_ipfs_daemon |
| 85 | |
| 86 | test_done |