Files
lix/tests/functional2/eval/fetchers/test_tarball_ttl.py
T
eldritch horrors 1657d0eb47 f2: add mark for nix settings defaults and use it
this fixes a large portion of tests currently marked no_daemon. most of
them only needed to set some trusted settings, which is easily done now

Change-Id: Id5a5ee94951cdc92bddd2264c738ca4f98980c8b
2026-07-12 20:28:05 +02:00

81 lines
2.4 KiB
Python

from pathlib import Path
import pytest
from testlib.fixtures.nix import Nix
@pytest.mark.parametrize("sha", ["", "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="])
def test_locked_tarball_ttl(nix: Nix, sha: str):
files = nix.env.dirs.home
(files / "file").write_text("contents")
res = (
nix.nix(
[
"eval",
"--expr",
f'builtins.fetchurl {{ url = "file://{files}/file"; sha256 = "{sha}"; }}',
],
flake=True,
)
.run()
.expect(102)
)
assert "hash mismatch" in res.stderr_plain
assert "sha256-0bKln76n4gB3r5+Rsn6V6GUGGycL4D/1Oas7c1h4gug=" in res.stderr_plain
# empty or zero hash should count as not locked and be refetched
(files / "file").write_text("other contents")
res = (
nix.nix(
[
"eval",
*["--tarball-ttl", "0"],
"--expr",
f'builtins.fetchurl {{ url = "file://{files}/file"; sha256 = "{sha}"; }}',
],
flake=True,
)
.run()
.expect(102)
)
assert "hash mismatch" in res.stderr_plain
assert "sha256-Ql7LXhAAyVRbEF8VR8bW8D0c1LONlNRX7AMpB+i1EHk=" in res.stderr_plain
# hash-locked tarballs should *not* be refetched as long as their store path exists
(files / "file").write_text("different contents")
res = (
nix.nix(
[
"eval",
*["--tarball-ttl", "0"],
"--raw",
"--expr",
f'builtins.fetchurl {{ url = "file://{files}/file"; sha256 = "sha256-Ql7LXhAAyVRbEF8VR8bW8D0c1LONlNRX7AMpB+i1EHk="; }}',
],
flake=True,
)
.run()
.ok()
)
path = Path(res.stdout_plain)
assert path.read_text() == "other contents"
# but store paths that went away are always refetched and checked
nix.nix(["store", "delete", path], flake=True).run().ok()
res = (
nix.nix(
[
"eval",
"--expr",
f'builtins.fetchurl {{ url = "file://{files}/file"; sha256 = "sha256-Ql7LXhAAyVRbEF8VR8bW8D0c1LONlNRX7AMpB+i1EHk="; }}',
],
flake=True,
)
.run()
.expect(102)
)
assert "hash mismatch" in res.stderr_plain
assert "sha256-DKElpSdXX/9t9X/8f4IfbwQccBptZZqVy1/6JW6uFoY=" in res.stderr_plain