"Fossies" - the Fresh Open Source Software Archive

Member "apt-1.9.4/test/integration/test-apt-cli-json-hooks" (19 Sep 2019, 7188 Bytes) of package /linux/misc/apt-1.9.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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