summaryrefslogtreecommitdiff
path: root/test/integration
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2018-06-27 11:31:21 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2018-07-09 16:05:40 +0200
commit21e7f2c41bf00bbe8285dbddf049b63ed3fe0b14 (patch)
tree4bb3598605a176ace7e590e03cfe618d6d1abefd /test/integration
parentc934279f7a8945d05f383ad67e2c846c4db17791 (diff)
Handle JSON hooks that just close the file/exit and fix some other errors
JSON hooks might disappear and the common idiom to work around hooks disappearing is to check for the hook in the shell snippet that is in the apt.conf file and if it does not exist, do nothing. This caused APT to fail however, expecting it to acknowledge the handshake. Ignoring ECONNRESET on handshakes solves the problem. The error case, and the other error cases also did not stop execution of the hook, causing more errors to pile up. Fix this by directly going to the closing part of the code. LP: #1776218 (cherry picked from commit 1d53cffad22c92645090e0e6ddde31fe4f7c3b05)
Diffstat (limited to 'test/integration')
-rwxr-xr-xtest/integration/test-apt-cli-json-hooks87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/integration/test-apt-cli-json-hooks b/test/integration/test-apt-cli-json-hooks
index 0d2a55fb3..80922e01b 100755
--- a/test/integration/test-apt-cli-json-hooks
+++ b/test/integration/test-apt-cli-json-hooks
@@ -120,3 +120,90 @@ HOOK: empty
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.post","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":1,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"1.0","architecture":"all","pin":500},"install":{"id":1,"version":"1.0","architecture":"all","pin":500}}}]}}
HOOK: empty
HOOK: BYE' apt install foo -s
+
+################## Error in hello response #########################
+
+cat > json-hook.sh << EOF
+#!/bin/bash
+exec 2>/dev/null
+trap '' SIGPIPE
+while true; do
+ read request <&\$APT_HOOK_SOCKET
+ read empty <&\$APT_HOOK_SOCKET
+
+ if echo "\$request" | grep -q ".hello"; then
+ printf '{"jsonrpc": "2.0", "error": {"version": "0.1"}, "id": 0}\n\n' >&\$APT_HOOK_SOCKET
+ break
+ fi
+done
+exit 0
+EOF
+
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+E: Hook '$HOOK' reported an error during hello: {"jsonrpc": "2.0", "error": {"version": "0.1"}, "id": 0}
+E: Hook '$HOOK' reported an error during hello: {"jsonrpc": "2.0", "error": {"version": "0.1"}, "id": 0}' apt install foo -s
+
+################## Missing separator line #########################
+cat > json-hook.sh << EOF
+#!/bin/bash
+exec 2>/dev/null
+trap '' SIGPIPE
+while true; do
+ read request <&\$APT_HOOK_SOCKET
+ read empty <&\$APT_HOOK_SOCKET
+
+ if echo "\$request" | grep -q ".hello"; then
+ printf '{"jsonrpc": "2.0", "result": {"version": "0.1"}, "id": 0}\n' >&\$APT_HOOK_SOCKET
+ break
+ fi
+done
+exit 0
+EOF
+
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+E: Could not read message separator line after handshake from '$HOOK': end of file
+E: Could not read message separator line after handshake from '$HOOK': end of file' apt install foo -s
+
+################## Wrong separator line #########################
+cat > json-hook.sh << EOF
+#!/bin/bash
+exec 2>/dev/null
+trap '' SIGPIPE
+while true; do
+ read request <&\$APT_HOOK_SOCKET
+ read empty <&\$APT_HOOK_SOCKET
+
+ if echo "\$request" | grep -q ".hello"; then
+ printf '{"jsonrpc": "2.0", "result": {"version": "0.1"}, "id": 0}\nXX' >&\$APT_HOOK_SOCKET
+ break
+ fi
+done
+exit 0
+EOF
+
+
+testfailureequal 'Reading package lists...
+Building dependency tree...
+E: Expected empty line after handshake from '$HOOK', received XX
+E: Expected empty line after handshake from '$HOOK', received XX' apt install foo -s
+
+##################### Removed hook || true ############################
+cat > rootdir/etc/apt/apt.conf.d/99-json-hooks << EOF
+ AptCli::Hooks::Install:: "true";
+ AptCli::Hooks::Search:: "true";
+EOF
+
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ foo
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst foo (1.0 unstable [all])
+Conf foo (1.0 unstable [all])' apt install foo -s
+
+
+