diff options
author | Jakub Kądziołka <[email protected]> | 2020-06-22 02:56:22 +0200 |
---|---|---|
committer | Jakub Kądziołka <[email protected]> | 2020-06-22 02:56:22 +0200 |
commit | 43bc7855113bd725d464dd9eaa1e54e78edfaab1 (patch) | |
tree | 2655f85e9946ececdb4fb052c2f3e31375c41e0f /tests | |
parent | 0c4e39c0b025fb23a2e5df46434fc96112bb6d6c (diff) | |
parent | f8a28b6c6d4fe7642b7df35e8518e3c0174ede74 (diff) |
Merge branch 'master' into core-updates
Diffstat (limited to 'tests')
-rw-r--r-- | tests/channels.scm | 126 | ||||
-rw-r--r-- | tests/git-authenticate.scm | 27 | ||||
-rw-r--r-- | tests/guix-environment-container.sh | 2 | ||||
-rw-r--r-- | tests/guix-repl.sh | 84 |
4 files changed, 210 insertions, 29 deletions
diff --git a/tests/channels.scm b/tests/channels.scm index 3b141428c8..5f13a48ec1 100644 --- a/tests/channels.scm +++ b/tests/channels.scm @@ -31,15 +31,28 @@ #:use-module ((guix build utils) #:select (which)) #:use-module (git) #:use-module (guix git) + #:use-module (guix git-authenticate) + #:use-module (guix openpgp) #:use-module (guix tests git) + #:use-module (guix tests gnupg) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (srfi srfi-64) + #:use-module (rnrs bytevectors) + #:use-module (rnrs io ports) #:use-module (ice-9 control) #:use-module (ice-9 match)) +(define (gpg+git-available?) + (and (which (git-command)) + (which (gpg-command)) (which (gpgconf-command)))) + +(define commit-id-string + (compose oid->string commit-id)) + + (test-begin "channels") (define* (make-instance #:key @@ -199,12 +212,12 @@ (commit (oid->string (commit-id commit2))))) (old (channel (inherit spec) (commit (oid->string (commit-id commit1)))))) - (define (validate-pull channel current instance relation) + (define (validate-pull channel current commit relation) (return (and (eq? channel old) (string=? (oid->string (commit-id commit2)) current) (string=? (oid->string (commit-id commit1)) - (channel-instance-commit instance)) + commit) relation))) (with-store store @@ -389,4 +402,113 @@ (channel-news-for-commit channel commit5 commit1)) '(#f "tag-for-first-news-entry"))))))) +(unless (gpg+git-available?) (test-skip 1)) +(test-assert "authenticate-channel, wrong first commit signer" + (with-fresh-gnupg-setup (list %ed25519-public-key-file + %ed25519-secret-key-file + %ed25519bis-public-key-file + %ed25519bis-secret-key-file) + (with-temporary-git-repository directory + `((add ".guix-channel" + ,(object->string + '(channel (version 0) + (keyring-reference "master")))) + (add ".guix-authorizations" + ,(object->string + `(authorizations (version 0) + ((,(key-fingerprint + %ed25519-public-key-file) + (name "Charlie")))))) + (add "signer.key" ,(call-with-input-file %ed25519-public-key-file + get-string-all)) + (commit "first commit" + (signer ,(key-fingerprint %ed25519-public-key-file)))) + (with-repository directory repository + (let* ((commit1 (find-commit repository "first")) + (intro ((@@ (guix channels) make-channel-introduction) + (commit-id-string commit1) + (openpgp-public-key-fingerprint + (read-openpgp-packet + %ed25519bis-public-key-file)) ;different key + #f)) ;no signature + (channel (channel (name 'example) + (url (string-append "file://" directory)) + (introduction intro)))) + (guard (c ((message? c) + (->bool (string-contains (condition-message c) + "initial commit")))) + (authenticate-channel channel directory + (commit-id-string commit1) + #:keyring-reference-prefix "") + 'failed)))))) + +(unless (gpg+git-available?) (test-skip 1)) +(test-assert "authenticate-channel, .guix-authorizations" + (with-fresh-gnupg-setup (list %ed25519-public-key-file + %ed25519-secret-key-file + %ed25519bis-public-key-file + %ed25519bis-secret-key-file) + (with-temporary-git-repository directory + `((add ".guix-channel" + ,(object->string + '(channel (version 0) + (keyring-reference "channel-keyring")))) + (add ".guix-authorizations" + ,(object->string + `(authorizations (version 0) + ((,(key-fingerprint + %ed25519-public-key-file) + (name "Charlie")))))) + (commit "zeroth commit") + (add "a.txt" "A") + (commit "first commit" + (signer ,(key-fingerprint %ed25519-public-key-file))) + (add "b.txt" "B") + (commit "second commit" + (signer ,(key-fingerprint %ed25519-public-key-file))) + (add "c.txt" "C") + (commit "third commit" + (signer ,(key-fingerprint %ed25519bis-public-key-file))) + (branch "channel-keyring") + (checkout "channel-keyring") + (add "signer.key" ,(call-with-input-file %ed25519-public-key-file + get-string-all)) + (add "other.key" ,(call-with-input-file %ed25519bis-public-key-file + get-string-all)) + (commit "keyring commit") + (checkout "master")) + (with-repository directory repository + (let* ((commit1 (find-commit repository "first")) + (commit2 (find-commit repository "second")) + (commit3 (find-commit repository "third")) + (intro ((@@ (guix channels) make-channel-introduction) + (commit-id-string commit1) + (openpgp-public-key-fingerprint + (read-openpgp-packet + %ed25519-public-key-file)) + #f)) ;no signature + (channel (channel (name 'example) + (url (string-append "file://" directory)) + (introduction intro)))) + ;; COMMIT1 and COMMIT2 are fine. + (and (authenticate-channel channel directory + (commit-id-string commit2) + #:keyring-reference-prefix "") + + ;; COMMIT3 is signed by an unauthorized key according to its + ;; parent's '.guix-authorizations' file. + (guard (c ((unauthorized-commit-error? c) + (and (oid=? (git-authentication-error-commit c) + (commit-id commit3)) + (bytevector=? + (openpgp-public-key-fingerprint + (unauthorized-commit-error-signing-key c)) + (openpgp-public-key-fingerprint + (read-openpgp-packet + %ed25519bis-public-key-file)))))) + (authenticate-channel channel directory + (commit-id-string commit3) + #:keyring-reference-prefix "") + 'failed))))))) + (test-end "channels") diff --git a/tests/git-authenticate.scm b/tests/git-authenticate.scm index 97990acaea..865481f7c5 100644 --- a/tests/git-authenticate.scm +++ b/tests/git-authenticate.scm @@ -32,31 +32,6 @@ ;; Test the (guix git-authenticate) tools. -(define %ed25519-public-key-file - (search-path %load-path "tests/ed25519.key")) -(define %ed25519-secret-key-file - (search-path %load-path "tests/ed25519.sec")) -(define %ed25519bis-public-key-file - (search-path %load-path "tests/ed25519bis.key")) -(define %ed25519bis-secret-key-file - (search-path %load-path "tests/ed25519bis.sec")) - -(define (read-openpgp-packet file) - (get-openpgp-packet - (open-bytevector-input-port - (call-with-input-file file read-radix-64)))) - -(define key-fingerprint - (compose openpgp-format-fingerprint - openpgp-public-key-fingerprint - read-openpgp-packet)) - -(define (key-id file) - (define id - (openpgp-public-key-id (read-openpgp-packet))) - - (string-pad (number->string id 16) 16 #\0)) - (define (gpg+git-available?) (and (which (git-command)) (which (gpg-command)) (which (gpgconf-command)))) @@ -81,7 +56,7 @@ #:keyring-reference "master") 'failed))))) -(unless (which (git-command)) (test-skip 1)) +(unless (which (gpg+git-available?)) (test-skip 1)) (test-assert "signed commits, SHA1 signature" (with-fresh-gnupg-setup (list %ed25519-public-key-file %ed25519-secret-key-file) diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index d313f2e734..45264d4978 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh @@ -24,7 +24,7 @@ set -e guix environment --version -if ! guile -c '((@@ (guix scripts environment) assert-container-features))' +if ! guile -c '((@ (guix scripts environment) assert-container-features))' then # User containers are not supported; skip this test. exit 77 diff --git a/tests/guix-repl.sh b/tests/guix-repl.sh new file mode 100644 index 0000000000..e1c2b8241f --- /dev/null +++ b/tests/guix-repl.sh @@ -0,0 +1,84 @@ +# GNU Guix --- Functional package management for GNU +# Copyright © 2020 Simon Tournier <[email protected]> +# Copyright © 2020 Konrad Hinsen <[email protected]> +# +# This file is part of GNU Guix. +# +# GNU Guix is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Guix is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +# +# Test the `guix repl' command-line utility. +# + +guix repl --version + +test_directory="`mktemp -d`" +export test_directory +trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT + +tmpfile="$test_directory/foo.scm" +rm -f "$tmpfile" +trap 'rm -f "$tmpfile"' EXIT + +module_dir="t-guix-repl-$$" +mkdir "$module_dir" +trap 'rm -rf "$module_dir"' EXIT + + +cat > "$tmpfile"<<EOF +(use-modules (guix packages) + (gnu packages base)) + +(format #t "~a\n" (package-name coreutils)) +EOF + +test "`guix repl "$tmpfile"`" = "coreutils" + + +cat > "$module_dir/foo.scm"<<EOF +(define-module (foo) + #:use-module (guix packages) + #:use-module (gnu packages base)) + +(define-public dummy + (package (inherit hello) + (name "dummy") + (version "42") + (synopsis "dummy package") + (description "dummy package. Only used for testing purposes."))) +EOF + +cat > "$tmpfile"<<EOF +(use-modules (guix packages) + (foo)) + +(format #t "~a\n" (package-version dummy)) +EOF + +test "`guix repl "$tmpfile" -L "$module_dir"`" = "42" + +cat > "$tmpfile"<<EOF +(format #t "~a\n" (cdr (command-line))) +EOF + +test "`guix repl -- "$tmpfile" -a b --input=foo.txt`" = "(-a b --input=foo.txt)" + +cat > "$tmpfile"<<EOF +#!$(type -P env) -S guix repl -- +!# +(format #t "~a\n" (cdr (command-line))) +EOF +chmod 755 $tmpfile + +test "`"$tmpfile" -a b --input=foo.txt`" = "(-a b --input=foo.txt)" |