test-apt-key 7.0 KB

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