test-policy-pinning 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 IS=""
  72. local IB=""
  73. local SB=""
  74. local SS=""
  75. [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
  76. 100 $STATUS" || IB=" "
  77. [ "$1" = "1.0" ] && IS="***" && SS="
  78. 100 $STATUS" || IS=" "
  79. local BPO1ARCHIVE=""
  80. local BPO2ARCHIVE=""
  81. if [ ! "$7" = "2.0~bpo2" ]; then
  82. BPO1PIN="$AB"
  83. BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main all Packages"
  84. else
  85. BPO2ARCHIVE="
  86. 2.0~bpo2 $AB
  87. $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main all Packages"
  88. SB="$(echo "$SB" | tail -n 1)"
  89. shift
  90. fi
  91. shift 6
  92. testsuccessequal "coolstuff:
  93. Installed: $INSTALLED
  94. Candidate: $CANDIDATE
  95. Version table:${BPO2ARCHIVE}
  96. $IB 2.0~bpo1 $PB
  97. ${BPO1ARCHIVE}$SB
  98. $IS 1.0 $AS
  99. $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} stable/main all Packages$SS" \
  100. aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
  101. }
  102. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 500 ""
  103. testequalpolicycoolstuff "" "1.0" 500 990 500 "" -t stable
  104. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -t backports
  105. echo "Package: *
  106. Pin: release n=backports
  107. Pin-Priority: 200" > rootdir/etc/apt/preferences
  108. testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=GlobalPin
  109. testequalpolicycoolstuff "" "1.0" 200 990 200 "" -o Test=GlobalPin -t stable
  110. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=GlobalPin -t backports
  111. echo "Package: *
  112. Pin: release n=backports
  113. Pin-Priority: 600" > rootdir/etc/apt/preferences
  114. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=GlobalPin
  115. testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=GlobalPin -t stable
  116. echo "Package: coolstuff
  117. Pin: release n=backports
  118. Pin-Priority: 200" > rootdir/etc/apt/preferences
  119. #FIXME: policy can't differentiate between two sources where one has a package specific pin in place
  120. # testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
  121. # testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
  122. testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
  123. echo "Package: coolstuff
  124. Pin: release n=backports
  125. Pin-Priority: 600" > rootdir/etc/apt/preferences
  126. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
  127. testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
  128. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
  129. echo "Package: coolstuff
  130. Pin: release n=backports
  131. Pin-Priority: -1" > rootdir/etc/apt/preferences
  132. # testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
  133. # testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
  134. # testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
  135. rm rootdir/etc/apt/preferences
  136. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  137. signreleasefiles
  138. aptgetupdate
  139. testequalpolicycoolstuff "" "1.0" 1 500 1 "" -o Test=NotAutomatic
  140. testequalpolicycoolstuff "" "1.0" 1 990 1 "" -o Test=NotAutomatic -t stable
  141. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=NotAutomatic -t backports
  142. echo "Package: *
  143. Pin: release n=backports
  144. Pin-Priority: 200" > rootdir/etc/apt/preferences
  145. testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=NotAutomatic
  146. echo "Package: *
  147. Pin: release n=backports
  148. Pin-Priority: 600" > rootdir/etc/apt/preferences
  149. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=NotAutomatic
  150. testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=NotAutomatic -t stable
  151. echo "Package: coolstuff
  152. Pin: release n=backports
  153. Pin-Priority: 200" > rootdir/etc/apt/preferences
  154. testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
  155. echo "Package: coolstuff
  156. Pin: release n=backports
  157. Pin-Priority: 600" > rootdir/etc/apt/preferences
  158. testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
  159. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
  160. testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
  161. rm rootdir/etc/apt/preferences
  162. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  163. signreleasefiles
  164. aptgetupdate
  165. testequalpolicycoolstuff "" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
  166. testequalpolicycoolstuff "" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
  167. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
  168. echo "Package: *
  169. Pin: release n=backports
  170. Pin-Priority: 200" > rootdir/etc/apt/preferences
  171. testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=ButAutomaticUpgrades
  172. echo "Package: *
  173. Pin: release n=backports
  174. Pin-Priority: 600" > rootdir/etc/apt/preferences
  175. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=ButAutomaticUpgrades
  176. testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=ButAutomaticUpgrades -t stable
  177. echo "Package: coolstuff
  178. Pin: release n=backports
  179. Pin-Priority: 200" > rootdir/etc/apt/preferences
  180. testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  181. echo "Package: coolstuff
  182. Pin: release n=backports
  183. Pin-Priority: 600" > rootdir/etc/apt/preferences
  184. testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  185. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
  186. testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
  187. rm rootdir/etc/apt/preferences
  188. testsuccess aptget install coolstuff -y
  189. testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
  190. testsuccess aptget dist-upgrade -y
  191. testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
  192. testequalpolicycoolstuff "1.0" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
  193. testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
  194. testsuccess aptget install coolstuff -t backports -y
  195. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
  196. testsuccess aptget dist-upgrade -y
  197. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
  198. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
  199. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
  200. rm incoming/backports.main.pkglist incoming/backports.main.srclist
  201. buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
  202. setupaptarchive
  203. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  204. signreleasefiles
  205. aptgetupdate
  206. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 100 "" "2.0~bpo2" -o Test=NotAutomatic
  207. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 100 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
  208. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
  209. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  210. signreleasefiles
  211. aptgetupdate
  212. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
  213. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
  214. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports
  215. tmppath=$(readlink -f .)
  216. # Check 16-bit integers
  217. echo "Package: coolstuff
  218. Pin: release n=backports
  219. Pin-Priority: 32767
  220. " > rootdir/etc/apt/preferences
  221. testsuccess aptget install -s coolstuff -o PinPriority=32767
  222. echo "Package: coolstuff
  223. Pin: release n=backports
  224. Pin-Priority: -32768
  225. " > rootdir/etc/apt/preferences
  226. testsuccess aptget install -s coolstuff -o PinPriority=-32768
  227. # Check for 32-bit integers
  228. echo "Package: coolstuff
  229. Pin: release n=backports
  230. Pin-Priority: 32768
  231. " > rootdir/etc/apt/preferences
  232. testfailureequal "Reading package lists...
  233. E: ${tmppath}/rootdir/etc/apt/preferences: Value 32768 is outside the range of valid pin priorities (-32768 to 32767)" \
  234. aptget install -s coolstuff -o PinPriority=32768
  235. echo "Package: coolstuff
  236. Pin: release n=backports
  237. Pin-Priority: -32769
  238. " > rootdir/etc/apt/preferences
  239. testfailureequal "Reading package lists...
  240. E: ${tmppath}/rootdir/etc/apt/preferences: Value -32769 is outside the range of valid pin priorities (-32768 to 32767)" \
  241. aptget install -s coolstuff -o PinPriority=-32769
  242. # Check for 64-bit integers
  243. echo "Package: coolstuff
  244. Pin: release n=backports
  245. Pin-Priority: 2147483648
  246. " > rootdir/etc/apt/preferences
  247. testfailureequal "Reading package lists...
  248. E: Cannot convert 2147483648 to integer - (34: Numerical result out of range)
  249. E: ${tmppath}/rootdir/etc/apt/preferences: Value 2147483648 is outside the range of valid pin priorities (-32768 to 32767)" \
  250. aptget install -s coolstuff -o PinPriority=2147483648
  251. # Check for 0
  252. echo "Package: coolstuff
  253. Pin: release n=backports
  254. Pin-Priority: 0
  255. " > rootdir/etc/apt/preferences
  256. testfailureequal "Reading package lists...
  257. E: No priority (or zero) specified for pin" \
  258. aptget install -s coolstuff -o PinPriority=0