[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#45253] [PATCH 1/6] tests: Check the build trace for hash mismatches
From: |
Ludovic Courtès |
Subject: |
[bug#45253] [PATCH 1/6] tests: Check the build trace for hash mismatches on substitutes. |
Date: |
Tue, 15 Dec 2020 10:57:25 +0100 |
* tests/store.scm ("substitute, corrupt output hash, build trace"): New
test.
---
tests/store.scm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/tests/store.scm b/tests/store.scm
index 38051bf5e5..7f1ec51875 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -787,6 +787,61 @@
(build-derivations s (list d))
#f))))))
+(test-assert "substitute, corrupt output hash, build trace"
+ ;; Likewise, and check the build trace.
+ (with-store s
+ (let* ((c "hello, world") ; contents of the output
+ (d (build-expression->derivation
+ s "corrupt-substitute"
+ `(mkdir %output)
+ #:guile-for-build
+ (package-derivation s %bootstrap-guile (%current-system))))
+ (o (derivation->output-path d)))
+ ;; Make sure we use 'guix substitute'.
+ (set-build-options s
+ #:print-build-trace #t
+ #:use-substitutes? #t
+ #:fallback? #f
+ #:substitute-urls (%test-substitute-urls))
+
+ (with-derivation-substitute d c
+ (sha256 => (make-bytevector 32 0)) ;select a hash that doesn't match C
+
+ (define output
+ (call-with-output-string
+ (lambda (port)
+ (parameterize ((current-build-output-port port))
+ (guard (c ((store-protocol-error? c) #t))
+ (build-derivations s (list d))
+ #f)))))
+
+ (define actual-hash
+ (let-values (((port get-hash)
+ (gcrypt:open-hash-port
+ (gcrypt:hash-algorithm gcrypt:sha256))))
+ (write-file-tree "foo" port
+ #:file-type+size
+ (lambda _
+ (values 'regular (string-length c)))
+ #:file-port
+ (lambda _
+ (open-input-string c)))
+ (close-port port)
+ (bytevector->nix-base32-string (get-hash))))
+
+ (define expected-hash
+ (bytevector->nix-base32-string (make-bytevector 32 0)))
+
+ (define mismatch
+ (string-append "@ hash-mismatch " o " sha256 "
+ expected-hash " " actual-hash "\n"))
+
+ (define failure
+ (string-append "@ substituter-failed " o))
+
+ (and (string-contains output mismatch)
+ (string-contains output failure))))))
+
(test-assert "substitute --fallback"
(with-store s
(let* ((t (random-text)) ; contents of the output
--
2.29.2
- [bug#45253] [PATCH 0/6] Pipeline substitute integrity check, deduplication, and canonicalization, Ludovic Courtès, 2020/12/15
- [bug#45253] [PATCH 1/6] tests: Check the build trace for hash mismatches on substitutes.,
Ludovic Courtès <=
- [bug#45253] [PATCH 5/6] tests: Make sure substituted items are deduplicated., Ludovic Courtès, 2020/12/15
- [bug#45253] [PATCH 4/6] daemon: Do not reset timestamps and permissions on substituted items., Ludovic Courtès, 2020/12/15
- [bug#45253] [PATCH 6/6] daemon: Delegate deduplication to 'guix substitute'., Ludovic Courtès, 2020/12/15
- [bug#45253] [PATCH 3/6] tests: Check the mtime and permissions of substituted items., Ludovic Courtès, 2020/12/15
- [bug#45253] [PATCH 2/6] daemon: Let 'guix substitute' perform hash checks., Ludovic Courtès, 2020/12/15
- [bug#45253] [PATCH 0/6] Pipeline substitute integrity check, deduplication, and canonicalization, Ludovic Courtès, 2020/12/15
- bug#45253: [PATCH 0/6] Pipeline substitute integrity check, deduplication, and canonicalization, Ludovic Courtès, 2020/12/19