test-policy-pinning 13 KB

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