You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

421 lines
14 KiB

  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 --no-update
  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 ${3:-$1}
  270. ${3:-$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' '-32767'
  278. currentpin '-32767' '2.0~bpo1' '-32767'
  279. # Check for 0
  280. echo "Package: coolstuff
  281. Pin: release n=backports
  282. Pin-Priority: 0
  283. " > rootdir/etc/apt/preferences
  284. testfailureequal "Reading package lists...
  285. E: No priority (or zero) specified for pin" \
  286. aptget install -s coolstuff -o PinPriority=0
  287. # Check with comments
  288. echo "#Package: coolstuff
  289. #Pin: release n=backports
  290. #Pin-Priority: 0
  291. # Test
  292. Package: coolstuff
  293. Pin: release n=backports
  294. #Pin: release n=unstable
  295. #Pin-Priority: 999
  296. Pin-Priority: 999
  297. #Pin-Priority: 999" > rootdir/etc/apt/preferences
  298. testsuccessequal "coolstuff:
  299. Installed: 2.0~bpo1
  300. Candidate: 2.0~bpo2
  301. Version table:
  302. 2.0~bpo2 999
  303. 100 file:${tmppath}/aptarchive backports/main all Packages
  304. *** 2.0~bpo1 100
  305. 100 ${tmppath}/rootdir/var/lib/dpkg/status
  306. 1.0 500
  307. 500 file:${tmppath}/aptarchive stable/main all Packages" aptcache policy coolstuff
  308. # Check for override pins
  309. # Normal pins: First one wins
  310. echo "Package: coolstuff
  311. Pin: release n=backports
  312. Pin-Priority: 990
  313. Package: coolstuff
  314. Pin: release n=backports
  315. Pin-Priority: 991
  316. " > rootdir/etc/apt/preferences
  317. testsuccessequal "coolstuff:
  318. Installed: 2.0~bpo1
  319. Candidate: 2.0~bpo2
  320. Version table:
  321. 2.0~bpo2 990
  322. 100 file:${tmppath}/aptarchive backports/main all Packages
  323. *** 2.0~bpo1 100
  324. 100 ${tmppath}/rootdir/var/lib/dpkg/status
  325. 1.0 500
  326. 500 file:${tmppath}/aptarchive stable/main all Packages" aptcache policy coolstuff
  327. echo "Package: coolstuff
  328. Pin: release n=backports
  329. Pin-Priority: 990
  330. Package: *
  331. Pin: release n=backports
  332. Pin-Priority: never
  333. " > rootdir/etc/apt/preferences
  334. testsuccessequal "coolstuff:
  335. Installed: 2.0~bpo1
  336. Candidate: 2.0~bpo1
  337. Version table:
  338. 2.0~bpo2 -32768
  339. -32768 file:${tmppath}/aptarchive backports/main all Packages
  340. *** 2.0~bpo1 100
  341. 100 ${tmppath}/rootdir/var/lib/dpkg/status
  342. 1.0 500
  343. 500 file:${tmppath}/aptarchive stable/main all Packages" aptcache policy coolstuff
  344. # Check for 0
  345. echo "Package: coolstuff
  346. Pin: release n=backports
  347. Pin-Priority: never
  348. " > rootdir/etc/apt/preferences
  349. testfailureequal "Reading package lists...
  350. E: ${tmppath}/rootdir/etc/apt/preferences: The special 'Pin-Priority: never' can only be used for 'Package: *' records" \
  351. aptget install -s coolstuff -o PinPriority=0