Skip to content

Commit e87dc1b

Browse files
committed
Exercise strict signal handling and additional archive/release refusal cases
1 parent e253936 commit e87dc1b

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎tests/acme.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ for scenario in free webroot foreign conflict invalid-nginx failed-certbot inter
5454
"$ACME_ROOT" "$DOMAIN" "$ACME_ROOT" >"$CERT_ROOT/renewal/$DOMAIN.conf"
5555
}
5656
set +e
57-
(ensure_certificate) >"$case_dir/manager.log" 2>&1
57+
(set -Eeuo pipefail; ensure_certificate) >"$case_dir/manager.log" 2>&1
5858
result=$?
5959
set -e
6060
if [[ ( $scenario == free || $scenario == webroot ) && $result != 0 ]]; then

‎tests/download.sh‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ result=$?
2424
set -e
2525
[[ $result != 0 && ! -e $SANDBOX/executed ]]
2626
metadata "$(sha256sum "$SANDBOX/source.tar.gz" | cut -d' ' -f1)"
27+
jq '.assets += .assets' "$TMP/release.json" >"$TMP/duplicate.json"
28+
mv "$TMP/duplicate.json" "$TMP/release.json"
29+
set +e
30+
(download_candidate) >"$SANDBOX/duplicate.log" 2>&1
31+
result=$?
32+
set -e
33+
[[ $result != 0 && ! -e $SANDBOX/executed ]]
34+
metadata "$(sha256sum "$SANDBOX/source.tar.gz" | cut -d' ' -f1)"
2735
download_candidate
2836
[[ -e $SANDBOX/executed ]]
2937
rm "$SANDBOX/executed" "$SANDBOX/archive/telemt"
@@ -35,7 +43,7 @@ set +e
3543
result=$?
3644
set -e
3745
[[ $result != 0 && ! -e $SANDBOX/executed ]]
38-
printf 'ok - digest mismatch and symlink archive never execute; valid digest passes\n'
46+
printf 'ok - digest mismatch, ambiguous asset and symlink archive never execute; valid digest passes\n'
3947

4048
# SC2016: preserve positional arguments for the generated candidate stub.
4149
# shellcheck disable=SC2016

‎tests/test_safety.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import importlib.util
33
import io
4+
import gzip
45
import json
56
import os
67
import tarfile
@@ -276,6 +277,30 @@ def test_unsafe_archive_variants_never_create_binary(self):
276277
with self.assertRaises(ValueError):
277278
s.extract_binary(archive, output)
278279
self.assertFalse(output.exists())
280+
member = tarfile.TarInfo('telemt')
281+
member.size = 128 * 1024 * 1024 + 1
282+
with gzip.open(archive, 'wb') as compressed:
283+
compressed.write(member.tobuf() + b'\0' * 1024)
284+
with self.assertRaises(ValueError):
285+
s.extract_binary(archive, output)
286+
self.assertFalse(output.exists())
287+
288+
@unittest.skipUnless(os.name == 'posix', 'Unix flags checked on Linux CI')
289+
def test_archive_output_symlink_does_not_overwrite_target(self):
290+
with tempfile.TemporaryDirectory() as tmp:
291+
root = Path(tmp)
292+
target = root/'target'
293+
target.write_bytes(b'unchanged')
294+
output = root/'binary'
295+
output.symlink_to(target)
296+
archive = root/'asset.tar.gz'
297+
with tarfile.open(archive, 'w:gz') as tar:
298+
member = tarfile.TarInfo('telemt')
299+
member.size = 7
300+
tar.addfile(member, io.BytesIO(b'fixture'))
301+
with self.assertRaises(OSError):
302+
s.extract_binary(archive, output)
303+
self.assertEqual(target.read_bytes(), b'unchanged')
279304

280305
@unittest.skipUnless(os.name == 'posix', 'Unix permissions checked on Linux CI')
281306
def test_symlink_and_writable_ancestor_refused(self):

0 commit comments

Comments
 (0)