File: substitute-with-invalid-ca.sh

package info (click to toggle)
nix 2.8.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,304 kB
  • sloc: cpp: 62,562; sh: 7,853; yacc: 680; perl: 606; xml: 410; lex: 314; makefile: 73; ansic: 57; sql: 49; python: 22; exp: 3; ruby: 1
file content (38 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
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
source common.sh

BINARY_CACHE=file://$cacheDir

getHash() {
    basename "$1" | cut -d '-' -f 1
}
getRemoteNarInfo () {
    echo "$cacheDir/$(getHash "$1").narinfo"
}

cat <<EOF > $TEST_HOME/good.txt
I’m a good path
EOF

cat <<EOF > $TEST_HOME/bad.txt
I’m a bad path
EOF

good=$(nix-store --add $TEST_HOME/good.txt)
bad=$(nix-store --add $TEST_HOME/bad.txt)
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