You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

210 lines
7.0 KiB

  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture "i386"
  7. DESCR='Some description that has a unusual word xxyyzz and aabbcc and a UPPERCASE'
  8. DESCR2='Some other description with the unusual aabbcc only'
  9. insertpackage 'unstable' 'foo' 'all' '1.0' '' '' "$DESCR
  10. Long description of stuff and such, with lines
  11. .
  12. and paragraphs and everything."
  13. insertpackage 'testing' 'bar' 'i386' '2.0' '' '' "$DESCR2"
  14. setupaptarchive
  15. APTARCHIVE="$(readlink -f ./aptarchive)"
  16. cat >> json-hook.sh << EOF
  17. #!/bin/bash
  18. while true; do
  19. read request <&\$APT_HOOK_SOCKET
  20. read empty <&\$APT_HOOK_SOCKET
  21. if echo "\$request" | grep -q ".hello"; then
  22. echo "HOOK: HELLO"
  23. printf '{"jsonrpc": "2.0", "result": {"version": "0.1"}, "id": 0}\n\n' >&\$APT_HOOK_SOCKET
  24. fi
  25. if echo "\$request" | grep -q ".bye"; then
  26. echo "HOOK: BYE"
  27. exit 0;
  28. fi
  29. echo HOOK: request \$request
  30. echo HOOK: empty \$empty
  31. done
  32. EOF
  33. chmod +x json-hook.sh
  34. HOOK="$(readlink -f ./json-hook.sh)"
  35. # Setup all hooks
  36. cat >> rootdir/etc/apt/apt.conf.d/99-json-hooks << EOF
  37. AptCli::Hooks::Install:: "$HOOK";
  38. AptCli::Hooks::Search:: "$HOOK";
  39. EOF
  40. ############################# Success search #######################
  41. testsuccessequal 'HOOK: HELLO
  42. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  43. HOOK: empty
  44. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.search.pre","params":{"command":"search","search-terms":["foo"],"unknown-packages":[],"packages":[]}}
  45. HOOK: empty
  46. HOOK: BYE
  47. Sorting...
  48. Full Text Search...
  49. foo/unstable 1.0 all
  50. Some description that has a unusual word xxyyzz and aabbcc and a UPPERCASE
  51. HOOK: HELLO
  52. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  53. HOOK: empty
  54. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.search.post","params":{"command":"search","search-terms":["foo"],"unknown-packages":[],"packages":[]}}
  55. HOOK: empty
  56. HOOK: BYE' apt search foo
  57. ############################# Failed search #######################
  58. testsuccessequal 'HOOK: HELLO
  59. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  60. HOOK: empty
  61. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.search.pre","params":{"command":"search","search-terms":["foox"],"unknown-packages":[],"packages":[]}}
  62. HOOK: empty
  63. HOOK: BYE
  64. Sorting...
  65. Full Text Search...
  66. HOOK: HELLO
  67. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  68. HOOK: empty
  69. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.search.fail","params":{"command":"search","search-terms":["foox"],"unknown-packages":[],"packages":[]}}
  70. HOOK: empty
  71. HOOK: BYE' apt search foox
  72. ############################# Failed install #######################
  73. testfailureequal 'Reading package lists...
  74. Building dependency tree...
  75. HOOK: HELLO
  76. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  77. HOOK: empty
  78. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.fail","params":{"command":"install","search-terms":["foxxx"],"unknown-packages":["foxxx"],"packages":[]}}
  79. HOOK: empty
  80. HOOK: BYE
  81. E: Unable to locate package foxxx' apt install foxxx
  82. ############################# Success install #######################
  83. testsuccessequal 'Reading package lists...
  84. Building dependency tree...
  85. HOOK: HELLO
  86. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  87. HOOK: empty
  88. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.pre-prompt","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}}}]}}
  89. HOOK: empty
  90. HOOK: BYE
  91. The following NEW packages will be installed:
  92. foo
  93. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  94. Inst foo (1.0 unstable [all])
  95. Conf foo (1.0 unstable [all])
  96. HOOK: HELLO
  97. HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
  98. HOOK: empty
  99. 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}}}]}}
  100. HOOK: empty
  101. HOOK: BYE' apt install foo -s
  102. ################## Error in hello response #########################
  103. cat > json-hook.sh << EOF
  104. #!/bin/bash
  105. exec 2>/dev/null
  106. trap '' SIGPIPE
  107. while true; do
  108. read request <&\$APT_HOOK_SOCKET
  109. read empty <&\$APT_HOOK_SOCKET
  110. if echo "\$request" | grep -q ".hello"; then
  111. printf '{"jsonrpc": "2.0", "error": {"version": "0.1"}, "id": 0}\n\n' >&\$APT_HOOK_SOCKET
  112. break
  113. fi
  114. done
  115. exit 0
  116. EOF
  117. testfailureequal 'Reading package lists...
  118. Building dependency tree...
  119. E: Hook '$HOOK' reported an error during hello: {"jsonrpc": "2.0", "error": {"version": "0.1"}, "id": 0}
  120. E: Hook '$HOOK' reported an error during hello: {"jsonrpc": "2.0", "error": {"version": "0.1"}, "id": 0}' apt install foo -s
  121. ################## Missing separator line #########################
  122. cat > json-hook.sh << EOF
  123. #!/bin/bash
  124. exec 2>/dev/null
  125. trap '' SIGPIPE
  126. while true; do
  127. read request <&\$APT_HOOK_SOCKET
  128. read empty <&\$APT_HOOK_SOCKET
  129. if echo "\$request" | grep -q ".hello"; then
  130. printf '{"jsonrpc": "2.0", "result": {"version": "0.1"}, "id": 0}\n' >&\$APT_HOOK_SOCKET
  131. break
  132. fi
  133. done
  134. exit 0
  135. EOF
  136. testfailureequal 'Reading package lists...
  137. Building dependency tree...
  138. E: Could not read message separator line after handshake from '$HOOK': end of file
  139. E: Could not read message separator line after handshake from '$HOOK': end of file' apt install foo -s
  140. ################## Wrong separator line #########################
  141. cat > json-hook.sh << EOF
  142. #!/bin/bash
  143. exec 2>/dev/null
  144. trap '' SIGPIPE
  145. while true; do
  146. read request <&\$APT_HOOK_SOCKET
  147. read empty <&\$APT_HOOK_SOCKET
  148. if echo "\$request" | grep -q ".hello"; then
  149. printf '{"jsonrpc": "2.0", "result": {"version": "0.1"}, "id": 0}\nXX' >&\$APT_HOOK_SOCKET
  150. break
  151. fi
  152. done
  153. exit 0
  154. EOF
  155. testfailureequal 'Reading package lists...
  156. Building dependency tree...
  157. E: Expected empty line after handshake from '$HOOK', received XX
  158. E: Expected empty line after handshake from '$HOOK', received XX' apt install foo -s
  159. ##################### Removed hook || true ############################
  160. cat > rootdir/etc/apt/apt.conf.d/99-json-hooks << EOF
  161. AptCli::Hooks::Install:: "true";
  162. AptCli::Hooks::Search:: "true";
  163. EOF
  164. testsuccessequal 'Reading package lists...
  165. Building dependency tree...
  166. The following NEW packages will be installed:
  167. foo
  168. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  169. Inst foo (1.0 unstable [all])
  170. Conf foo (1.0 unstable [all])' apt install foo -s