test-policy-pinning 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. testequal "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. aptgetupdate() {
  23. # just to be sure that no old files are used
  24. rm -rf rootdir/var/lib/apt
  25. if aptget update -qq 2>&1 | grep '^E: '; then
  26. msgwarn 'apt-get update failed with an error'
  27. fi
  28. }
  29. ### not signed archive
  30. aptgetupdate
  31. testequalpolicy 100 500
  32. testequalpolicy 990 500 -t now
  33. sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
  34. aptgetupdate
  35. testequalpolicy 100 1 -o Test=NotAutomatic
  36. testequalpolicy 990 1 -o Test=NotAutomatic -t now
  37. sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
  38. aptgetupdate
  39. testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
  40. testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
  41. sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
  42. aptgetupdate
  43. testequalpolicy 100 500 -o Test=Automatic
  44. testequalpolicy 990 500 -o Test=Automatic -t now
  45. sed -i aptarchive/Release -e '/NotAutomatic: / d' -e '/ButAutomaticUpgrades: / d'
  46. ### signed but no key in trusted
  47. signreleasefiles 'Marvin Paranoid'
  48. aptgetupdate
  49. testequalpolicy 100 500
  50. testequalpolicy 990 500 -t now
  51. sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
  52. signreleasefiles 'Marvin Paranoid'
  53. aptgetupdate
  54. testequalpolicy 100 1 -o Test=NotAutomatic
  55. testequalpolicy 990 1 -o Test=NotAutomatic -t now
  56. sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
  57. signreleasefiles 'Marvin Paranoid'
  58. aptgetupdate
  59. testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
  60. testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
  61. sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
  62. signreleasefiles 'Marvin Paranoid'
  63. aptgetupdate
  64. testequalpolicy 100 500 -o Test=Automatic
  65. testequalpolicy 990 500 -o Test=Automatic -t now
  66. ### signed and valid key
  67. buildsimplenativepackage "coolstuff" "all" "1.0" "stable"
  68. buildsimplenativepackage "coolstuff" "all" "2.0~bpo1" "backports"
  69. setupaptarchive
  70. testequalpolicycoolstuff() {
  71. local INSTALLED="${1:-(none)}"
  72. local CANDIDATE="${2:-(none)}"
  73. local AB="$3"
  74. local AS="$4"
  75. local PB="$5"
  76. local PINVERSION="$6"
  77. if [ -n "$PINVERSION" ]; then
  78. PINVERSION="Package pin: $PINVERSION
  79. "
  80. fi
  81. local IS=""
  82. local IB=""
  83. local SB=""
  84. local SS=""
  85. [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
  86. 100 $STATUS" || IB=" "
  87. [ "$1" = "1.0" ] && IS="***" && SS="
  88. 100 $STATUS" || IS=" "
  89. local BPO1ARCHIVE=""
  90. local BPO2ARCHIVE=""
  91. if [ ! "$7" = "2.0~bpo2" ]; then
  92. BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ backports/main i386 Packages"
  93. else
  94. BPO2ARCHIVE="
  95. 2.0~bpo2 $PB
  96. $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ backports/main i386 Packages"
  97. SB="$(echo "$SB" | tail -n 1)"
  98. shift
  99. fi
  100. shift 6
  101. testequal "coolstuff:
  102. Installed: $INSTALLED
  103. Candidate: $CANDIDATE
  104. ${PINVERSION}Version table:${BPO2ARCHIVE}
  105. $IB 2.0~bpo1 $PB
  106. ${BPO1ARCHIVE}$SB
  107. $IS 1.0 $PB
  108. $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ stable/main i386 Packages$SS" \
  109. aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
  110. }
  111. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 0 ""
  112. testequalpolicycoolstuff "" "1.0" 500 990 0 "" -t stable
  113. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -t backports
  114. echo "Package: *
  115. Pin: release n=backports
  116. Pin-Priority: 200" > rootdir/etc/apt/preferences
  117. testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=GlobalPin
  118. testequalpolicycoolstuff "" "1.0" 200 990 0 "" -o Test=GlobalPin -t stable
  119. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=GlobalPin -t backports
  120. echo "Package: *
  121. Pin: release n=backports
  122. Pin-Priority: 600" > rootdir/etc/apt/preferences
  123. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=GlobalPin
  124. testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=GlobalPin -t stable
  125. echo "Package: coolstuff
  126. Pin: release n=backports
  127. Pin-Priority: 200" > rootdir/etc/apt/preferences
  128. #FIXME: policy can't differentiate between two sources where one has a package specific pin in place
  129. # testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
  130. # testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
  131. testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
  132. echo "Package: coolstuff
  133. Pin: release n=backports
  134. Pin-Priority: 600" > rootdir/etc/apt/preferences
  135. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
  136. testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
  137. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
  138. echo "Package: coolstuff
  139. Pin: release n=backports
  140. Pin-Priority: -1" > rootdir/etc/apt/preferences
  141. # testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
  142. # testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
  143. # testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
  144. rm rootdir/etc/apt/preferences
  145. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  146. signreleasefiles
  147. aptgetupdate
  148. testequalpolicycoolstuff "" "1.0" 1 500 0 "" -o Test=NotAutomatic
  149. testequalpolicycoolstuff "" "1.0" 1 990 0 "" -o Test=NotAutomatic -t stable
  150. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=NotAutomatic -t backports
  151. echo "Package: *
  152. Pin: release n=backports
  153. Pin-Priority: 200" > rootdir/etc/apt/preferences
  154. testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=NotAutomatic
  155. echo "Package: *
  156. Pin: release n=backports
  157. Pin-Priority: 600" > rootdir/etc/apt/preferences
  158. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=NotAutomatic
  159. testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=NotAutomatic -t stable
  160. echo "Package: coolstuff
  161. Pin: release n=backports
  162. Pin-Priority: 200" > rootdir/etc/apt/preferences
  163. testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
  164. echo "Package: coolstuff
  165. Pin: release n=backports
  166. Pin-Priority: 600" > rootdir/etc/apt/preferences
  167. testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
  168. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
  169. testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
  170. rm rootdir/etc/apt/preferences
  171. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  172. signreleasefiles
  173. aptgetupdate
  174. testequalpolicycoolstuff "" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
  175. testequalpolicycoolstuff "" "1.0" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  176. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
  177. echo "Package: *
  178. Pin: release n=backports
  179. Pin-Priority: 200" > rootdir/etc/apt/preferences
  180. testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=ButAutomaticUpgrades
  181. echo "Package: *
  182. Pin: release n=backports
  183. Pin-Priority: 600" > rootdir/etc/apt/preferences
  184. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=ButAutomaticUpgrades
  185. testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  186. echo "Package: coolstuff
  187. Pin: release n=backports
  188. Pin-Priority: 200" > rootdir/etc/apt/preferences
  189. testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  190. echo "Package: coolstuff
  191. Pin: release n=backports
  192. Pin-Priority: 600" > rootdir/etc/apt/preferences
  193. testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  194. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
  195. testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
  196. rm rootdir/etc/apt/preferences
  197. aptget install coolstuff -qq > /dev/null 2> /dev/null
  198. testequalpolicycoolstuff "1.0" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
  199. aptget dist-upgrade -qq > /dev/null 2> /dev/null
  200. testequalpolicycoolstuff "1.0" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
  201. testequalpolicycoolstuff "1.0" "1.0" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  202. testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
  203. aptget install coolstuff -t backports -qq > /dev/null 2> /dev/null
  204. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 0 "" -o Test=ButAutomaticUpgrades
  205. aptget dist-upgrade -qq > /dev/null 2> /dev/null
  206. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 0 "" -o Test=ButAutomaticUpgrades
  207. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  208. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
  209. rm incoming/backports.main.pkglist incoming/backports.main.srclist
  210. buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
  211. setupaptarchive
  212. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  213. signreleasefiles
  214. aptgetupdate
  215. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 0 "" "2.0~bpo2" -o Test=NotAutomatic
  216. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 0 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
  217. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 0 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
  218. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  219. signreleasefiles
  220. aptgetupdate
  221. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
  222. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
  223. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports