diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-01-28 12:01:12 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2022-02-14 11:23:07 +0100 |
| commit | 36cb04df96623ffe8f1074172a4ed9e51bcf6e3a (patch) | |
| tree | 8b676397278b6335abb61bf50280594249094fa1 | |
| parent | ef6d127190fed307f1ca52883b460a7ff53b317d (diff) | |
git-authenticate: Test introductory commit signature verification.
These tests mimic similar tests already in 'tests/channels.scm', but
without using the higher-level 'authenticate-channel'.
* tests/git-authenticate.scm ("introductory commit, valid signature")
("introductory commit, missing signature")
("introductory commit, wrong signature"): New tests.
| -rw-r--r-- | tests/git-authenticate.scm | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/tests/git-authenticate.scm b/tests/git-authenticate.scm index f66ef191b09..6ec55fb2e59 100644 --- a/tests/git-authenticate.scm +++ b/tests/git-authenticate.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2020, 2022 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -20,12 +20,17 @@ | |||
| 20 | #:use-module (git) | 20 | #:use-module (git) |
| 21 | #:use-module (guix git) | 21 | #:use-module (guix git) |
| 22 | #:use-module (guix git-authenticate) | 22 | #:use-module (guix git-authenticate) |
| 23 | #:use-module ((guix channels) #:select (openpgp-fingerprint)) | ||
| 24 | #:use-module ((guix diagnostics) | ||
| 25 | #:select (formatted-message? formatted-message-arguments)) | ||
| 23 | #:use-module (guix openpgp) | 26 | #:use-module (guix openpgp) |
| 27 | #:use-module ((guix tests) #:select (random-text)) | ||
| 24 | #:use-module (guix tests git) | 28 | #:use-module (guix tests git) |
| 25 | #:use-module (guix tests gnupg) | 29 | #:use-module (guix tests gnupg) |
| 26 | #:use-module (guix build utils) | 30 | #:use-module (guix build utils) |
| 27 | #:use-module (srfi srfi-1) | 31 | #:use-module (srfi srfi-1) |
| 28 | #:use-module (srfi srfi-34) | 32 | #:use-module (srfi srfi-34) |
| 33 | #:use-module (srfi srfi-35) | ||
| 29 | #:use-module (srfi srfi-64) | 34 | #:use-module (srfi srfi-64) |
| 30 | #:use-module (rnrs bytevectors) | 35 | #:use-module (rnrs bytevectors) |
| 31 | #:use-module (rnrs io ports)) | 36 | #:use-module (rnrs io ports)) |
| @@ -327,4 +332,103 @@ | |||
| 327 | #:keyring-reference "master") | 332 | #:keyring-reference "master") |
| 328 | 'failed))))))) | 333 | 'failed))))))) |
| 329 | 334 | ||
| 335 | (unless (gpg+git-available?) (test-skip 1)) | ||
| 336 | (test-assert "introductory commit, valid signature" | ||
| 337 | (with-fresh-gnupg-setup (list %ed25519-public-key-file | ||
| 338 | %ed25519-secret-key-file) | ||
| 339 | (let ((fingerprint (key-fingerprint %ed25519-public-key-file))) | ||
| 340 | (with-temporary-git-repository directory | ||
| 341 | `((add "signer.key" ,(call-with-input-file %ed25519-public-key-file | ||
| 342 | get-string-all)) | ||
| 343 | (add ".guix-authorizations" | ||
| 344 | ,(object->string | ||
| 345 | `(authorizations (version 0) | ||
| 346 | ((,(key-fingerprint | ||
| 347 | %ed25519-public-key-file) | ||
| 348 | (name "Charlie")))))) | ||
| 349 | (commit "zeroth commit" (signer ,fingerprint)) | ||
| 350 | (add "a.txt" "A") | ||
| 351 | (commit "first commit" (signer ,fingerprint))) | ||
| 352 | (with-repository directory repository | ||
| 353 | (let ((commit0 (find-commit repository "zero")) | ||
| 354 | (commit1 (find-commit repository "first"))) | ||
| 355 | ;; COMMIT0 is signed with the right key, and COMMIT1 is fine. | ||
| 356 | (authenticate-repository repository | ||
| 357 | (commit-id commit0) | ||
| 358 | (openpgp-fingerprint fingerprint) | ||
| 359 | #:keyring-reference "master" | ||
| 360 | #:cache-key (random-text)))))))) | ||
| 361 | |||
| 362 | (unless (gpg+git-available?) (test-skip 1)) | ||
| 363 | (test-equal "introductory commit, missing signature" | ||
| 364 | 'intro-lacks-signature | ||
| 365 | (with-fresh-gnupg-setup (list %ed25519-public-key-file | ||
| 366 | %ed25519-secret-key-file) | ||
| 367 | (let ((fingerprint (key-fingerprint %ed25519-public-key-file))) | ||
| 368 | (with-temporary-git-repository directory | ||
| 369 | `((add "signer.key" ,(call-with-input-file %ed25519-public-key-file | ||
| 370 | get-string-all)) | ||
| 371 | (add ".guix-authorizations" | ||
| 372 | ,(object->string | ||
| 373 | `(authorizations (version 0) | ||
| 374 | ((,(key-fingerprint | ||
| 375 | %ed25519-public-key-file) | ||
| 376 | (name "Charlie")))))) | ||
| 377 | (commit "zeroth commit") ;unsigned! | ||
| 378 | (add "a.txt" "A") | ||
| 379 | (commit "first commit" (signer ,fingerprint))) | ||
| 380 | (with-repository directory repository | ||
| 381 | (let ((commit0 (find-commit repository "zero"))) | ||
| 382 | ;; COMMIT0 is not signed. | ||
| 383 | (guard (c ((formatted-message? c) | ||
| 384 | ;; Message like "commit ~a lacks a signature". | ||
| 385 | (and (equal? (formatted-message-arguments c) | ||
| 386 | (list (oid->string (commit-id commit0)))) | ||
| 387 | 'intro-lacks-signature))) | ||
| 388 | (authenticate-repository repository | ||
| 389 | (commit-id commit0) | ||
| 390 | (openpgp-fingerprint fingerprint) | ||
| 391 | #:keyring-reference "master" | ||
| 392 | #:cache-key (random-text))))))))) | ||
| 393 | |||
| 394 | (unless (gpg+git-available?) (test-skip 1)) | ||
| 395 | (test-equal "introductory commit, wrong signature" | ||
| 396 | 'wrong-intro-signing-key | ||
| 397 | (with-fresh-gnupg-setup (list %ed25519-public-key-file | ||
| 398 | %ed25519-secret-key-file | ||
| 399 | %ed25519-2-public-key-file | ||
| 400 | %ed25519-2-secret-key-file) | ||
| 401 | (let ((fingerprint (key-fingerprint %ed25519-public-key-file)) | ||
| 402 | (wrong-fingerprint (key-fingerprint %ed25519-2-public-key-file))) | ||
| 403 | (with-temporary-git-repository directory | ||
| 404 | `((add "signer1.key" ,(call-with-input-file %ed25519-public-key-file | ||
| 405 | get-string-all)) | ||
| 406 | (add "signer2.key" ,(call-with-input-file %ed25519-2-public-key-file | ||
| 407 | get-string-all)) | ||
| 408 | (add ".guix-authorizations" | ||
| 409 | ,(object->string | ||
| 410 | `(authorizations (version 0) | ||
| 411 | ((,(key-fingerprint | ||
| 412 | %ed25519-public-key-file) | ||
| 413 | (name "Charlie")))))) | ||
| 414 | (commit "zeroth commit" (signer ,wrong-fingerprint)) | ||
| 415 | (add "a.txt" "A") | ||
| 416 | (commit "first commit" (signer ,fingerprint))) | ||
| 417 | (with-repository directory repository | ||
| 418 | (let ((commit0 (find-commit repository "zero")) | ||
| 419 | (commit1 (find-commit repository "first"))) | ||
| 420 | ;; COMMIT0 is signed with the wrong key--not the one passed as the | ||
| 421 | ;; SIGNER argument to 'authenticate-repository'. | ||
| 422 | (guard (c ((formatted-message? c) | ||
| 423 | ;; Message like "commit ~a signed by ~a instead of ~a". | ||
| 424 | (and (equal? (formatted-message-arguments c) | ||
| 425 | (list (oid->string (commit-id commit0)) | ||
| 426 | wrong-fingerprint fingerprint)) | ||
| 427 | 'wrong-intro-signing-key))) | ||
| 428 | (authenticate-repository repository | ||
| 429 | (commit-id commit0) | ||
| 430 | (openpgp-fingerprint fingerprint) | ||
| 431 | #:keyring-reference "master" | ||
| 432 | #:cache-key (random-text))))))))) | ||
| 433 | |||
| 330 | (test-end "git-authenticate") | 434 | (test-end "git-authenticate") |
