fix msm-plugin.c svace issue: make sure dupPath is not NULL before strchr()
[platform/upstream/rpm.git] / tests / rpmi.at
1 #    rpmi.at: test various aspects of rpm install
2 #
3 #    Copyright (C) 2007  Ralf Corsépius <corsepiu@fedoraproject.org>
4 #
5 #    This program is free software; you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation; either version 2 of the License, or
8 #    (at your option) any later version.
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program; if not, write to the Free Software
17 #    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
19 AT_BANNER([RPM install tests])
20
21 AT_SETUP([rpm -U <manifest>])
22 AT_KEYWORDS([install])
23 AT_CHECK([
24 RPMDB_CLEAR
25 RPMDB_INIT
26
27 echo /data/RPMS/hello-2.0-1.x86_64.rpm > ${RPMTEST}/tmp/test.mft
28 runroot rpm -U --ignorearch --ignoreos --nodeps \
29         /tmp/test.mft
30 ],
31 [0],
32 [],
33 [])
34 AT_CLEANUP
35
36 AT_SETUP([rpm -U <manifest notfound 1>])
37 AT_KEYWORDS([install])
38 AT_CHECK([
39 RPMDB_CLEAR
40 RPMDB_INIT
41
42 echo /data/RPMS/hello-2.0-1.x86_64.rpm > ${RPMTEST}/tmp/test.mft
43 runroot rpm -U --ignorearch --ignoreos --nodeps \
44         /tmp/test-not-there.mft
45 ],
46 [1],
47 [],
48 [error: open of /tmp/test-not-there.mft failed: No such file or directory
49 ])
50 AT_CLEANUP
51
52 AT_SETUP([rpm -U <manifest notfound 2>])
53 AT_KEYWORDS([install])
54 AT_CHECK([
55 RPMDB_CLEAR
56 RPMDB_INIT
57
58 echo /data/RPMS/hello-not-there-2.0-1.x86_64.rpm > ${RPMTEST}/tmp/test.mft
59 runroot rpm -U --ignorearch --ignoreos --nodeps \
60         /tmp/test.mft
61 ],
62 [1],
63 [],
64 [error: open of /data/RPMS/hello-not-there-2.0-1.x86_64.rpm failed: No such file or directory
65 ])
66 AT_CLEANUP
67
68 AT_SETUP([rpm -U <notfound>])
69 AT_KEYWORDS([install])
70 AT_CHECK([
71 RPMDB_CLEAR
72 RPMDB_INIT
73
74 runroot rpm -U --ignorearch --ignoreos --nodeps \
75         /data/RPMS/hello-not-there-2.0-1.x86_64.rpm
76 ],
77 [1],
78 [],
79 [error: open of /data/RPMS/hello-not-there-2.0-1.x86_64.rpm failed: No such file or directory
80 ])
81 AT_CLEANUP
82
83 AT_SETUP([rpm -U <unsigned>])
84 AT_KEYWORDS([install])
85 AT_CHECK([
86 RPMDB_CLEAR
87 RPMDB_INIT
88
89 runroot rpm -U --ignorearch --ignoreos --nodeps \
90         /data/RPMS/hello-2.0-1.x86_64.rpm
91 ],
92 [0],
93 [],
94 [])
95 AT_CLEANUP
96
97 AT_SETUP([rpm -U <signed nokey>])
98 AT_KEYWORDS([install])
99 AT_CHECK([
100 RPMDB_CLEAR
101 RPMDB_INIT
102
103 runroot rpm -U --ignorearch --ignoreos --nodeps \
104         /data/RPMS/hello-2.0-1.x86_64-signed.rpm
105 ],
106 [0],
107 [],
108 [warning: /data/RPMS/hello-2.0-1.x86_64-signed.rpm: Header V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
109 ])
110 AT_CLEANUP
111
112 AT_SETUP([rpm -U <signed>])
113 AT_KEYWORDS([install])
114 AT_CHECK([
115 RPMDB_CLEAR
116 RPMDB_INIT
117
118 runroot rpmkeys --import /data/keys/rpm.org-rsa-2048-test.pub
119 runroot rpm -U --ignorearch --ignoreos --nodeps \
120         /data/RPMS/hello-2.0-1.x86_64-signed.rpm
121 ],
122 [0],
123 [],
124 [])
125 AT_CLEANUP
126
127 AT_SETUP([rpm -U <corrupted signed 1>])
128 AT_KEYWORDS([install])
129 AT_CHECK([
130 RPMDB_CLEAR
131 RPMDB_INIT
132
133 pkg="hello-2.0-1.x86_64-signed.rpm"
134 cp "${RPMTEST}"/data/RPMS/${pkg} "${RPMTEST}"/tmp/${pkg}
135 dd if=/dev/zero of="${RPMTEST}"/tmp/${pkg} \
136    conv=notrunc bs=1 seek=264 count=2 2> /dev/null
137
138 runroot rpm -U --ignorearch --ignoreos --nodeps \
139         /tmp/${pkg}
140 ],
141 [1],
142 [],
143 [error: /tmp/hello-2.0-1.x86_64-signed.rpm: Header signature: BAD (package tag 268: invalid OpenPGP signature)
144 error: /tmp/hello-2.0-1.x86_64-signed.rpm cannot be installed
145 ])
146 AT_CLEANUP
147
148 AT_SETUP([rpm -U <corrupted signed 2>])
149 AT_KEYWORDS([install])
150 AT_CHECK([
151 RPMDB_CLEAR
152 RPMDB_INIT
153
154 pkg="hello-2.0-1.x86_64-signed.rpm"
155 cp "${RPMTEST}"/data/RPMS/${pkg} "${RPMTEST}"/tmp/${pkg}
156 dd if=/dev/zero of="${RPMTEST}"/tmp/${pkg} \
157    conv=notrunc bs=1 seek=5555 count=6 2> /dev/null
158
159 runroot rpm -U --ignorearch --ignoreos --nodeps \
160         /tmp/${pkg}
161 ],
162 [1],
163 [],
164 [error: /tmp/hello-2.0-1.x86_64-signed.rpm: Header V4 RSA/SHA256 Signature, key ID 1964c5fc: BAD
165 error: /tmp/hello-2.0-1.x86_64-signed.rpm: Header SHA1 digest: BAD (Expected 5cd9874c510b67b44483f9e382a1649ef7743bac != 4261b2c1eb861a4152c2239bce20bfbcaa8971ba)
166 error: /tmp/hello-2.0-1.x86_64-signed.rpm: Header SHA256 digest: BAD (Expected ef920781af3bf072ae9888eec3de1c589143101dff9cc0b561468d395fb766d9 != 29fdfe92782fb0470a9a164a6c94af87d3b138c63b39d4c30e0223ca1202ba82)
167 error: /tmp/hello-2.0-1.x86_64-signed.rpm cannot be installed
168 ])
169 AT_CLEANUP
170
171 # This is more about documenting current behavior than what it *should* do
172 # when encountering corrupted payload.
173 AT_SETUP([rpm -U <corrupted signed 3>])
174 AT_KEYWORDS([install])
175 AT_CHECK([
176 RPMDB_CLEAR
177 RPMDB_INIT
178
179 pkg="hello-2.0-1.x86_64-signed.rpm"
180 cp "${RPMTEST}"/data/RPMS/${pkg} "${RPMTEST}"/tmp/${pkg}
181 dd if=/dev/zero of="${RPMTEST}"/tmp/${pkg} \
182    conv=notrunc bs=1 seek=7788 count=6 2> /dev/null
183
184 runroot rpm -U --ignorearch --ignoreos --nodeps \
185         /tmp/${pkg}
186 ],
187 [1],
188 [],
189 [warning: /tmp/hello-2.0-1.x86_64-signed.rpm: Header V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
190 error: unpacking of archive failed: cpio: Bad magic
191 error: hello-2.0-1.x86_64: install failed
192 ])
193 AT_CLEANUP
194
195 # ------------------------------
196 # Check if rpm -U *.src.rpm works
197 AT_SETUP([rpm -U *.src.rpm])
198 AT_KEYWORDS([install])
199 AT_CHECK([
200 rm -rf ${TOPDIR}
201
202 runroot rpm \
203   -U /data/SRPMS/hello-1.0-1.src.rpm
204 ],
205 [0],
206 [ignore],
207 [ignore])
208 AT_CLEANUP
209
210 # ------------------------------
211 # Check if rpm -i *.src.rpm works
212 AT_SETUP([rpm -i *.src.rpm])
213 AT_KEYWORDS([install])
214 AT_CHECK([
215 rm -rf ${TOPDIR}
216
217 runroot rpm \
218   -i /data/SRPMS/hello-1.0-1.src.rpm
219 ],
220 [0],
221 [ignore],
222 [ignore])
223 AT_CLEANUP
224
225 # ------------------------------
226 # Various error behavior tests
227 #
228 AT_SETUP([rpm -i <nonexistent file>])
229 AT_KEYWORDS([install])
230 AT_CHECK([
231 runroot rpm \
232   -i no_such_file
233 ],
234 [1],
235 [ignore],
236 [ignore])
237 AT_CLEANUP
238
239 # XXX hmm, --nomanifest seems broken atm...
240 AT_SETUP([rpm -i --nomanifest <garbage text file>])
241 AT_KEYWORDS([install])
242 AT_CHECK([
243 junk="${RPMTEST}/textfile"
244 cat << EOF > "${junk}"
245 no_such.file
246 not_an.rpm
247 EOF
248
249 runroot rpm \
250   -Uvv --nomanifest /textfile
251 ],
252 [1],
253 [ignore],
254 [ignore])
255 AT_CLEANUP
256
257 AT_SETUP([rpm -i <garbage text file])
258 AT_KEYWORDS([install])
259 AT_CHECK([
260 junk="${RPMTEST}/not_an.rpm"
261 cat << EOF > "${junk}"
262 no_such.file
263 not_pkg.rpm
264 EOF
265
266 runroot rpm \
267   -Uvv /not_an.rpm
268 ],
269 [2],
270 [ignore],
271 [ignore])
272 AT_CLEANUP
273
274 # ------------------------------
275 # Test normal upgrade
276 AT_SETUP([rpm -U upgrade to newer])
277 AT_CHECK([
278 RPMDB_CLEAR
279 RPMDB_INIT
280 rm -rf "${TOPDIR}"
281
282 for v in "1.0" "2.0"; do
283     runroot rpmbuild --quiet -bb \
284         --define "ver $v" \
285           /data/SPECS/versiontest.spec
286 done
287
288 runroot rpm -U /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm
289 runroot rpm -U /build/RPMS/noarch/versiontest-2.0-1.noarch.rpm
290 runroot rpm -q versiontest
291 ],
292 [0],
293 [versiontest-2.0-1.noarch
294 ],
295 [])
296 AT_CLEANUP
297
298 # Test upgrading to older package (should fail)
299 AT_SETUP([rpm -U upgrade to older])
300 AT_CHECK([
301 RPMDB_CLEAR
302 RPMDB_INIT
303
304 runroot rpm -U /build/RPMS/noarch/versiontest-2.0-1.noarch.rpm
305 runroot rpm -U /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm
306 ],
307 [2],
308 [],
309 [       package versiontest-2.0-1.noarch (which is newer than versiontest-1.0-1.noarch) is already installed
310 ])
311 AT_CLEANUP
312
313 # Test downgrading to older package with --oldpackage
314 AT_SETUP([rpm -U --oldpackage downgrade])
315 AT_CHECK([
316 RPMDB_CLEAR
317 RPMDB_INIT
318
319 runroot rpm -U /build/RPMS/noarch/versiontest-2.0-1.noarch.rpm
320 runroot rpm -U --oldpackage /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm
321 runroot rpm -q versiontest
322 ],
323 [0],
324 [versiontest-1.0-1.noarch
325 ],
326 [ignore])
327 AT_CLEANUP
328
329 # Test upgrade of different versions in same transaction
330 AT_SETUP([rpm -U two versions of same package 1])
331 AT_CHECK([
332 RPMDB_CLEAR
333 RPMDB_INIT
334
335 runroot rpm -Uv \
336   /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm \
337   /build/RPMS/noarch/versiontest-2.0-1.noarch.rpm
338 runroot rpm -q versiontest
339 ],
340 [0],
341 [Preparing packages...
342 versiontest-2.0-1.noarch
343 versiontest-2.0-1.noarch
344 ],
345 [warning: package versiontest-1.0-1.noarch was already added, replacing with versiontest-2.0-1.noarch
346 ])
347 AT_CLEANUP
348
349 # Test upgrade of different versions in same transaction
350 AT_SETUP([rpm -U two versions of same package 2])
351 AT_CHECK([
352 RPMDB_CLEAR
353 RPMDB_INIT
354
355 runroot rpm -Uv \
356   /build/RPMS/noarch/versiontest-2.0-1.noarch.rpm \
357   /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm
358 runroot rpm -q versiontest
359 ],
360 [0],
361 [Preparing packages...
362 versiontest-2.0-1.noarch
363 versiontest-2.0-1.noarch
364 ],
365 [warning: package versiontest-2.0-1.noarch was already added, skipping versiontest-1.0-1.noarch
366 ])
367 AT_CLEANUP
368
369 # Test upgrade of obsoleted package in same transaction
370 AT_SETUP([rpm -U obsoleted package 1])
371 AT_CHECK([
372 RPMDB_CLEAR
373 RPMDB_INIT
374
375 runroot rpmbuild --quiet -bb \
376         --define "pkg one" \
377         --define "obs deptest-two" \
378         /data/SPECS/deptest.spec
379 runroot rpmbuild --quiet -bb \
380         --define "pkg two" \
381         /data/SPECS/deptest.spec
382
383
384 runroot rpm -Uv \
385   /build/RPMS/noarch/deptest-two-1.0-1.noarch.rpm \
386   /build/RPMS/noarch/deptest-one-1.0-1.noarch.rpm
387 runroot rpm -q deptest-one
388 ],
389 [0],
390 [Preparing packages...
391 deptest-one-1.0-1.noarch
392 deptest-one-1.0-1.noarch
393 ],
394 [warning: package deptest-two-1.0-1.noarch was already added, replacing with deptest-one-1.0-1.noarch
395 ])
396 AT_CLEANUP
397
398 # Test upgrade of obsoleted package in same transaction
399 AT_SETUP([rpm -U obsoleted package 2])
400 AT_CHECK([
401 RPMDB_CLEAR
402 RPMDB_INIT
403
404 runroot rpmbuild --quiet -bb \
405         --define "pkg one" \
406         --define "obs deptest-two" \
407         /data/SPECS/deptest.spec
408 runroot rpmbuild --quiet -bb \
409         --define "pkg two" \
410         /data/SPECS/deptest.spec
411
412
413 runroot rpm -Uv \
414   /build/RPMS/noarch/deptest-one-1.0-1.noarch.rpm \
415   /build/RPMS/noarch/deptest-two-1.0-1.noarch.rpm
416 runroot rpm -q deptest-one
417 ],
418 [0],
419 [Preparing packages...
420 deptest-one-1.0-1.noarch
421 deptest-one-1.0-1.noarch
422 ],
423 [warning: package deptest-one-1.0-1.noarch was already added, skipping deptest-two-1.0-1.noarch
424 ])
425 AT_CLEANUP
426
427 # Test install of two different versions in same transaction
428 AT_SETUP([rpm -i two versions of same package])
429 AT_CHECK([
430 RPMDB_CLEAR
431 RPMDB_INIT
432
433 runroot rpm -i \
434   /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm \
435   /build/RPMS/noarch/versiontest-2.0-1.noarch.rpm
436 runroot rpm -q versiontest
437 ],
438 [0],
439 [versiontest-2.0-1.noarch
440 versiontest-1.0-1.noarch
441 ],
442 [])
443 AT_CLEANUP
444
445 # Test install of two different versions in same transaction
446 # TODO: test only one was installed
447 AT_SETUP([rpm -i identical versions of same package])
448 AT_CHECK([
449 RPMDB_CLEAR
450 RPMDB_INIT
451
452 runroot rpm -i \
453   /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm \
454   /build/RPMS/noarch/versiontest-1.0-1.noarch.rpm
455 runroot rpm -q versiontest
456 ],
457 [0],
458 [versiontest-1.0-1.noarch
459 ],
460 [])
461 AT_CLEANUP
462
463 # TODO: the same with epoch vs no epoch
464
465 AT_SETUP([rpm -U with invalid --relocate])
466 AT_KEYWORDS([install relocate])
467 AT_CHECK([
468 RPMDB_CLEAR
469 RPMDB_INIT
470
471 runroot rpmbuild --quiet -bb /data/SPECS/hello-script.spec
472
473 runroot rpm -U --test --ignoreos --relocate /usr=/opt \
474   /build/RPMS/noarch/hello-script-1.0-1.noarch.rpm
475 ],
476 [1],
477 [],
478 [       path /usr in package hello-script-1.0-1.noarch is not relocatable
479 ])
480 AT_CLEANUP
481
482 AT_SETUP([rpm -U --badreloc with invalid --relocate])
483 AT_KEYWORDS([install relocate])
484 AT_CHECK([
485 RPMDB_CLEAR
486 RPMDB_INIT
487
488 runroot rpmbuild --quiet -bb /data/SPECS/hello-script.spec
489
490 runroot rpm -U --test --ignoreos --badreloc --relocate /usr=/opt \
491   /build/RPMS/noarch/hello-script-1.0-1.noarch.rpm
492 ],
493 [0],
494 [],
495 [])
496 AT_CLEANUP
497
498 AT_SETUP([rpm -i with/without --excludedocs])
499 AT_KEYWORDS([install excludedocs])
500 AT_CHECK([
501 RPMDB_CLEAR
502 RPMDB_INIT
503
504 runroot rpmbuild --quiet -bb /data/SPECS/testdoc.spec
505
506 runroot rpm -i --excludedocs \
507   /build/RPMS/noarch/testdoc-1.0-1.noarch.rpm
508
509 RPM_DOCDIR=$(runroot rpm --eval '%_defaultdocdir')
510 RPM_DATADIR=$(runroot rpm --eval '%_datadir')
511
512 test ! -e ${RPMTEST}${RPM_DOCDIR}/testdoc || exit 1
513 test -e ${RPMTEST}${RPM_DATADIR}/testdoc/nodoc || exit 1
514
515 runroot rpm -e testdoc
516
517 runroot rpm -i \
518   /build/RPMS/noarch/testdoc-1.0-1.noarch.rpm
519 test -e ${RPMTEST}${RPM_DOCDIR}/testdoc/documentation1 || exit 1
520 test -e ${RPMTEST}${RPM_DOCDIR}/testdoc/documentation2 || exit 1
521 test -e ${RPMTEST}${RPM_DOCDIR}/testdoc/examples/example1 || exit 1
522 test -e ${RPMTEST}${RPM_DOCDIR}/testdoc/examples/example2 || exit 1
523 test -e ${RPMTEST}${RPM_DATADIR}/testdoc/nodoc || exit 1
524
525 runroot rpm -e testdoc
526 ],
527 [0],
528 [],
529 [])
530 AT_CLEANUP
531