test-apt-key 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 'Check that Sixpack key can be' 'exported'
  33. aptkey export 'Sixpack' > aptkey.export
  34. aptkey --keyring rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg exportall > aptkey.exportall
  35. testsuccess --nomsg cmp aptkey.export aptkey.exportall
  36. testsuccess test -s aptkey.export
  37. testsuccess test -s aptkey.exportall
  38. msgtest 'Execute update again to trigger removal of' 'Rex Expired key'
  39. testsuccess --nomsg aptkey --fakeroot update
  40. aptkey list | grep '^pub' > aptkey.list
  41. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18'
  42. msgtest "Try to remove a key which exists, but isn't in the" 'forced keyring'
  43. testsuccess --nomsg aptkey --fakeroot --keyring rootdir/etc/apt/trusted.gpg del DBAC8DAE
  44. aptkey list | grep '^pub' > aptkey.list
  45. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18'
  46. testsuccess aptkey --fakeroot del DBAC8DAE
  47. testempty aptkey list
  48. msgtest 'Test key removal with' 'single key in real file'
  49. cleanplate
  50. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  51. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  52. testempty aptkey list
  53. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  54. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  55. msgtest 'Test key removal with' 'single key in softlink'
  56. cleanplate
  57. ln -s $(readlink -f ./keys/joesixpack.pub) rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  58. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  59. testempty aptkey list
  60. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  61. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  62. cleanplate
  63. testsuccess aptkey --fakeroot add ./keys/joesixpack.pub
  64. testsuccess aptkey --fakeroot add ./keys/marvinparanoid.pub
  65. aptkey list | grep '^pub' > aptkey.list
  66. testfileequal ./aptkey.list 'pub 2048R/DBAC8DAE 2010-08-18
  67. pub 2048R/528144E2 2011-01-16'
  68. cp -a rootdir/etc/apt/trusted.gpg keys/testcase-multikey.pub # store for reuse
  69. msgtest 'Test key removal with' 'multi key in real file'
  70. cleanplate
  71. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  72. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  73. aptkey list | grep '^pub' > aptkey.list
  74. testfileequal ./aptkey.list 'pub 2048R/528144E2 2011-01-16'
  75. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  76. msgtest 'Test key removal with' 'multi key in softlink'
  77. cleanplate
  78. ln -s $(readlink -f ./keys/testcase-multikey.pub) rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  79. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  80. aptkey list | grep '^pub' > aptkey.list
  81. testfileequal ./aptkey.list 'pub 2048R/528144E2 2011-01-16'
  82. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  83. testsuccess test ! -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  84. testsuccess test -L rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  85. msgtest 'Test key removal with' 'multiple files including key'
  86. cleanplate
  87. cp -a keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  88. cp -a keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg
  89. testsuccess --nomsg aptkey --fakeroot del DBAC8DAE
  90. aptkey list | grep '^pub' > aptkey.list
  91. testfileequal ./aptkey.list 'pub 2048R/528144E2 2011-01-16'
  92. testsuccess test ! -e rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  93. testsuccess cmp keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg~
  94. testsuccess cmp keys/testcase-multikey.pub rootdir/etc/apt/trusted.gpg.d/multikey.gpg~
  95. }
  96. setupgpgcommand() {
  97. echo "APT::Key::GPGCommand \"$1\";" > rootdir/etc/apt/apt.conf.d/00gpgcmd
  98. msgtest 'Test that apt-key uses for the following tests command' "$1"
  99. aptkey adv --version >aptkey.version 2>&1
  100. if grep -q "^Executing: $1 --" aptkey.version; then
  101. msgpass
  102. else
  103. cat aptkey.version
  104. msgfail
  105. fi
  106. }
  107. # run with default (whatever this is)
  108. testrun
  109. # run with …
  110. setupgpgcommand 'gpg'
  111. testrun
  112. setupgpgcommand 'gpg2'
  113. testrun