tests/nixos: make the tarball-flakes test better reflect real use cases
In most real world cases, the Link header is set on the redirect, not on
the final file. This regressed in Lix earlier and while new unit tests
were added to cover it, this integration test should probably have also
caught it.
Change-Id: I2a9d8d952fff36f2c22cfd751451c2b523f7045c
This commit is contained in:
parent
c55e93ca23
commit
a3256a9375
|
@ -5,7 +5,7 @@ let
|
||||||
|
|
||||||
root = pkgs.runCommand "nixpkgs-flake" {}
|
root = pkgs.runCommand "nixpkgs-flake" {}
|
||||||
''
|
''
|
||||||
mkdir -p $out/stable
|
mkdir -p $out/{stable,tags}
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
dir=nixpkgs-${nixpkgs.shortRev}
|
dir=nixpkgs-${nixpkgs.shortRev}
|
||||||
|
@ -14,9 +14,13 @@ let
|
||||||
find $dir -print0 | xargs -0 touch -h -t ${builtins.substring 0 12 nixpkgs.lastModifiedDate}.${builtins.substring 12 2 nixpkgs.lastModifiedDate} --
|
find $dir -print0 | xargs -0 touch -h -t ${builtins.substring 0 12 nixpkgs.lastModifiedDate}.${builtins.substring 12 2 nixpkgs.lastModifiedDate} --
|
||||||
tar cfz $out/stable/${nixpkgs.rev}.tar.gz $dir --hard-dereference
|
tar cfz $out/stable/${nixpkgs.rev}.tar.gz $dir --hard-dereference
|
||||||
|
|
||||||
echo 'Redirect "/latest.tar.gz" "/stable/${nixpkgs.rev}.tar.gz"' > $out/.htaccess
|
# Set the "Link" header on the redirect but not the final response to
|
||||||
|
# simulate an S3-like serving environment where the final host cannot set
|
||||||
echo 'Header set Link "<http://localhost/stable/${nixpkgs.rev}.tar.gz?rev=${nixpkgs.rev}&revCount=1234>; rel=\"immutable\""' > $out/stable/.htaccess
|
# arbitrary headers.
|
||||||
|
cat >$out/tags/.htaccess <<EOF
|
||||||
|
Redirect "/tags/latest.tar.gz" "/stable/${nixpkgs.rev}.tar.gz"
|
||||||
|
Header always set Link "<http://localhost/stable/${nixpkgs.rev}.tar.gz?rev=${nixpkgs.rev}&revCount=1234>; rel=\"immutable\""
|
||||||
|
EOF
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
|
|
||||||
|
@ -59,7 +63,7 @@ in
|
||||||
|
|
||||||
machine.wait_for_unit("httpd.service")
|
machine.wait_for_unit("httpd.service")
|
||||||
|
|
||||||
out = machine.succeed("nix flake metadata --json http://localhost/latest.tar.gz")
|
out = machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz")
|
||||||
print(out)
|
print(out)
|
||||||
info = json.loads(out)
|
info = json.loads(out)
|
||||||
|
|
||||||
|
@ -74,14 +78,14 @@ in
|
||||||
assert rev_count == 1234, f"{rev_count=} != 1234"
|
assert rev_count == 1234, f"{rev_count=} != 1234"
|
||||||
|
|
||||||
# Check that fetching with rev/revCount/narHash succeeds.
|
# Check that fetching with rev/revCount/narHash succeeds.
|
||||||
machine.succeed("nix flake metadata --json http://localhost/latest.tar.gz?rev=" + revision)
|
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=" + revision)
|
||||||
machine.succeed("nix flake metadata --json http://localhost/latest.tar.gz?revCount=" + str(rev_count))
|
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=" + str(rev_count))
|
||||||
machine.succeed("nix flake metadata --json http://localhost/latest.tar.gz?narHash=" + info["locked"]["narHash"])
|
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=" + info["locked"]["narHash"])
|
||||||
|
|
||||||
# Check that fetching fails if we provide incorrect attributes.
|
# Check that fetching fails if we provide incorrect attributes.
|
||||||
machine.fail("nix flake metadata --json http://localhost/latest.tar.gz?rev=493300eb13ae6fb387fbd47bf54a85915acc31c0")
|
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=493300eb13ae6fb387fbd47bf54a85915acc31c0")
|
||||||
machine.fail("nix flake metadata --json http://localhost/latest.tar.gz?revCount=789")
|
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=789")
|
||||||
machine.fail("nix flake metadata --json http://localhost/latest.tar.gz?narHash=sha256-tbudgBSg+bHWHiHnlteNzN8TUvI80ygS9IULh4rklEw=")
|
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=sha256-tbudgBSg+bHWHiHnlteNzN8TUvI80ygS9IULh4rklEw=")
|
||||||
'';
|
'';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue