test/integration/test-ubuntu-bug-346386-apt-get-update-paywall: use downloadfile()
[ntk/apt.git] / test / integration / test-ubuntu-bug-346386-apt-get-update-paywall
CommitLineData
ae99ce2e
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6
7setupenvironment
8configarchitecture 'native'
9
10insertpackage 'unstable' 'unrelated' 'all' '1.0' 'stable'
11insertsource 'unstable' 'unrelated' 'all' '1.0' 'stable'
12
13echo 'ni ni ni' > aptarchive/knights
14
15setupaptarchive
16changetowebserver -o 'aptwebserver::overwrite::.*::filename=/knights'
17
18msgtest 'Acquire test file from the webserver to check' 'overwrite'
3b5607fc
MV
19if downloadfile http://localhost:8080/holygrail ./knights-talking >/dev/null; then
20 msgpass
21else
22 msgfail
23fi
ae99ce2e
DK
24testfileequal knights-talking 'ni ni ni'
25
26ensure_n_canary_strings_in_dir() {
27 local DIR="$1"
28 local CANARY_STRING="$2"
29 local EXPECTED_N="$3"
30
31 msgtest "Testing in $DIR for $EXPECTED_N canary" "$CANARY_STRING"
32 local N=$(grep "$CANARY_STRING" $DIR/* 2>/dev/null |wc -l )
33 test "$N" = "$EXPECTED_N" && msgpass || msgfail "Expected $EXPECTED_N canaries, got $N"
34}
35
36LISTS='rootdir/var/lib/apt/lists'
37rm -rf rootdir/var/lib/apt/lists
38msgtest 'Got expected NODATA failure in' 'apt-get update'
39aptget update -qq 2>&1 | grep -q 'E: GPG error.*NODATA' && msgpass || msgfail
40
41ensure_n_canary_strings_in_dir $LISTS 'ni ni ni' 0
42testequal 'partial' ls $LISTS
43
44# and again with pre-existing files with "valid data" which should remain
45for f in Release Release.gpg main_binary-amd64_Packages main_source_Sources; do
46 echo 'peng neee-wom' > $LISTS/localhost:8080_dists_stable_${f}
47done
48
49msgtest 'Got expected NODATA failure in' 'apt-get update'
50aptget update -qq 2>&1 | grep -q 'E: GPG error.*NODATA' && msgpass || msgfail
51
52ensure_n_canary_strings_in_dir $LISTS 'peng neee-wom' 4
53ensure_n_canary_strings_in_dir $LISTS 'ni ni ni' 0
54
55# and now with a pre-existing InRelease file
56echo 'peng neee-wom' > $LISTS/localhost:8080_dists_stable_InRelease
57rm -f $LISTS/localhost:8080_dists_stable_Release $LISTS/localhost:8080_dists_stable_Release.gpg
58msgtest 'excpected failure of' 'apt-get update'
59aptget update -qq 2>&1 | grep -q 'E: GPG error.*NODATA' && msgpass || msgfail
60
61ensure_n_canary_strings_in_dir $LISTS 'peng neee-wom' 3
62ensure_n_canary_strings_in_dir $LISTS 'ni ni ni' 0