test-policy-pinning 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. buildaptarchive
  8. setupflataptarchive
  9. STATUS=$(readlink -f rootdir/var/lib/dpkg/status)
  10. APTARCHIVE=$(readlink -f aptarchive)
  11. testequalpolicy() {
  12. local SP="$1"
  13. local AP="$2"
  14. shift 2
  15. testsuccessequal "Package files:
  16. $(echo "$SP" | awk '{ printf("%3s\n",$0) }') ${STATUS}
  17. release a=now
  18. $(echo "$AP" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} Packages
  19. release c=
  20. Pinned packages:" aptcache policy "$@"
  21. }
  22. testglobalpolicy() {
  23. aptgetupdate
  24. testequalpolicy 100 500
  25. testequalpolicy 990 500 -t now
  26. sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
  27. aptgetupdate
  28. testequalpolicy 100 1 -o Test=NotAutomatic
  29. testequalpolicy 990 1 -o Test=NotAutomatic -t now
  30. sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
  31. aptgetupdate
  32. testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
  33. testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
  34. sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
  35. aptgetupdate
  36. testequalpolicy 100 500 -o Test=Automatic
  37. testequalpolicy 990 500 -o Test=Automatic -t now
  38. sed -i aptarchive/Release -e '/NotAutomatic: / d' -e '/ButAutomaticUpgrades: / d'
  39. }
  40. msgmsg 'Test with not signed archive'
  41. aptgetupdate() {
  42. rm -rf rootdir/var/lib/apt
  43. testwarning aptget update --allow-insecure-repositories
  44. }
  45. testglobalpolicy
  46. msgmsg 'Test with signed but no key in trusted'
  47. aptgetupdate() {
  48. rm -rf rootdir/var/lib/apt
  49. signreleasefiles 'Marvin Paranoid'
  50. testwarning aptget update --allow-insecure-repositories
  51. }
  52. testglobalpolicy
  53. # much the same tests will be executed below in more detail again for this one
  54. msgmsg 'Test with signed and valid key'
  55. aptgetupdate() {
  56. rm -rf rootdir/var/lib/apt
  57. signreleasefiles 'Joe Sixpack'
  58. testsuccess aptget update
  59. }
  60. testglobalpolicy
  61. msgmsg 'Test with specific packages'
  62. buildsimplenativepackage "coolstuff" "all" "1.0" "stable"
  63. buildsimplenativepackage "coolstuff" "all" "2.0~bpo1" "backports"
  64. setupaptarchive
  65. testequalpolicycoolstuff() {
  66. local INSTALLED="${1:-(none)}"
  67. local CANDIDATE="${2:-(none)}"
  68. local AB="$3"
  69. local AS="$4"
  70. local PB="$5"
  71. local PINVERSION="$6"
  72. if [ -n "$PINVERSION" ]; then
  73. PINVERSION="Package pin: $PINVERSION
  74. "
  75. fi
  76. local IS=""
  77. local IB=""
  78. local SB=""
  79. local SS=""
  80. [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
  81. 100 $STATUS" || IB=" "
  82. [ "$1" = "1.0" ] && IS="***" && SS="
  83. 100 $STATUS" || IS=" "
  84. local BPO1ARCHIVE=""
  85. local BPO2ARCHIVE=""
  86. if [ ! "$7" = "2.0~bpo2" ]; then
  87. BPO1PIN="$AB"
  88. BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main i386 Packages"
  89. else
  90. BPO2ARCHIVE="
  91. 2.0~bpo2 $AB
  92. $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main i386 Packages"
  93. SB="$(echo "$SB" | tail -n 1)"
  94. shift
  95. fi
  96. shift 6
  97. testsuccessequal "coolstuff:
  98. Installed: $INSTALLED
  99. Candidate: $CANDIDATE
  100. ${PINVERSION}Version table:${BPO2ARCHIVE}
  101. $IB 2.0~bpo1 $PB
  102. ${BPO1ARCHIVE}$SB
  103. $IS 1.0 $AS
  104. $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} stable/main i386 Packages$SS" \
  105. aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
  106. }
  107. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 500 ""
  108. testequalpolicycoolstuff "" "1.0" 500 990 500 "" -t stable
  109. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -t backports
  110. echo "Package: *
  111. Pin: release n=backports
  112. Pin-Priority: 200" > rootdir/etc/apt/preferences
  113. testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=GlobalPin
  114. testequalpolicycoolstuff "" "1.0" 200 990 200 "" -o Test=GlobalPin -t stable
  115. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=GlobalPin -t backports
  116. echo "Package: *
  117. Pin: release n=backports
  118. Pin-Priority: 600" > rootdir/etc/apt/preferences
  119. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=GlobalPin
  120. testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=GlobalPin -t stable
  121. echo "Package: coolstuff
  122. Pin: release n=backports
  123. Pin-Priority: 200" > rootdir/etc/apt/preferences
  124. #FIXME: policy can't differentiate between two sources where one has a package specific pin in place
  125. # testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
  126. # testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
  127. testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
  128. echo "Package: coolstuff
  129. Pin: release n=backports
  130. Pin-Priority: 600" > rootdir/etc/apt/preferences
  131. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
  132. testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
  133. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
  134. echo "Package: coolstuff
  135. Pin: release n=backports
  136. Pin-Priority: -1" > rootdir/etc/apt/preferences
  137. # testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
  138. # testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
  139. # testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
  140. rm rootdir/etc/apt/preferences
  141. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  142. signreleasefiles
  143. aptgetupdate
  144. testequalpolicycoolstuff "" "1.0" 1 500 1 "" -o Test=NotAutomatic
  145. testequalpolicycoolstuff "" "1.0" 1 990 1 "" -o Test=NotAutomatic -t stable
  146. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=NotAutomatic -t backports
  147. echo "Package: *
  148. Pin: release n=backports
  149. Pin-Priority: 200" > rootdir/etc/apt/preferences
  150. testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=NotAutomatic
  151. echo "Package: *
  152. Pin: release n=backports
  153. Pin-Priority: 600" > rootdir/etc/apt/preferences
  154. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=NotAutomatic
  155. testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=NotAutomatic -t stable
  156. echo "Package: coolstuff
  157. Pin: release n=backports
  158. Pin-Priority: 200" > rootdir/etc/apt/preferences
  159. testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
  160. echo "Package: coolstuff
  161. Pin: release n=backports
  162. Pin-Priority: 600" > rootdir/etc/apt/preferences
  163. testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
  164. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
  165. testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
  166. rm rootdir/etc/apt/preferences
  167. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  168. signreleasefiles
  169. aptgetupdate
  170. testequalpolicycoolstuff "" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
  171. testequalpolicycoolstuff "" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
  172. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
  173. echo "Package: *
  174. Pin: release n=backports
  175. Pin-Priority: 200" > rootdir/etc/apt/preferences
  176. testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=ButAutomaticUpgrades
  177. echo "Package: *
  178. Pin: release n=backports
  179. Pin-Priority: 600" > rootdir/etc/apt/preferences
  180. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=ButAutomaticUpgrades
  181. testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=ButAutomaticUpgrades -t stable
  182. echo "Package: coolstuff
  183. Pin: release n=backports
  184. Pin-Priority: 200" > rootdir/etc/apt/preferences
  185. testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  186. echo "Package: coolstuff
  187. Pin: release n=backports
  188. Pin-Priority: 600" > rootdir/etc/apt/preferences
  189. testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  190. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
  191. testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
  192. rm rootdir/etc/apt/preferences
  193. testsuccess aptget install coolstuff -y
  194. testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
  195. testsuccess aptget dist-upgrade -y
  196. testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
  197. testequalpolicycoolstuff "1.0" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
  198. testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
  199. testsuccess aptget install coolstuff -t backports -y
  200. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
  201. testsuccess aptget dist-upgrade -y
  202. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
  203. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
  204. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
  205. rm incoming/backports.main.pkglist incoming/backports.main.srclist
  206. buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
  207. setupaptarchive
  208. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  209. signreleasefiles
  210. aptgetupdate
  211. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 100 "" "2.0~bpo2" -o Test=NotAutomatic
  212. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 100 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
  213. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
  214. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  215. signreleasefiles
  216. aptgetupdate
  217. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
  218. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
  219. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports