1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-publish)
20 #:use-module (guix scripts publish)
21 #:use-module (guix tests)
22 #:use-module (guix config)
23 #:use-module (guix utils)
24 #:use-module (guix hash)
25 #:use-module (guix store)
26 #:use-module (guix base32)
27 #:use-module (guix base64)
28 #:use-module ((guix serialization) #:select (restore-file))
29 #:use-module (guix pk-crypto)
30 #:use-module (web client)
31 #:use-module (web response)
32 #:use-module (rnrs bytevectors)
33 #:use-module (srfi srfi-1)
34 #:use-module (srfi srfi-26)
35 #:use-module (srfi srfi-64)
36 #:use-module (ice-9 match)
37 #:use-module (ice-9 rdelim))
40 (open-connection-for-tests))
42 (define %reference (add-text-to-store %store "ref" "foo"))
44 (define %item (add-text-to-store %store "item" "bar" (list %reference)))
46 (define (http-get-body uri)
47 (call-with-values (lambda () (http-get uri))
48 (lambda (response body) body)))
50 (define (publish-uri route)
51 (string-append "http://localhost:6789" route))
53 ;; Run a local publishing server in a separate thread.
56 (guix-publish "--port=6789"))) ; attempt to avoid port collision
58 ;; Wait until the server is accepting connections.
59 (let ((conn (socket PF_INET SOCK_STREAM 0)))
61 (unless (false-if-exception
62 (connect conn AF_INET (inet-pton AF_INET "127.0.0.1") 6789))
65 (test-begin "publish")
67 (test-equal "/nix-cache-info"
68 (format #f "StoreDir: ~a\nWantMassQuery: 0\nPriority: 100\n"
70 (http-get-body (publish-uri "/nix-cache-info")))
72 (test-equal "/*.narinfo"
73 (let* ((info (query-path-info %store %item))
84 (bytevector->nix-base32-string
85 (path-info-hash info))
86 (path-info-nar-size info)
87 (basename (first (path-info-references info)))))
88 (signature (base64-encode
90 (canonical-sexp->string
91 ((@@ (guix scripts publish) signed-string)
93 (format #f "~aSignature: 1;~a;~a~%"
94 unsigned-info (gethostname) signature))
98 (string-append "/" (store-path-hash-part %item) ".narinfo")))))
102 (call-with-temporary-output-file
104 (let ((nar (utf8->string
107 (string-append "/nar/" (basename %item)))))))
108 (call-with-input-string nar (cut restore-file <> temp)))
109 (call-with-input-file temp read-string))))
114 (exit (= (test-runner-fail-count (test-runner-current)) 0))