|
| 1 | +#!/bin/bash -e |
| 2 | +. ../../test-lib.sh 2>/dev/null || { echo "Must run in script directory!" ; exit 1 ; } |
| 3 | +cleanup |
| 4 | + |
| 5 | +# Test that corruptions of binary artifacts are detected... |
| 6 | + |
| 7 | +# setup local archive |
| 8 | +trap 'rm -rf "${archiveDir}"' EXIT |
| 9 | +archiveDir=$(mktemp -d) |
| 10 | + |
| 11 | +upload="$archiveDir/uploads" |
| 12 | +cat >"${upload}.yaml" <<EOF |
| 13 | +archive: |
| 14 | + - |
| 15 | + name: "local" |
| 16 | + backend: file |
| 17 | + path: "$(mangle_path "$archiveDir/artifacts")" |
| 18 | +EOF |
| 19 | +scratch="$archiveDir/scratch" |
| 20 | +mkdir "$scratch" |
| 21 | + |
| 22 | +# fill archive |
| 23 | +run_bob build -c "$upload" --download=no --upload root |
| 24 | +ARTIFACTS=( $(/usr/bin/find "$archiveDir/artifacts" -type f) ) |
| 25 | +test "${#ARTIFACTS[@]}" -eq 1 |
| 26 | + |
| 27 | +# save artifact for later modification |
| 28 | +A="${ARTIFACTS[0]}" |
| 29 | +SAVE="$archiveDir/save.tgz" |
| 30 | +cp "$A" "$SAVE" |
| 31 | + |
| 32 | +# Verify download of re-packed artifact still works. |
| 33 | +rm "$A" |
| 34 | +pushd "$scratch" |
| 35 | +tar xf "$SAVE" |
| 36 | +tar --pax-option bob-archive-vsn=1 -zcf "$A" meta content |
| 37 | +popd |
| 38 | +run_bob dev -c "$upload" --download=forced root |
| 39 | + |
| 40 | +# Modify content. When downloading the artifact again, the corruption must be |
| 41 | +# detected. |
| 42 | +rm "$A" |
| 43 | +pushd "$scratch" |
| 44 | +tar xf "$SAVE" |
| 45 | +echo bar > content/result.txt |
| 46 | +tar --pax-option bob-archive-vsn=1 -zcf "$A" meta content |
| 47 | +popd |
| 48 | + |
| 49 | +rm -rf dev |
| 50 | +expect_fail run_bob dev -c "$upload" --download=forced root |
| 51 | + |
| 52 | +# Remove audit trail. Such artifacts must be rejected. |
| 53 | +rm "$A" |
| 54 | +pushd "$scratch" |
| 55 | +tar xf "$SAVE" |
| 56 | +tar --pax-option bob-archive-vsn=1 -zcf "$A" content |
| 57 | +popd |
| 58 | + |
| 59 | +rm -rf dev |
| 60 | +expect_fail run_bob dev -c "$upload" --download=forced root |
| 61 | + |
| 62 | +# Add garbage in the middle. Must fail gracefully. |
| 63 | +len=$(stat -c %s "$SAVE") |
| 64 | +head -c $((len - 64)) "$SAVE" > "$A" |
| 65 | +echo -n asdf >> "$A" |
| 66 | +tail -c 60 "$SAVE" >> "$A" |
| 67 | + |
| 68 | +rm -rf dev |
| 69 | +expect_fail run_bob dev -c "$upload" --download=forced root |
0 commit comments