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
|
summary: Ensure that the network-bind interface works
details: |
The network-bind interface allows an application to accept incoming network
connections.
A snap which defines the network-bind plug must be shown in the interfaces
list. The plug must be auto-connected on install and, as usual, must be able
to be reconnected.
A snap declaring a plug on this interface must be accessible by a network
client.
environment:
SNAP_NAME: network-bind-consumer
PORT: 8081
REQUEST_FILE: ./request.txt
prepare: |
echo "Given a snap declaring the network-bind plug is installed"
"$TESTSTOOLS"/snaps-state install-local "$SNAP_NAME"
echo "Given the snap's service is listening"
# shellcheck source=tests/lib/network.sh
. "$TESTSLIB"/network.sh
wait_listen_port "$PORT"
echo "Given we store a basic HTTP request"
cat > "$REQUEST_FILE" <<EOF
GET / HTTP/1.0
EOF
restore: |
# This snap is removed because it generates thousands of DENIALS in the journal. Most of those
# are sent after the journalctl cursor for following test is determined producing errors while
# preparing the test.
snap remove --purge network-bind-consumer
execute: |
echo "The interface is connected by default"
snap interfaces -i network-bind | MATCH ":network-bind .*$SNAP_NAME"
echo "Then the service is accessible by a client"
nc -w 1 localhost "$PORT" < "$REQUEST_FILE" | grep -Pqz 'ok\n'
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect "$SNAP_NAME:network-bind"
echo "Then the service is not accessible by a client"
response=$(nc -w 1 localhost "$PORT" < "$REQUEST_FILE")
[ "$response" = "" ]
echo "Then the plug can be connected again"
snap connect "$SNAP_NAME:network-bind"
|