-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy patht0701-delegated-routing-reframe.sh
executable file
·171 lines (147 loc) · 5.12 KB
/
t0701-delegated-routing-reframe.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
test_description="Test delegated routing via reframe endpoint"
. lib/test-lib.sh
if ! test_have_prereq SOCAT; then
skip_all="skipping '$test_description': socat is not available"
test_done
fi
# simple reframe server mock
# local endpoint responds with deterministic application/vnd.ipfs.rpc+dag-json; version=1
REFRAME_PORT=5098
function start_reframe_mock_endpoint() {
REMOTE_SERVER_LOG="reframe-server.log"
rm -f $REMOTE_SERVER_LOG
touch response
socat tcp-listen:$REFRAME_PORT,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat response'!!CREATE:$REMOTE_SERVER_LOG &
REMOTE_SERVER_PID=$!
socat /dev/null tcp:127.0.0.1:$REFRAME_PORT,retry=10
return $?
}
function serve_reframe_response() {
local body=$1
local status_code=${2:-"200 OK"}
local length=$((1 + ${#body}))
echo -e "HTTP/1.1 $status_code\nContent-Type: application/vnd.ipfs.rpc+dag-json; version=1\nContent-Length: $length\n\n$body" > response
}
function stop_reframe_mock_endpoint() {
exec 7<&-
kill $REMOTE_SERVER_PID > /dev/null 2>&1
wait $REMOTE_SERVER_PID || true
}
# daemon running in online mode to ensure Pin.origins/PinStatus.delegates work
test_init_ipfs
# based on static, synthetic reframe messages:
# t0701-delegated-routing-reframe/FindProvidersRequest
# t0701-delegated-routing-reframe/FindProvidersResponse
FINDPROV_CID="bafybeigvgzoolc3drupxhlevdp2ugqcrbcsqfmcek2zxiw5wctk3xjpjwy"
EXPECTED_PROV="QmQzqxhK82kAmKvARFZSkUVS6fo9sySaiogAnx5EnZ6ZmC"
test_expect_success "default Routing config has no Routers defined" '
echo null > expected &&
ipfs config show | jq .Routing.Routers > actual &&
test_cmp expected actual
'
# turn off all implicit routers
ipfs config Routing.Type none || exit 1
test_launch_ipfs_daemon
test_expect_success "disabling default router (dht) works" '
ipfs config Routing.Type > actual &&
echo none > expected &&
test_cmp expected actual
'
test_expect_success "no routers means findprovs returns no results" '
ipfs routing findprovs "$FINDPROV_CID" > actual &&
echo -n > expected &&
test_cmp expected actual
'
test_kill_ipfs_daemon
ipfs config Routing.Type --json '"custom"' || exit 1
ipfs config Routing.Methods --json '{
"find-peers": {
"RouterName": "TestDelegatedRouter"
},
"find-providers": {
"RouterName": "TestDelegatedRouter"
},
"get-ipns": {
"RouterName": "TestDelegatedRouter"
},
"provide": {
"RouterName": "TestDelegatedRouter"
}
}' || exit 1
test_expect_success "missing method params makes daemon fails" '
echo "Error: constructing the node (see log for full detail): method name \"put-ipns\" is missing from Routing.Methods config param" > expected_error &&
GOLOG_LOG_LEVEL=fatal ipfs daemon 2> actual_error || exit 0 &&
test_cmp expected_error actual_error
'
ipfs config Routing.Methods --json '{
"find-peers": {
"RouterName": "TestDelegatedRouter"
},
"find-providers": {
"RouterName": "TestDelegatedRouter"
},
"get-ipns": {
"RouterName": "TestDelegatedRouter"
},
"provide": {
"RouterName": "TestDelegatedRouter"
},
"put-ipns": {
"RouterName": "TestDelegatedRouter"
},
"NOT_SUPPORTED": {
"RouterName": "TestDelegatedRouter"
}
}' || exit 1
test_expect_success "having wrong methods makes daemon fails" '
echo "Error: constructing the node (see log for full detail): method name \"NOT_SUPPORTED\" is not a supported method on Routing.Methods config param" > expected_error &&
GOLOG_LOG_LEVEL=fatal ipfs daemon 2> actual_error || exit 0 &&
test_cmp expected_error actual_error
'
# set Routing config to only use delegated routing via mocked reframe endpoint
ipfs config Routing.Type --json '"custom"' || exit 1
ipfs config Routing.Routers.TestDelegatedRouter --json '{
"Type": "reframe",
"Parameters": {
"Endpoint": "http://127.0.0.1:5098/reframe"
}
}' || exit 1
ipfs config Routing.Methods --json '{
"find-peers": {
"RouterName": "TestDelegatedRouter"
},
"find-providers": {
"RouterName": "TestDelegatedRouter"
},
"get-ipns": {
"RouterName": "TestDelegatedRouter"
},
"provide": {
"RouterName": "TestDelegatedRouter"
},
"put-ipns": {
"RouterName": "TestDelegatedRouter"
}
}' || exit 1
test_expect_success "adding reframe endpoint to Routing.Routers config works" '
echo "http://127.0.0.1:5098/reframe" > expected &&
ipfs config Routing.Routers.TestDelegatedRouter.Parameters.Endpoint > actual &&
test_cmp expected actual
'
test_launch_ipfs_daemon
test_expect_success "start_reframe_mock_endpoint" '
start_reframe_mock_endpoint
'
test_expect_success "'ipfs routing findprovs' returns result from delegated reframe router" '
serve_reframe_response "$(<../t0701-delegated-routing-reframe/FindProvidersResponse)" &&
echo "$EXPECTED_PROV" > expected &&
ipfs routing findprovs "$FINDPROV_CID" > actual &&
test_cmp expected actual
'
test_expect_success "stop_reframe_mock_endpoint" '
stop_reframe_mock_endpoint
'
test_kill_ipfs_daemon
test_done
# vim: ts=2 sw=2 sts=2 et: