1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/usr/bin/busybox sh
SCRIPT="generators/60local"
oneTimeSetUp() {
# Define global variables for command output.
sourceslist="${SHUNIT_TMPDIR}/sources.list"
ROOT=${SHUNIT_TMPDIR}/_root_
mkdir -p ${ROOT}/tmp ${ROOT}/etc/apt/keyrings/
}
setUp() {
rm -f "${sourceslist}"
# clear out settings between tests
for x in _DEVEL_ local0 local1; do
for y in source repository comment key; do
unset apt_setup_${x}_${y}
done
done
unset db_go_ret
# provide a default fetch result, that can be overriden
export fetch_url_result="pretend binary GPG key"
}
test_no_locals() {
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: $output" '[ 0 = $result ]'
assertFalse "'${sourceslist}' should not have been created" "[ -e '${sourceslist}' ]"
}
test__DEVEL_repo() {
apt_setup__DEVEL__repository="file:///foo/bar"
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: $output" '[ 0 = $result ]'
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup__DEVEL__repository}'" "grep -q '${apt_setup__DEVEL__repository}' '${sourceslist}'"
}
test_comment() {
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_comment="my favourite stuff"
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: $output" '[ 0 = $result ]'
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
}
test_options() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_options="check-valid-until=false"
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: '$output'" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_options}'" "grep -q '${apt_setup_local0_options}' '${sourceslist}'"
# head -v "${sourceslist}"
}
test_options_and_key() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_options="check-valid-until=false"
apt_setup_local0_comment="some_comment"
apt_setup_local0_key=zzzz # we're mocking fetch_url, so this setting isn't actually used
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: '$output'" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
assertTrue "'${sourceslist}' should contain 'signed-by=/etc/apt/keyrings/${apt_setup_local0_comment}.gpg'" "grep -q 'signed-by=/etc/apt/keyrings/${apt_setup_local0_comment}.gpg' '${sourceslist}'"
assertTrue "'${ROOT}/etc/apt/keyrings/${apt_setup_local0_comment}.gpg' should contain '${fetch_url_result}'" "grep -q '${fetch_url_result}' '${ROOT}/etc/apt/keyrings/${apt_setup_local0_comment}.gpg'"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_options}'" "grep -q '${apt_setup_local0_options}' '${sourceslist}'"
}
test_source() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_source=true
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: '$output'" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain 'mumble'" "grep -q '${apt_setup__DEVEL__repository}' '${sourceslist}'"
}
test_gpg_asc() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_source=true
fetch_url_result='-----BEGIN PGP PUBLIC KEY BLOCK-----'
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: '$output'" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
}
test_failed_fetch() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_source=true
apt_setup_local0_key=zzzz # we're mocking fetch_url, so this setting isn't actually used
# simulate a failure of fetch_url
fetch_url_result='fail'
# make it look like the user doesn't want to retry
db_go_ret=false
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertFalse "command should have failed" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertFalse "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
}
test_ignore_failed_fetch() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_source=true
apt_setup_local0_key=zzzz # we're mocking fetch_url, so this setting isn't actually used
# simulate a failure of fetch_url
fetch_url_result='fail'
# make it look like the user wants to ignore the failure
db_go_ret=true
apt_setup_local_key_error=Ignore
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: '$output'" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
}
test_multi_repo() {
touch "$ROOT/tmp/key0.pub"
apt_setup_local0_repository="http://some.url/"
apt_setup_local0_source=true
apt_setup_local1_repository="https://someother.url/"
fetch_url_result='fail'
apt_setup_local_key_error=Ignore
db_go_ret=true
output=$(. $SCRIPT "${sourceslist}" 2>&1)
result=$?
assertTrue "command failed with this output: '$output'" "[ 0 -eq $result ]"
assertTrue "'${sourceslist}' should have been created" "[ -e '${sourceslist}' ]"
assertTrue "'${sourceslist}' should contain '${apt_setup_local0_repository}'" "grep -q '${apt_setup_local0_repository}' '${sourceslist}'"
assertTrue "'${sourceslist}' should contain '${apt_setup_local1_repository}'" "grep -q '${apt_setup_local1_repository}' '${sourceslist}'"
# head -v "${sourceslist}"
}
# load shunit2
. shunit2
|