test-apt-key 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. echo 'APT::Key::ArchiveKeyring "./keys/joesixpack.pub";
  13. APT::Key::RemovedKeys "./keys/rexexpired.pub";' > rootdir/etc/apt/apt.conf.d/aptkey.conf
  14. testrun() {
  15. cleanplate
  16. ln -sf ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  17. msgtest 'Check that paths in list output are not' 'double-slashed'
  18. aptkey list 2>&1 | grep -q '//' && msgfail || msgpass
  19. msgtest 'Check that paths in finger output are not' 'double-slashed'
  20. aptkey finger 2>&1 | grep -q '//' && msgfail || msgpass
  21. aptkey list | grep '^pub' > aptkey.list
  22. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18'
  23. testequal 'gpg: key DBAC8DAE: "Joe Sixpack (APT Testcases Dummy) <joe@example.org>" not changed
  24. gpg: Total number processed: 1
  25. gpg: unchanged: 1' aptkey --fakeroot update
  26. aptkey list | grep '^pub' > aptkey.list
  27. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18'
  28. testsuccess aptkey --fakeroot add ./keys/rexexpired.pub
  29. aptkey list | grep '^pub' > aptkey.list
  30. testfileequal ./aptkey.list 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]
  31. pub 2048R/DBAC8DAE 2010-08-18'
  32. msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
  33. testsuccess --nomsg aptkey --fakeroot update
  34. aptkey list | grep '^pub' > aptkey.list
  35. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18'
  36. msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
  37. testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE
  38. aptkey list | grep '^pub' > aptkey.list
  39. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18'
  40. testsuccess aptkey --fakeroot del DBAC8DAE
  41. testempty aptkey list
  42. msgtest 'Test key removal with' 'single key in real file'
  43. cleanplate
  44. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  45. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  46. testempty aptkey list
  47. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  48. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  49. msgtest 'Test key removal with' 'single key in softlink'
  50. cleanplate
  51. ln -s $(readlink -f ./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 test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  56. cleanplate
  57. testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
  58. testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
  59. aptkey list | grep '^pub' > aptkey.list
  60. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18
  61. pub 2048R/528144E2 2011-01-16'
  62. cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
  63. msgtest 'Test key removal with' 'multi key in real file'
  64. cleanplate
  65. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  66. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  67. aptkey list | grep '^pub' > aptkey.list
  68. testfileequal ./aptkey.list 'pub 2048R/528144E2 2011-01-16'
  69. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  70. msgtest 'Test key removal with' 'multi key in softlink'
  71. cleanplate
  72. ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  73. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  74. aptkey list | grep '^pub' > aptkey.list
  75. testfileequal ./aptkey.list 'pub 2048R/528144E2 2011-01-16'
  76. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  77. testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  78. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  79. msgtest 'Test key removal with' 'multiple files including key'
  80. cleanplate
  81. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  82. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  83. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  84. aptkey list | grep '^pub' > aptkey.list
  85. testfileequal ./aptkey.list 'pub 2048R/528144E2 2011-01-16'
  86. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  87. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  88. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  89. }
  90. setupgpgcommand() {
  91. echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
  92. msgtest 'Test that apt-key uses for the following tests command' "$1"
  93. aptkey adv --version >aptkey.version 2>&1
  94. if grep -q "^Executing: $1 --" aptkey.version; then
  95. msgpass
  96. else
  97. cat aptkey.version
  98. msgfail
  99. fi
  100. }
  101. # run with default (whatever this is)
  102. testrun
  103. # run with …
  104. setupgpgcommand 'gpg'
  105. testrun
  106. setupgpgcommand 'gpg2'
  107. testrun