test-apt-key 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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' 'fingerprint'
  57. cleanplate
  58. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  59. testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
  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' 'single key in softlink'
  64. cleanplate
  65. ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  66. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  67. testempty aptkey list
  68. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  69. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  70. cleanplate
  71. testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
  72. testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
  73. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  74. pub 2048R/528144E2 2011-01-16'
  75. cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
  76. msgtest 'Test key removal with' 'multi key in real file'
  77. cleanplate
  78. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  79. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  80. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  81. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  82. msgtest 'Test key removal with' 'multi key in softlink'
  83. cleanplate
  84. ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  85. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  86. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  87. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  88. testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  89. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  90. msgtest 'Test key removal with' 'multiple files including key'
  91. cleanplate
  92. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  93. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  94. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  95. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  96. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  97. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  98. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  99. cleanplate
  100. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  101. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  102. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  103. pub 2048R/DBAC8DAE 2010-08-18
  104. pub 2048R/528144E2 2011-01-16'
  105. msgtest 'Test merge-back of' 'added keys'
  106. testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub
  107. testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
  108. pub 2048R/DBAC8DAE 2010-08-18
  109. pub 2048R/DBAC8DAE 2010-08-18
  110. pub 2048R/528144E2 2011-01-16'
  111. msgtest 'Test merge-back of' 'removed keys'
  112. testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
  113. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  114. pub 2048R/DBAC8DAE 2010-08-18
  115. pub 2048R/528144E2 2011-01-16'
  116. msgtest 'Test merge-back of' 'removed duplicate keys'
  117. testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
  118. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  119. }
  120. setupgpgcommand() {
  121. echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
  122. msgtest 'Test that apt-key uses for the following tests command' "$1"
  123. aptkey adv --version >aptkey.version 2>&1
  124. if grep -q "^Executing: $1 --" aptkey.version; then
  125. msgpass
  126. else
  127. cat aptkey.version
  128. msgfail
  129. fi
  130. }
  131. # run with default (whatever this is)
  132. testrun
  133. # run with …
  134. setupgpgcommand 'gpg'
  135. testrun
  136. setupgpgcommand 'gpg2'
  137. testrun