master
sh 211 lines 6.6 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2014 Juan Batiz-Benet
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test daemon command"
8
9 . lib/test-lib.sh
10
11 test_expect_success "create pebble config" '
12 ipfs init --profile=pebbleds,test > /dev/null &&
13 cp "$IPFS_PATH/config" init-config
14 '
15
16 test_expect_success "cleanup repo" '
17 rm -rf "$IPFS_PATH"
18 '
19
20 test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile=test
21 test_kill_ipfs_daemon
22
23 test_expect_success "daemon initialization with existing config works" '
24 ipfs config "Datastore.Spec.path" >actual &&
25 test $(cat actual) = "pebbleds" &&
26 ipfs config Addresses > orig_addrs
27 '
28
29 test_expect_success "cleanup repo" '
30 rm -rf "$IPFS_PATH"
31 '
32
33 test_launch_ipfs_daemon --init --init-config="$(pwd)/init-config" --init-profile=test,randomports
34 test_kill_ipfs_daemon
35
36 test_expect_success "daemon initialization with existing config + profiles works" '
37 ipfs config Addresses >new_addrs &&
38 test_expect_code 1 diff -q new_addrs orig_addrs
39 '
40
41 test_expect_success "cleanup repo" '
42 rm -rf "$IPFS_PATH"
43 '
44
45 test_init_ipfs
46 test_expect_success "set Resource Manager variables showed at startup" '
47 ipfs config --json Swarm.ResourceMgr.MaxFileDescriptors 1024 &&
48 ipfs config Swarm.ResourceMgr.MaxMemory 4GB
49 '
50 test_launch_ipfs_daemon
51
52 # this errors if we didn't --init $IPFS_PATH correctly
53 test_expect_success "'ipfs config Identity.PeerID' works" '
54 PEERID=$(ipfs config Identity.PeerID)
55 '
56
57 test_expect_success "'ipfs swarm addrs local' works" '
58 ipfs swarm addrs local >local_addrs
59 '
60
61 test_expect_success "ipfs swarm addrs listen; works" '
62 ipfs swarm addrs listen >listen_addrs
63 '
64
65 test_expect_success "ipfs peer id looks good" '
66 test_check_peerid "$PEERID"
67 '
68
69 # this is for checking SetAllowedOrigins race condition for the api and gateway
70 # See https://github.com/ipfs/go-ipfs/pull/1966
71 test_expect_success "ipfs API works with the correct allowed origin port" '
72 curl -s -X POST -H "Origin:http://localhost:$API_PORT" -I "http://$API_ADDR/api/v0/version"
73 '
74
75 test_expect_success "ipfs gateway works with the correct allowed origin port" '
76 curl -s -X POST -H "Origin:http://localhost:$GWAY_PORT" -I "http://$GWAY_ADDR/api/v0/version"
77 '
78
79 test_expect_success "ipfs daemon output includes looks good" '
80 test_should_contain "Initializing daemon..." actual_daemon &&
81 test_should_contain "$(ipfs version --all)" actual_daemon &&
82 test_should_contain "PeerID: $(ipfs config Identity.PeerID)" actual_daemon &&
83 test_should_contain "Swarm listening on 127.0.0.1:" actual_daemon &&
84 test_should_contain "RPC API server listening on '$API_MADDR'" actual_daemon &&
85 test_should_contain "WebUI: http://'$API_ADDR'/webui" actual_daemon &&
86 test_should_contain "Gateway server listening on '$GWAY_MADDR'" actual_daemon &&
87 test_should_contain "Daemon is ready" actual_daemon &&
88 cat actual_daemon
89 '
90
91 test_expect_success ".ipfs/ has been created" '
92 test -d ".ipfs" &&
93 test -f ".ipfs/config" &&
94 test -d ".ipfs/datastore" &&
95 test -d ".ipfs/blocks" ||
96 test_fsh ls -al .ipfs
97 '
98
99 # begin same as in t0010
100
101 test_expect_success "ipfs version succeeds" '
102 ipfs version >version.txt
103 '
104
105 test_expect_success "ipfs version output looks good" '
106 egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
107 test_fsh cat version.txt
108 '
109
110 test_expect_success "ipfs version deps succeeds" '
111 ipfs version deps >deps.txt
112 '
113
114 test_expect_success "ipfs version deps output looks good ( set \$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK to skip this test )" '
115 head -1 deps.txt | grep "go-ipfs@(devel)" &&
116 [[ "$GOIPFSTEST_SKIP_LOCAL_DEVTREE_DEPS_CHECK" == "1" ]] ||
117 [[ $(tail -n +2 deps.txt | egrep -v -c "^[^ @]+@v[^ @]+( => [^ @]+@v[^ @]+)?$") -eq 0 ]] ||
118 test_fsh cat deps.txt
119 '
120
121 test_expect_success "ipfs help succeeds" '
122 ipfs help >help.txt
123 '
124
125 test_expect_success "ipfs help output looks good" '
126 egrep -i "^Usage" help.txt >/dev/null &&
127 egrep "ipfs .* <command>" help.txt >/dev/null ||
128 test_fsh cat help.txt
129 '
130
131 # check transport is encrypted by default and no plaintext is allowed
132
133 test_expect_success SOCAT "default transport should support encryption (TLS, needs socat )" '
134 socat -s - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-tls &&
135 grep -q "/tls" swarmnc &&
136 test_must_fail grep -q "na" swarmnc ||
137 test_fsh cat swarmnc
138 '
139
140 test_expect_success SOCAT "default transport should support encryption (Noise, needs socat )" '
141 socat -s - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-noise &&
142 grep -q "/noise" swarmnc &&
143 test_must_fail grep -q "na" swarmnc ||
144 test_fsh cat swarmnc
145 '
146
147 test_expect_success SOCAT "default transport should not support plaintext (needs socat )" '
148 socat -s - tcp:localhost:$SWARM_PORT,connect-timeout=1 > swarmnc < ../t0060-data/mss-plaintext &&
149 grep -q "na" swarmnc &&
150 test_must_fail grep -q "/plaintext" swarmnc ||
151 test_fsh cat swarmnc
152 '
153
154 test_expect_success "output from streaming commands works" '
155 test_expect_code 28 curl -X POST -m 5 http://localhost:$API_PORT/api/v0/stats/bw\?poll=true > statsout
156 '
157
158 test_expect_success "output looks good" '
159 grep TotalIn statsout > /dev/null &&
160 grep TotalOut statsout > /dev/null &&
161 grep RateIn statsout > /dev/null &&
162 grep RateOut statsout >/dev/null
163 '
164
165 # end same as in t0010
166
167 test_expect_success "daemon is still running" '
168 kill -0 $IPFS_PID
169 '
170
171 test_expect_success "'ipfs daemon' can be killed" '
172 test_kill_repeat_10_sec $IPFS_PID
173 '
174
175 test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
176 yes | ipfs daemon >stdin_daemon_out 2>stdin_daemon_err &
177 DAEMON_PID=$!
178 test_wait_for_file 20 100ms "$IPFS_PATH/api" &&
179 test_set_address_vars stdin_daemon_out
180 '
181
182 test_expect_success "daemon with pipe eventually becomes live" '
183 pollEndpoint -host='$API_MADDR' -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
184 test_kill_repeat_10_sec $DAEMON_PID ||
185 test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
186 '
187
188 test_expect_success "'ipfs daemon' cleans up when it fails to start" '
189 test_must_fail ipfs daemon --routing=foobar &&
190 test ! -e "$IPFS_PATH/repo.lock"
191 '
192
193 ulimit -S -n 512
194 TEST_ULIMIT_PRESET=1
195 test_launch_ipfs_daemon
196
197 test_expect_success "daemon raised its fd limit" '
198 test_should_not_contain "setting file descriptor limit" actual_daemon
199 '
200
201 test_expect_success "daemon actually can handle 2048 file descriptors" '
202 hang-fds -hold=2s 2000 '$API_MADDR' > /dev/null
203 '
204
205 test_expect_success "daemon didn't throw any errors" '
206 test_expect_code 1 grep "too many open files" daemon_err
207 '
208
209 test_kill_ipfs_daemon
210
211 test_done