@cryptotaxi247 / kubo / commits / 963499111

Add sharness tests for CID security

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Mar 2, 2018 at 21:46 UTC 9634991112fca3ea365f7b5ac3330db14b28b7e8
1 file changed +61
test/sharness/t0275-cid-security.sh new
+61
@@ -0,0 +1,61 @@
1 +#!/bin/sh
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 murmur3 2>add_out
15 +'
16 +
17 +test_expect_success "error reason is pointed out" '
18 + grep "insecure hash functions not allowed" 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 --mhlen 19 2>block_out
23 +'
24 +
25 +test_expect_success "error reason is pointed out" '
26 + grep "hashes must be at 20 least bytes long" 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 zDvnoLcPKWR 2>ipfs_cat
34 + '
35 +
36 +
37 + test_expect_success "error reason is pointed out" '
38 + grep "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 z2ba5YhCCFNFxLtxMygQwjBjYSD8nUeN 2>ipfs_get
44 +
45 + '
46 +
47 + test_expect_success "error reason is pointed out" '
48 + grep "hashes must be at 20 least bytes long" ipfs_get
49 + '
50 +}
51 +
52 +
53 +# should work offline
54 +test_cat_get
55 +
56 +# should work online
57 +test_launch_ipfs_daemon
58 +test_cat_get
59 +test_kill_ipfs_daemon
60 +
61 +test_done