t0060-daemon.sh 4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/sh
#
# Copyright (c) 2014 Juan Batiz-Benet
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test daemon command"

. lib/test-lib.sh

11 12 13 14
gwyport=8082
apiport=5002
swarmport=4003

15 16
# TODO: randomize ports here once we add --config to ipfs daemon

17
# this needs to be in a different test than "ipfs daemon" below
18
test_expect_success "setup IPFS_PATH" '
Christian Couder's avatar
Christian Couder committed
19 20
  IPFS_PATH="$(pwd)/.ipfs" &&
  export IPFS_PATH
21 22
'

23 24
api_maddr="/ip4/0.0.0.0/tcp/$apiport"
gway_maddr="/ip4/0.0.0.0/tcp/$gwyport"
25 26
test_expect_success 'ipfs init & config' '
  ipfs init &&
27 28
  ipfs config Addresses.Gateway $gway_maddr &&
  ipfs config Addresses.API $api_maddr &&
29 30 31
  ipfs config --json=true Addresses.Swarm "[\"/ip4/0.0.0.0/tcp/4003\"]"
'

Stephen Whitmore's avatar
Stephen Whitmore committed
32
test_launch_ipfs_daemon
33

Stephen Whitmore's avatar
Stephen Whitmore committed
34
# this errors if we didn't --init $IPFS_PATH correctly
35
test_expect_success "'ipfs config Identity.PeerID' works" '
36
  PEERID=$(ipfs config Identity.PeerID)
37 38
'

39 40 41 42
test_expect_success "'ipfs swarm addrs local' works" '
  ipfs swarm addrs local >local_addrs
'

43
test_expect_success "ipfs peer id looks good" '
44
  test_check_peerid "$PEERID"
45 46
'

rht's avatar
rht committed
47 48 49 50 51 52 53 54 55 56
# this is for checking SetAllowedOrigins race condition for the api and gateway
# See https://github.com/ipfs/go-ipfs/pull/1966
test_expect_success "ipfs API works with the correct allowed origin port" '
  curl -s -X GET -H "Origin:http://localhost:$apiport" -I "http://localhost:$apiport/api/v0/version"
'

test_expect_success "ipfs gateway works with the correct allowed origin port" '
  curl -s -X GET -H "Origin:http://localhost:$gwyport" -I "http://localhost:$gwyport/api/v0/version"
'

57
test_expect_success "ipfs daemon output looks good" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
58
  STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
59
  echo "Initializing daemon..." >expected_daemon &&
60
  sed "s/^/Swarm listening on /" local_addrs >>expected_daemon &&
61
  echo "API server listening on '$API_MADDR'" >>expected_daemon &&
62
  echo "Gateway (readonly) server listening on '$GWAY_MADDR'" >>expected_daemon &&
rht's avatar
rht committed
63
  echo "Daemon is ready" >>expected_daemon &&
64
  test_cmp expected_daemon actual_daemon
65 66
'

67 68 69
test_expect_success ".ipfs/ has been created" '
  test -d ".ipfs" &&
  test -f ".ipfs/config" &&
rht's avatar
rht committed
70 71 72
  test -d ".ipfs/datastore" &&
  test -d ".ipfs/blocks" ||
  test_fsh ls -al .ipfs
73 74
'

75 76 77 78 79 80 81
# begin same as in t0010

test_expect_success "ipfs version succeeds" '
	ipfs version >version.txt
'

test_expect_success "ipfs version output looks good" '
82
	egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
83 84 85 86 87 88 89 90
	test_fsh cat version.txt
'

test_expect_success "ipfs help succeeds" '
	ipfs help >help.txt
'

test_expect_success "ipfs help output looks good" '
91 92
	egrep -i "^Usage:" help.txt >/dev/null &&
	egrep "ipfs .* <command>" help.txt >/dev/null ||
93 94 95
	test_fsh cat help.txt
'

Christian Couder's avatar
Christian Couder committed
96 97 98 99
# netcat (nc) is needed for the following test
test_expect_success "nc is available" '
	type nc >/dev/null
'
100

Christian Couder's avatar
Christian Couder committed
101
# check transport is encrypted
rht's avatar
rht committed
102
test_expect_success "transport should be encrypted" '
103
  nc -w 5 localhost '$swarmport' >swarmnc &&
104
  grep -q "AES-256,AES-128" swarmnc &&
Jeromy's avatar
Jeromy committed
105
  test_must_fail grep -q "/multistream/1.0.0" swarmnc ||
106 107 108
	test_fsh cat swarmnc
'

109
test_expect_success "output from streaming commands works" '
110
	test_expect_code 28 curl -m 2 http://localhost:'$apiport'/api/v0/stats/bw\?poll=true > statsout
111 112 113 114 115 116 117 118 119
'

test_expect_success "output looks good" '
	grep TotalIn statsout > /dev/null &&
	grep TotalOut statsout > /dev/null &&
	grep RateIn statsout > /dev/null &&
	grep RateOut statsout >/dev/null
'

120 121
# end same as in t0010

122 123 124 125 126 127 128 129
test_expect_success "daemon is still running" '
  kill -0 $IPFS_PID
'

test_expect_success "'ipfs daemon' can be killed" '
  test_kill_repeat_10_sec $IPFS_PID
'

130 131
test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
  yes | ipfs daemon --init >stdin_daemon_out 2>stdin_daemon_err &
132
  pollEndpoint -host='$API_MADDR' -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
133
  test_kill_repeat_10_sec $! ||
134
  test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
135 136
'

137
test_done