test-apt-key 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. testfileequal './aptkey.list' "$1"
  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. testsuccessequal '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. testfailure test -e rootdir/etc/apt/trusted.gpg
  33. testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
  34. msgtest 'Check if trusted.gpg is created with permissions set to' '0644'
  35. if [ "$(stat -c '%a' rootdir/etc/apt/trusted.gpg )" = '644' ]; then
  36. msgpass
  37. else
  38. msgfail
  39. fi
  40. testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
  41. pub 2048R/DBAC8DAE 2010-08-18'
  42. msgtest 'Check that Sixpack key can be' 'exported'
  43. aptkey export 'Sixpack' > aptkey.export
  44. aptkey --keyring rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg exportall > aptkey.exportall
  45. testsuccess --nomsg cmp aptkey.export aptkey.exportall
  46. testsuccess test -s aptkey.export
  47. testsuccess test -s aptkey.exportall
  48. msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
  49. testsuccess --nomsg aptkey --fakeroot update
  50. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
  51. msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
  52. testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE
  53. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18'
  54. testsuccess aptkey --fakeroot del DBAC8DAE
  55. testempty aptkey list
  56. msgtest 'Test key removal with' 'single key in real file'
  57. cleanplate
  58. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  59. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  60. testempty aptkey list
  61. testfailure 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' 'long key ID'
  64. cleanplate
  65. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  66. testsuccess --nomsg aptkey --fakeroot del 5A90D141DBAC8DAE
  67. testempty aptkey list
  68. testfailure 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' 'fingerprint'
  71. cleanplate
  72. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  73. testsuccess --nomsg aptkey --fakeroot del 34A8E9D18DB320F367E8EAA05A90D141DBAC8DAE
  74. testempty aptkey list
  75. testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  76. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  77. msgtest 'Test key removal with' 'single key in softlink'
  78. cleanplate
  79. ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  80. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  81. testempty aptkey list
  82. testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  83. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  84. cleanplate
  85. testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
  86. testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
  87. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  88. pub 2048R/528144E2 2011-01-16'
  89. cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
  90. msgtest 'Test key removal with' 'multi key in real file'
  91. cleanplate
  92. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  93. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  94. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  95. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  96. msgtest 'Test key removal with' 'multi key in softlink'
  97. cleanplate
  98. ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  99. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  100. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  101. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  102. testfailure test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  103. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  104. msgtest 'Test key removal with' 'multiple files including key'
  105. cleanplate
  106. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  107. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  108. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  109. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  110. testfailure test -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  111. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  112. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  113. cleanplate
  114. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  115. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  116. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  117. pub 2048R/DBAC8DAE 2010-08-18
  118. pub 2048R/528144E2 2011-01-16'
  119. msgtest 'Test merge-back of' 'added keys'
  120. testsuccess --nomsg aptkey adv --batch --yes --import keys/rexexpired.pub
  121. testaptkeys 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
  122. pub 2048R/DBAC8DAE 2010-08-18
  123. pub 2048R/DBAC8DAE 2010-08-18
  124. pub 2048R/528144E2 2011-01-16'
  125. msgtest 'Test merge-back of' 'removed keys'
  126. testsuccess --nomsg aptkey adv --batch --yes --delete-keys 27CE74F9
  127. testaptkeys 'pub 2048R/DBAC8DAE 2010-08-18
  128. pub 2048R/DBAC8DAE 2010-08-18
  129. pub 2048R/528144E2 2011-01-16'
  130. msgtest 'Test merge-back of' 'removed duplicate keys'
  131. testsuccess --nomsg aptkey adv --batch --yes --delete-keys DBAC8DAE
  132. testaptkeys 'pub 2048R/528144E2 2011-01-16'
  133. }
  134. setupgpgcommand() {
  135. echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
  136. msgtest 'Test that apt-key uses for the following tests command' "$1"
  137. aptkey adv --version >aptkey.version 2>&1
  138. if grep -q "^Executing: $1 --" aptkey.version; then
  139. msgpass
  140. else
  141. cat aptkey.version
  142. msgfail
  143. fi
  144. }
  145. # run with default (whatever this is)
  146. testrun
  147. # run with …
  148. setupgpgcommand 'gpg'
  149. testrun
  150. setupgpgcommand 'gpg2'
  151. testrun