Add sharness test for allowlist
Marco Munizaga committed
Jul 6, 2022 at 14:58 UTC
66b974d1b9069db7fc6a78db3ce66acd35916d85
1 file changed
+50
test/sharness/t0139-swarm-rcmgr.sh
+50
@@ -146,4 +146,54 @@ test_expect_success 'Set limit for peer scope with an invalid peer ID' '
146
147
test_kill_ipfs_daemon
148
149
+## Test allowlist
150
+
151
+test_expect_success 'init iptb' '
152
+ iptb testbed create -type localipfs -count 3 -init
153
+'
154
+
155
+test_expect_success 'peer ids' '
156
+ PEERID_0=$(iptb attr get 0 id) &&
157
+ PEERID_1=$(iptb attr get 1 id) &&
158
+ PEERID_2=$(iptb attr get 2 id)
159
+'
160
+
161
+#enable resource manager
162
+test_expect_success 'enable RCMGR' '
163
+ ipfsi 0 config --bool Swarm.ResourceMgr.Enabled true &&
164
+ ipfsi 0 config --json Swarm.ResourceMgr.Allowlist "[\"/ip4/0.0.0.0/ipcidr/0/p2p/$PEERID_2\"]"
165
+'
166
+
167
+test_expect_success 'start nodes' '
168
+ iptb start -wait [0-2]
169
+'
170
+
171
+test_expect_success "change system limits on node 0" '
172
+ ipfsi 0 swarm limit system | jq ". + {Conns: 0,ConnsInbound: 0, ConnsOutbound: 0}" > system.json &&
173
+ ipfsi 0 swarm limit system system.json
174
+'
175
+
176
+test_expect_success "node 0 fails to connect to 1" '
177
+ test_expect_code 1 iptb connect 0 1
178
+'
179
+
180
+test_expect_success "node 0 connects to 2 because it's allowlisted" '
181
+ iptb connect 0 2
182
+'
183
+
184
+test_expect_success "node 0 fails to ping 1" '
185
+ test_expect_code 1 ipfsi 0 ping -n2 -- "$PEERID_1" 2> actual &&
186
+ test_should_contain "Error: ping failed" actual
187
+'
188
+
189
+test_expect_success "node 1 can ping 2" '
190
+ ipfsi 0 ping -n2 -- "$PEERID_2"
191
+'
192
+
193
+test_expect_success 'stop iptb' '
194
+ iptb stop 0 &&
195
+ iptb stop 1 &&
196
+ iptb stop 2
197
+'
198
+
199
test_done