summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLuca BRUNO <luca.bruno@coreos.com>2021-06-22 10:42:36 +0000
committerLuca BRUNO <luca.bruno@coreos.com>2021-06-22 12:15:18 +0000
commit70a8f56ce134a718b9b09a7ca14de7513865e516 (patch)
treeda0e3ab7cf3e7a89d087f188955347f9f2d538e5 /tests
parent47b7b1efc27291a6e2a0f732ade7db310d377044 (diff)
downloadostree-70a8f56ce134a718b9b09a7ca14de7513865e516.tar.gz
lib/commit: respect SOURCE_DATE_EPOCH for commit timestamp
This tweaks `ostree_repo_write_commit` so that it checks for the envinroment variable `SOURCE_DATE_EPOCH` as a way to override the current time, which is used as the commit timestamp. Ref: https://reproducible-builds.org/docs/source-date-epoch/ Ref: https://reproducible-builds.org/specs/source-date-epoch/
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test-commit-timestamp.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test-commit-timestamp.sh b/tests/test-commit-timestamp.sh
new file mode 100755
index 00000000..7dbdbdfc
--- /dev/null
+++ b/tests/test-commit-timestamp.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+#
+# SPDX-License-Identifier: LGPL-2.0+
+
+set -euo pipefail
+
+. $(dirname $0)/libtest.sh
+TZ='UTC'
+LANG='C'
+
+echo "1..2"
+
+# Explicit timestamp via CLI flag.
+mkdir testrepo
+ostree_repo_init testrepo --mode="archive"
+mkdir testrepo-files
+cd testrepo-files
+echo first > firstfile
+cd ..
+${CMD_PREFIX} ostree --repo=./testrepo commit -b cli --timestamp='@1234567890' -s "cli timestamp"
+${CMD_PREFIX} ostree --repo=./testrepo show cli > show-cli.txt
+rm -rf testrepo testrepo-files
+assert_file_has_content_literal show-cli.txt 'Date: 2009-02-13 23:31:30 +0000'
+echo "ok commit with CLI timestamp"
+
+# Reproducible timestamp via env flag.
+mkdir testrepo
+ostree_repo_init testrepo --mode="archive"
+mkdir testrepo-files
+cd testrepo-files
+echo first > firstfile
+cd ..
+${CMD_PREFIX} SOURCE_DATE_EPOCH='1234567890' ostree --repo=./testrepo commit -b env -s "env timestamp"
+if (${CMD_PREFIX} SOURCE_DATE_EPOCH='invalid' ostree --repo=./testrepo commit -b env -s "invalid timestamp") 2> commit-invalid.txt; then
+ assert_not_reached "commit with invalid timestamp succeeded"
+fi
+if (${CMD_PREFIX} SOURCE_DATE_EPOCH='12345678901234567890' ostree --repo=./testrepo commit -b env -s "overflowing timestamp") 2> commit-overflowing.txt; then
+ assert_not_reached "commit with overflowing timestamp succeeded"
+fi
+${CMD_PREFIX} ostree --repo=./testrepo show env > show-env.txt
+rm -rf testrepo testrepo-files
+assert_file_has_content_literal commit-invalid.txt 'Failed to convert SOURCE_DATE_EPOCH'
+assert_file_has_content_literal commit-overflowing.txt 'Parsing SOURCE_DATE_EPOCH: Numerical result out of range'
+assert_file_has_content_literal show-env.txt 'Date: 2009-02-13 23:31:30 +0000'
+echo "ok commit with env timestamp"