test-apt-key 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. # start from a clean plate again
  8. cleanplate() {
  9. rm -rf rootdir/etc/apt/trusted.gpg.d/ rootdir/etc/apt/trusted.gpg
  10. mkdir rootdir/etc/apt/trusted.gpg.d/
  11. }
  12. testaptkeys() {
  13. if ! aptkey list | grep '^pub' > aptkey.list; then
  14. echo -n > aptkey.list
  15. fi
  16. testequal "$1" cat ./aptkey.list
  17. }
  18. echo 'APT::Key::ArchiveKeyring "./keys/joesixpack.pub";
  19. APT::Key::RemovedKeys "./keys/rexexpired.pub";' > rootdir/etc/apt/apt.conf.d/aptkey.conf
  20. testrun() {
  21. cleanplate
  22. ln -sf ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  23. msgtest 'Check that paths in list output are not' 'double-slashed'
  24. aptkey list 2>&1 | grep -q '//' && msgfail || msgpass
  25. msgtest 'Check that paths in finger output are not' 'double-slashed'
  26. aptkey finger 2>&1 | grep -q '//' && msgfail || msgpass
  27. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
  28. testequal 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
  29. gpg: Total number processed: 1
  30. gpg: unchanged: 1' aptkey --fakeroot update
  31. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
  32. testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
  33. testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
  34. pub 2048R/DBAC8DAE 2010-08-18'
  35. msgtest 'Check that Sixpack key can be' 'exported'
  36. aptkey export 'Sixpack' > aptkey.export
  37. aptkey --keyring rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg exportall > aptkey.exportall
  38. testsuccess --nomsg cmp aptkey.export aptkey.exportall
  39. testsuccess test -s aptkey.export
  40. testsuccess test -s aptkey.exportall
  41. msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
  42. testsuccess --nomsg aptkey --fakeroot update
  43. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
  44. msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
  45. testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE
  46. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
  47. testsuccess aptkey --fakeroot del DBAC8DAE
  48. testempty aptkey list
  49. msgtest 'Test key removal with' 'single key in real file'
  50. cleanplate
  51. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  52. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  53. testempty aptkey list
  54. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  55. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  56. msgtest 'Test key removal with' 'long key ID'
  57. cleanplate
  58. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  59. testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
  60. testempty aptkey list
  61. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  62. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  63. msgtest 'Test key removal with' 'fingerprint'
  64. cleanplate
  65. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  66. testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
  67. testempty aptkey list
  68. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  69. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  70. msgtest 'Test key removal with' 'single key in softlink'
  71. cleanplate
  72. ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  73. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  74. testempty aptkey list
  75. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  76. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  77. cleanplate
  78. testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
  79. testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
  80. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  81. pub 2048R/528144E2 2011-01-16'
  82. cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
  83. msgtest 'Test key removal with' 'multi key in real file'
  84. cleanplate
  85. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  86. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  87. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  88. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  89. msgtest 'Test key removal with' 'multi key in softlink'
  90. cleanplate
  91. ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  92. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  93. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  94. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  95. testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  96. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  97. msgtest 'Test key removal with' 'multiple files including key'
  98. cleanplate
  99. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  100. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  101. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  102. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  103. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  104. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  105. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  106. cleanplate
  107. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  108. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  109. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  110. pub 2048R/DBAC8DAE 2010-08-18
  111. pub 2048R/528144E2 2011-01-16'
  112. msgtest 'Test merge-back of' 'added keys'
  113. testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub
  114. testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
  115. pub 2048R/DBAC8DAE 2010-08-18
  116. pub 2048R/DBAC8DAE 2010-08-18
  117. pub 2048R/528144E2 2011-01-16'
  118. msgtest 'Test merge-back of' 'removed keys'
  119. testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
  120. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  121. pub 2048R/DBAC8DAE 2010-08-18
  122. pub 2048R/528144E2 2011-01-16'
  123. msgtest 'Test merge-back of' 'removed duplicate keys'
  124. testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
  125. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  126. }
  127. setupgpgcommand() {
  128. echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
  129. msgtest 'Test that apt-key uses for the following tests command' "$1"
  130. aptkey adv --version >aptkey.version 2>&1
  131. if grep -q "^Executing: $1 --" aptkey.version; then
  132. msgpass
  133. else
  134. cat aptkey.version
  135. msgfail
  136. fi
  137. }
  138. # run with default (whatever this is)
  139. testrun
  140. # run with …
  141. setupgpgcommand 'gpg'
  142. testrun
  143. setupgpgcommand 'gpg2'
  144. testrun