2024-05-28 19:43:04 +03:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2021-05-27 14:25:25 +03:00
|
|
|
|
source common.sh
|
|
|
|
|
|
|
|
|
|
BINARY_CACHE=file://$cacheDir
|
|
|
|
|
|
|
|
|
|
getHash() {
|
|
|
|
|
basename "$1" | cut -d '-' -f 1
|
|
|
|
|
}
|
|
|
|
|
getRemoteNarInfo () {
|
|
|
|
|
echo "$cacheDir/$(getHash "$1").narinfo"
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 01:10:08 +03:00
|
|
|
|
cat <<EOF > "$TEST_HOME"/good.txt
|
2021-05-27 14:25:25 +03:00
|
|
|
|
I’m a good path
|
|
|
|
|
EOF
|
|
|
|
|
|
2024-08-02 01:10:08 +03:00
|
|
|
|
cat <<EOF > "$TEST_HOME"/bad.txt
|
2021-05-27 14:25:25 +03:00
|
|
|
|
I’m a bad path
|
|
|
|
|
EOF
|
|
|
|
|
|
2024-08-02 01:10:08 +03:00
|
|
|
|
good=$(nix-store --add "$TEST_HOME"/good.txt)
|
|
|
|
|
bad=$(nix-store --add "$TEST_HOME"/bad.txt)
|
2021-05-27 14:25:25 +03:00
|
|
|
|
nix copy --to "$BINARY_CACHE" "$good"
|
|
|
|
|
nix copy --to "$BINARY_CACHE" "$bad"
|
|
|
|
|
nix-collect-garbage >/dev/null 2>&1
|
|
|
|
|
|
|
|
|
|
# Falsifying the narinfo file for '$good'
|
|
|
|
|
goodPathNarInfo=$(getRemoteNarInfo "$good")
|
|
|
|
|
badPathNarInfo=$(getRemoteNarInfo "$bad")
|
|
|
|
|
for fieldName in URL FileHash FileSize NarHash NarSize; do
|
|
|
|
|
sed -i "/^$fieldName/d" "$goodPathNarInfo"
|
|
|
|
|
grep -E "^$fieldName" "$badPathNarInfo" >> "$goodPathNarInfo"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Copying back '$good' from the binary cache. This should fail as it is
|
|
|
|
|
# corrupted
|
|
|
|
|
if nix copy --from "$BINARY_CACHE" "$good"; then
|
|
|
|
|
fail "Importing a path with a wrong CA field should fail"
|
|
|
|
|
fi
|