master
sh 60 lines 2.09 KB
Raw
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="Test git plugin"
8
9 . lib/test-lib.sh
10
11 test_init_ipfs
12
13 # from https://github.com/ipfs/go-ipld-git/blob/master/make-test-repo.sh
14 test_expect_success "prepare test data" '
15 tar xzf ../t0280-plugin-git-data/git.tar.gz
16 '
17
18 test_dag_git() {
19 test_expect_success "add objects via dag put" '
20 find objects -type f -exec ipfs dag put --store-codec=git-raw --input-codec=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes
21 '
22
23 test_expect_success "successfully get added objects" '
24 cat hashes | xargs -I {} ipfs dag get -- {} > /dev/null
25 '
26
27 test_expect_success "dag get works" '
28 echo -n "{\"message\":\"Some version\n\",\"object\":{\"/\":\"baf4bcfeq6c2mspupcvftgevza56h7rmozose6wi\"},\"tag\":\"v1\",\"tagger\":{\"date\":\"1497302532\",\"email\":\"johndoe@example.com\",\"name\":\"John Doe\",\"timezone\":\"+0200\"},\"type\":\"commit\"}" > tag_expected &&
29 ipfs dag get baf4bcfhzi72pcj5cc4ocz7igcduubuu7aa3cddi > tag_actual
30 '
31
32 test_expect_success "outputs look correct" '
33 test_cmp tag_expected tag_actual
34 '
35
36 test_expect_success "path traversals work" '
37 echo -n "{\"date\":\"1497302532\",\"email\":\"johndoe@example.com\",\"name\":\"John Doe\",\"timezone\":\"+0200\"}" > author_expected &&
38 echo -n "{\"/\":{\"bytes\":\"YmxvYiAxMgBIZWxsbyB3b3JsZAo\"}}" > file1_expected &&
39 echo -n "{\"/\":{\"bytes\":\"YmxvYiA3ACcsLnB5Zgo\"}}" > file2_expected &&
40 ipfs dag get baf4bcfhzi72pcj5cc4ocz7igcduubuu7aa3cddi/object/author > author_actual &&
41 ipfs dag get baf4bcfhzi72pcj5cc4ocz7igcduubuu7aa3cddi/object/tree/file/hash > file1_actual &&
42 ipfs dag get baf4bcfhzi72pcj5cc4ocz7igcduubuu7aa3cddi/object/parents/0/tree/dir2/hash/f3/hash > file2_actual
43 '
44
45 test_expect_success "outputs look correct" '
46 test_cmp author_expected author_actual &&
47 test_cmp file1_expected file1_actual &&
48 test_cmp file2_expected file2_actual
49 '
50 }
51
52 # should work offline
53 test_dag_git
54
55 # should work online
56 test_launch_ipfs_daemon
57 test_dag_git
58 test_kill_ipfs_daemon
59
60 test_done