diff options
author | Mark H Weaver <mhw@netris.org> | 2014-03-22 11:19:19 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2014-03-22 11:19:19 -0400 |
commit | 1eefbb2693f0f29f8f095af9f067240b85e735aa (patch) | |
tree | 35dbaa90de4bb52162b176725aa6ac10d8de0e4f /tests | |
parent | b1a01474ac4f5bae1f2689805105103742178c2b (diff) | |
parent | 6212b8e5d3f08a3ff05111167f0b190cea800c7c (diff) |
Merge branch 'master' into core-updates
Diffstat (limited to 'tests')
-rw-r--r-- | tests/guix-register.sh | 4 | ||||
-rw-r--r-- | tests/pk-crypto.scm | 42 | ||||
-rw-r--r-- | tests/store.scm | 34 |
3 files changed, 75 insertions, 5 deletions
diff --git a/tests/guix-register.sh b/tests/guix-register.sh index ee633af4f9..019a451b3b 100644 --- a/tests/guix-register.sh +++ b/tests/guix-register.sh @@ -84,8 +84,8 @@ guix-register --prefix "$new_store" "$closure" NIX_IGNORE_SYMLINK_STORE=1 NIX_STORE_DIR="$new_store_dir" NIX_STATE_DIR="$new_store$localstatedir" -NIX_LOG_DIR="$new_store$localstatedir/log/nix" -NIX_DB_DIR="$new_store$localstatedir/nix/db" +NIX_LOG_DIR="$new_store$localstatedir/log/guix" +NIX_DB_DIR="$new_store$localstatedir/guix/db" export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR NIX_STATE_DIR \ NIX_LOG_DIR NIX_DB_DIR diff --git a/tests/pk-crypto.scm b/tests/pk-crypto.scm index 6774dd4157..294c7f3df8 100644 --- a/tests/pk-crypto.scm +++ b/tests/pk-crypto.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -31,7 +31,7 @@ ;; Test the (guix pk-crypto) module. (define %key-pair - ;; Key pair that was generated with: + ;; RSA key pair that was generated with: ;; (generate-key (string->canonical-sexp "(genkey (rsa (nbits 4:1024)))")) ;; which takes a bit of time. "(key-data @@ -48,6 +48,20 @@ (q #00E9AD22F158060BC9AE3601DA623AFC60FFF3058795802CA92371C00097335CF9A23D7782DE353C9DBA93D7BB99E6A24A411107605E722481C5C191F80D7EB77F#) (u #59B45B95AE01A7A7370FAFDB08FE73A4793CE37F228961B09B1B1E7DDAD9F8D3E28F5C5E8B4B067E6B8E0BBF3F690B42991A79E46108DDCDA2514323A66964DE#))))") +(define %ecc-key-pair + ;; Ed25519 key pair generated with: + ;; (generate-key (string->canonical-sexp "(genkey (ecdsa (curve Ed25519) (flags rfc6979 transient)))")) + "(key-data + (public-key + (ecc + (curve Ed25519) + (q #94869C1B9E69DB8DD910B7F7F4D6E56A63A964A59AE8F90F6703ACDDF6F50C81#))) + (private-key + (ecc + (curve Ed25519) + (q #94869C1B9E69DB8DD910B7F7F4D6E56A63A964A59AE8F90F6703ACDDF6F50C81#) + (d #6EFB32D0B4EC6B3237B523539F1979379B82726AAA605EB2FBA6775B2B777B78#))))") + (test-begin "pk-crypto") (let ((sexps '("(foo bar)" @@ -148,11 +162,35 @@ (and (string=? algo "sha256") (bytevector=? value bv)))))) +(test-equal "key-type" + '(rsa ecc) + (map (compose key-type + (cut find-sexp-token <> 'public-key) + string->canonical-sexp) + (list %key-pair %ecc-key-pair))) + (test-assert "sign + verify" (let* ((pair (string->canonical-sexp %key-pair)) (secret (find-sexp-token pair 'private-key)) (public (find-sexp-token pair 'public-key)) (data (bytevector->hash-data + (sha256 (string->utf8 "Hello, world.")) + #:key-type (key-type public))) + (sig (sign data secret))) + (and (verify sig data public) + (not (verify sig + (bytevector->hash-data + (sha256 (string->utf8 "Hi!")) + #:key-type (key-type public)) + public))))) + +;; Ed25519 appeared in libgcrypt 1.6.0. +(test-skip (if (version>? (gcrypt-version) "1.6.0") 0 1)) +(test-assert "sign + verify, Ed25519" + (let* ((pair (string->canonical-sexp %ecc-key-pair)) + (secret (find-sexp-token pair 'private-key)) + (public (find-sexp-token pair 'public-key)) + (data (bytevector->hash-data (sha256 (string->utf8 "Hello, world.")))) (sig (sign data secret))) (and (verify sig data public) diff --git a/tests/store.scm b/tests/store.scm index 78023a423d..d23024bcbc 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -87,7 +87,39 @@ (%store-prefix) "/283gqy39v3g9dxjy26rynl0zls82fmcg-guile-2.0.7/bin/guile"))))) -(test-skip (if %store 0 11)) +(test-skip (if %store 0 13)) + +(test-assert "valid-path? live" + (let ((p (add-text-to-store %store "hello" "hello, world"))) + (valid-path? %store p))) + +(test-assert "valid-path? false" + (not (valid-path? %store + (string-append (%store-prefix) "/" + (make-string 32 #\e) "-foobar")))) + +(test-assert "valid-path? error" + (with-store s + (guard (c ((nix-protocol-error? c) #t)) + (valid-path? s "foo") + #f))) + +(test-assert "valid-path? recovery" + ;; Prior to Nix commit 51800e0 (18 Mar. 2014), the daemon would immediately + ;; close the connection after receiving a 'valid-path?' RPC with a non-store + ;; file name. See + ;; <http://article.gmane.org/gmane.linux.distributions.nixos/12411> for + ;; details. + (with-store s + (let-syntax ((true-if-error (syntax-rules () + ((_ exp) + (guard (c ((nix-protocol-error? c) #t)) + exp #f))))) + (and (true-if-error (valid-path? s "foo")) + (true-if-error (valid-path? s "bar")) + (true-if-error (valid-path? s "baz")) + (true-if-error (valid-path? s "chbouib")) + (valid-path? s (add-text-to-store s "valid" "yeah")))))) (test-assert "hash-part->path" (let ((p (add-text-to-store %store "hello" "hello, world"))) |