t0060-daemon.sh 4.95 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

rht's avatar
rht committed
11 12 13
gwyport=8080
apiport=5001

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

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

22
# NOTE: this should remove bootstrap peers (needs a flag)
23 24
# TODO(cryptix):
#  - we won't see daemon startup failure because we put the daemon in the background - fix: fork with exit code after api listen
25
#  - also default ports: might clash with local clients. Failure in that case isn't clear as well because pollEndpoint just uses the already running node
26
test_expect_success "ipfs daemon --init launches" '
27
  ipfs daemon --init >actual_daemon 2>daemon_err &
28 29
'

30
# this is like "'ipfs daemon' is ready" in test_launch_ipfs_daemon(), see test-lib.sh
31 32
test_expect_success "initialization ended" '
  IPFS_PID=$! &&
33 34
  pollEndpoint -ep=/version -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
  test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
35 36
'

37 38
# this errors if daemon didnt --init $IPFS_PATH correctly
test_expect_success "'ipfs config Identity.PeerID' works" '
39
  PEERID=$(ipfs config Identity.PeerID)
40 41
'

42 43 44 45
test_expect_success "'ipfs swarm addrs local' works" '
  ipfs swarm addrs local >local_addrs
'

46
test_expect_success "ipfs peer id looks good" '
47
  test_check_peerid "$PEERID"
48 49
'

rht's avatar
rht committed
50 51 52 53 54 55 56 57 58 59
# 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"
'

60 61 62 63 64 65 66 67
# This is like t0020-init.sh "ipfs init output looks good"
#
# Unfortunately the line:
#
#   API server listening on /ip4/127.0.0.1/tcp/5001
#
# sometimes doesn't show up, so we cannot use test_expect_success yet.
#
68
test_expect_success "ipfs daemon output looks good" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
69
  STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
70 71 72 73 74 75
  echo "Initializing daemon..." >expected_daemon &&
  echo "initializing ipfs node at $IPFS_PATH" >>expected_daemon &&
  echo "generating 2048-bit RSA keypair...done" >>expected_daemon &&
  echo "peer identity: $PEERID" >>expected_daemon &&
  echo "to get started, enter:" >>expected_daemon &&
  printf "\\n\\t$STARTFILE\\n\\n" >>expected_daemon &&
76
  sed "s/^/Swarm listening on /" local_addrs >>expected_daemon &&
77 78
  echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected_daemon &&
  echo "Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080" >>expected_daemon &&
rht's avatar
rht committed
79
  echo "Daemon is ready" >>expected_daemon &&
80
  test_cmp expected_daemon actual_daemon
81 82
'

83 84 85
test_expect_success ".ipfs/ has been created" '
  test -d ".ipfs" &&
  test -f ".ipfs/config" &&
rht's avatar
rht committed
86 87 88
  test -d ".ipfs/datastore" &&
  test -d ".ipfs/blocks" ||
  test_fsh ls -al .ipfs
89 90
'

91 92 93 94 95 96 97
# begin same as in t0010

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

test_expect_success "ipfs version output looks good" '
98
	egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
99 100 101 102 103 104 105 106
	test_fsh cat version.txt
'

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

test_expect_success "ipfs help output looks good" '
107 108
	egrep -i "^Usage:" help.txt >/dev/null &&
	egrep "ipfs .* <command>" help.txt >/dev/null ||
109 110 111
	test_fsh cat help.txt
'

Christian Couder's avatar
Christian Couder committed
112 113 114 115
# netcat (nc) is needed for the following test
test_expect_success "nc is available" '
	type nc >/dev/null
'
116

Christian Couder's avatar
Christian Couder committed
117
# check transport is encrypted
rht's avatar
rht committed
118
test_expect_success "transport should be encrypted" '
119
  nc -w 5 localhost 4001 >swarmnc &&
120
  grep -q "AES-256,AES-128" swarmnc &&
Jeromy's avatar
Jeromy committed
121
  test_must_fail grep -q "/multistream/1.0.0" swarmnc ||
122 123 124
	test_fsh cat swarmnc
'

125 126 127 128 129 130 131 132 133 134 135
test_expect_success "output from streaming commands works" '
	test_expect_code 28 curl -m 2 http://localhost:5001/api/v0/stats/bw\?poll=true > statsout
'

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
'

136 137
# end same as in t0010

138 139 140 141 142 143 144 145
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
'

146 147 148
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 &
  pollEndpoint -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
149
  test_kill_repeat_10_sec $! ||
150
  test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
151 152
'

153
test_done