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
|
summary: Ensure that the cups interfaces work with app providers
details: |
A snap providing the cups-control and cups interfaces should be able to
create the control socket, with connecting consuming snaps able to use it.
This intentionally does not test the mediation properties of the cupsd
server.
# we run on all systems, since we want the cups snap to work for all systems
# which use snapd, such that any snap desiring to print can declare the cups
# interface and have it auto-connected to the cups snap on all systems for the
# best user experience everywhere
systems:
# TODO: make the snap test-snapd-cups-consumer work well for arm64
# currently producing error: 'nc: unix connect failed: No such file or directory'
- -ubuntu-2*-arm-64
- -ubuntu-core-2*-arm-64
prepare: |
# install the test snaps
# source for this snap:
# https://github.com/anonymouse64/test-snapd-cups-consumer
# needs to be built with snapcraft and hence cannot be snap pack'd here
snap install --edge test-snapd-cups-consumer
# the provider snap needs an assertion in order to have it's slot connected,
# but since this PR has not yet landed, we simply use the store as a way to
# download the built artifact - when this is fully supported in the
# review-tools, etc. then this can install the provider from the store
# directly instead
# source for this snap: https://github.com/anonymouse64/test-snapd-cups-provider
snap download --edge test-snapd-cups-provider --basename=test-snapd-cups-provider
snap install --dangerous test-snapd-cups-provider.snap
if [ -e /run/cups ]; then
mv /run/cups /run/cups.orig
fi
mkdir -m 0755 /run/cups
restore: |
rm -rf /run/cups
if [ -e /run/cups.orig ]; then
mv /run/cups.orig /run/cups
fi
execute: |
echo "The provider can create the socket and any other files"
test-snapd-cups-provider.sh -c "echo slot > /run/cups/cups.sock"
test-snapd-cups-provider.sh -c "echo slot > /run/cups/other"
echo "Check the consumer's interface is not auto-connected"
if [ "$(snap debug confinement)" = "strict" ]; then
echo "When the consumer's interface is not connected we cannot read the sockets"
not test-snapd-cups-consumer.cups-control -c "head /run/cups/cups.sock"
not test-snapd-cups-consumer.cups -c "head /run/cups/cups.sock"
fi
echo "When the cups-control interface is connected"
snap connect test-snapd-cups-consumer:cups-control test-snapd-cups-provider:cups-control
if [ "$(snap debug confinement)" = "strict" ]; then
echo "Then the plug can't access arbitrary files"
not test-snapd-cups-consumer.cups-control -c "head /run/cups/other"
fi
echo "The plug can write to the socket"
test-snapd-cups-consumer.cups-control -c "echo cups-control-plug > /run/cups/cups.sock"
test-snapd-cups-provider.sh -c "cat /run/cups/cups.sock" | MATCH cups-control-plug
echo "The plug can read from the socket"
test-snapd-cups-provider.sh -c "echo slot > /run/cups/cups.sock"
test-snapd-cups-consumer.cups-control -c "cat /run/cups/cups.sock" | MATCH slot
echo "When the cups-control interface is disconnected"
snap disconnect test-snapd-cups-consumer:cups-control
if [ "$(snap debug confinement)" = "strict" ]; then
echo "The plug cannot read from the socket"
not test-snapd-cups-consumer.cups-control -c "head /run/cups/cups.sock"
fi
echo "When the the cups interface is connected"
snap connect test-snapd-cups-consumer:cups test-snapd-cups-provider:cups
if [ "$(snap debug confinement)" = "strict" ]; then
echo "Then the plug can't access arbitrary files"
not test-snapd-cups-consumer.cups -c "head /run/cups/other"
echo "The plug also can't access the host /run cups socket"
not test-snapd-cups-consumer.cups -c "head /run/cups/cups.sock"
fi
echo "The plug can write to the special cups snap specific socket"
#shellcheck disable=SC2016
echo hello | test-snapd-cups-consumer.cups -c 'nc -q 1 -U $CUPS_SERVER' > cups-server-response.txt
echo "And the cups server on the other side of the socket sends a response"
MATCH hello < cups-server-response.txt
echo "The plug has CUPS_SERVER environment variable set automatically"
#shellcheck disable=SC2016
test-snapd-cups-consumer.cups -c 'echo $CUPS_SERVER' | MATCH /var/cups/cups.sock
echo "And the the cups interface can be disconnected again"
snap disconnect test-snapd-cups-consumer:cups
if [ "$(snap debug confinement)" = "strict" ]; then
not test-snapd-cups-consumer.cups -c "head /var/cups/cups.sock"
fi
echo "And the environment variable is not set"
#shellcheck disable=SC2016
test-snapd-cups-consumer.bin -c 'echo $CUPS_SERVER' | NOMATCH /var/cups/cups.sock
|