aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021 Simon South <simon@simonsouth.net>
;;;
;;; 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/>.

;;;
;;; The Transmission Daemon service.
;;;

(define-module (gnu tests file-sharing)
  #:use-module (gnu packages bittorrent)
  #:use-module (gnu services)
  #:use-module (gnu services file-sharing)
  #:use-module (gnu services networking)
  #:use-module (gnu system vm)
  #:use-module (gnu tests)
  #:use-module (guix gexp)
  #:export (%test-transmission-daemon))

(define %transmission-daemon-user "transmission")
(define %transmission-daemon-group "transmission")

(define %transmission-daemon-config-dir "/var/lib/transmission-daemon")
(define %transmission-daemon-watch-dir
  (string-append %transmission-daemon-config-dir "/watch"))
(define %transmission-daemon-incomplete-dir
  (string-append %transmission-daemon-config-dir "/incomplete"))

(define %transmission-daemon-settings-file
  (string-append %transmission-daemon-config-dir "/settings.json"))

(define %transmission-daemon-peer-port 51000) ; default is 51413

(define %transmission-daemon-rpc-port 9999)   ; default is 9091
(define %transmission-daemon-rpc-username "test-username")
(define %transmission-daemon-rpc-password "test-password")

(define %transmission-daemon-test-configuration
  (transmission-daemon-configuration
   (incomplete-dir-enabled? #t)
   (incomplete-dir %transmission-daemon-incomplete-dir)

   (watch-dir-enabled? #t)
   (watch-dir %transmission-daemon-watch-dir)

   (peer-port-random-on-start? #f)
   (peer-port %transmission-daemon-peer-port)

   (rpc-enabled? #t)
   (rpc-port %transmission-daemon-rpc-port)
   (rpc-whitelist-enabled? #f)
   (rpc-authentication-required? #t)
   (rpc-username %transmission-daemon-rpc-username)
   (rpc-password (transmission-password-hash %transmission-daemon-rpc-password
                                             "yEK0q3.X"))))

(define (run-transmission-daemon-test)
  (define os
    (marionette-operating-system
     (simple-operating-system
      (service dhcp-client-service-type)
      (service transmission-daemon-service-type
               %transmission-daemon-test-configuration))
     #:imported-modules '((gnu services herd)
                          (json parser))
     #:requirements '(transmission-daemon)))

  (define test
    (with-imported-modules '((gnu build marionette))
      #~(begin
          (use-modules (gnu build marionette)
                       (srfi srfi-64))

          (define marionette
            (make-marionette
             (list #$(virtual-machine
                      (operating-system os)
                      (port-forwardings
                       `((9091 . ,%transmission-daemon-rpc-port)))))))

          (test-runner-current (system-test-runner #$output))
          (test-begin "transmission-daemon")

          ;; Make sure the "transmission" user and group have been created.
          (test-assert "\"transmission\" user exists"
            (marionette-eval
             '(begin
                (getpwnam #$%transmission-daemon-user)
                #t)
             marionette))
          (test-assert "\"transmission\" group exists"
            (marionette-eval
             '(begin
                (getgrnam #$%transmission-daemon-group)
                #t)
             marionette))

          ;; Make sure Transmission Daemon's configuration directory has been
          ;; created with the correct ownership and permissions.
          (test-assert "configuration directory exists"
            (marionette-eval
             '(eq? (stat:type (stat #$%transmission-daemon-config-dir))
                   'directory)
             marionette))
          (test-assert "configuration directory has correct ownership"
            (marionette-eval
             '(let ((config-dir (stat #$%transmission-daemon-config-dir))
                    (transmission-user (getpwnam #$%transmission-daemon-user)))
                (and (eqv? (stat:uid config-dir)
                           (passwd:uid transmission-user))
                     (eqv? (stat:gid config-dir)
                           (passwd:gid transmission-user))))
             marionette))
          (test-assert "configuration directory has expected permissions"
            (marionette-eval
             '(eqv? (stat:perms (stat #$%transmission-daemon-config-dir))
                    #o750)
             marionette))

          ;; Make sure the incomplete-downloads and watch directories have been
          ;; created with the correct ownership and permissions.
          (test-assert "incomplete-downloads directory exists"
            (marionette-eval
             '(eq? (stat:type (stat #$%transmission-daemon-incomplete-dir))
                   'directory)
             marionette))
          (test-assert "incomplete-downloads directory has correct ownership"
            (marionette-eval
             '(let ((incomplete-dir
                     (stat #$%transmission-daemon-incomplete-dir))
                    (transmission-user
                     (getpwnam #$%transmission-daemon-user)))
                (and (eqv? (stat:uid incomplete-dir)
                           (passwd:uid transmission-user))
                     (eqv? (stat:gid incomplete-dir)
                           (passwd:gid transmission-user))))
             marionette))
          (test-assert
              "incomplete-downloads directory has expected permissions"
            (marionette-eval
             '(eqv? (stat:perms (stat #$%transmission-daemon-incomplete-dir))
                    #o750)
             marionette))

          (test-assert "watch directory exists"
            (marionette-eval
             '(eq? (stat:type (stat #$%transmission-daemon-watch-dir))
                   'directory)
             marionette))
          (test-assert "watch directory has correct ownership"
            (marionette-eval
             '(let ((watch-dir (stat #$%transmission-daemon-watch-dir))
                    (transmission-user (getpwnam #$%transmission-daemon-user)))
                (and (eqv? (stat:uid watch-dir)
                           (passwd:uid transmission-user))
                     (eqv? (stat:gid watch-dir)
                           (passwd:gid transmission-user))))
             marionette))
          (test-assert "watch directory has expected permissions"
            (marionette-eval
             '(eqv? (stat:perms (stat #$%transmission-daemon-watch-dir))
                    #o770)
             marionette))

          ;; Make sure the settings file has been created and appears valid.
          (test-assert "settings file exists"
            (marionette-eval
             '(file-exists? #$%transmission-daemon-settings-file)
             marionette))
          (test-assert "settings file is valid JSON"
            (marionette-eval
             '(begin
                (use-modules (json parser))
                (with-input-from-file #$%transmission-daemon-settings-file
                  (lambda ()
                    (json->scm)))
                #t)
             marionette))
          (test-assert "settings file contains a non-empty JSON object"
            (marionette-eval
             '(begin
                (use-modules (json parser)
                             (srfi srfi-1))
                (let ((settings (with-input-from-file
                                    #$%transmission-daemon-settings-file
                                  (lambda ()
                                    (json->scm)))))
                  (and (list? settings)
                       (not (null? settings))
                       (every pair? settings))))
             marionette))

          ;; Make sure Transmission Daemon is running.
          (test-assert "transmission-daemon is running"
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (live-service-running
                 (find (lambda (live-service)
                         (memq 'transmission-daemon
                               (live-service-provision live-service)))
                       (current-services))))
             marionette))

          ;; Make sure the daemon is listening for peer connections.
          (test-assert "transmission-daemon is listening for peers"
            (wait-for-tcp-port #$%transmission-daemon-peer-port marionette))

          ;; Make sure the daemon is listening for RPC-client connections.
          (test-assert "transmission-daemon is listening for RPC clients"
            (wait-for-tcp-port #$%transmission-daemon-rpc-port marionette))

          ;; Make sure the RPC-authentication settings are honored.
          (test-assert "transmission-daemon requires RPC authentication"
            (let ((transmission-remote
                   (string-append #+transmission "/bin/transmission-remote")))
              (with-error-to-port (%make-void-port "w")
                (lambda ()
                  (not (zero? (system* transmission-remote
                                       "--session-info")))))))
          (test-assert "transmission-daemon rejects incorrect RPC credentials"
            (let ((transmission-remote
                   (string-append #+transmission "/bin/transmission-remote"))
                  (wrong-auth-string
                   (string-append #$%transmission-daemon-rpc-username
                                  ":"
                                  "wrong-"
                                  #$%transmission-daemon-rpc-password)))
              (with-error-to-port (%make-void-port "w")
                (lambda ()
                  (not (zero? (system* transmission-remote
                                       "--auth" wrong-auth-string
                                       "--session-info")))))))
          (test-assert "transmission-daemon accepts correct RPC credentials"
            (let ((transmission-remote
                   (string-append #+transmission "/bin/transmission-remote"))
                  (auth-string
                   (string-append #$%transmission-daemon-rpc-username
                                  ":"
                                  #$%transmission-daemon-rpc-password)))
              (with-output-to-port (%make-void-port "w")
                (lambda ()
                  (zero? (system* transmission-remote
                                  "--auth" auth-string
                                  "--session-info"))))))

          (test-end))))

  (gexp->derivation "transmission-daemon-test" test))

(define %test-transmission-daemon
  (system-test
   (name "transmission-daemon")
   (description "Test a running Transmission Daemon service.")
   (value (run-transmission-daemon-test))))
tr> 2024-08-11gnu: Replace (almost) all uses of /run/setuid-programs....…those good for master, anyway. * gnu/packages/admin.scm (ktsuss, opendoas, hosts) [arguments]: Replace /run/setuid-programs with /run/privileged/bin. * gnu/packages/containers.scm (slirp4netns)[arguments]: Likewise. * gnu/packages/debian.scm (pbuilder)[arguments]: Likewise. * gnu/packages/disk.scm (udevil)[arguments]: Likewise. * gnu/packages/enlightenment.scm (efl, enlightenment) [arguments]: Likewise. * gnu/packages/gnome.scm (gdm, gnome-control-center) [arguments]: Likewise. * gnu/packages/linux.scm (singularity)[arguments]: Likewise. * gnu/packages/lxde.scm (spacefm)[arguments]: Likewise. * gnu/packages/monitoring.scm (zabbix-agentd)[arguments]: Likewise. * gnu/packages/virtualization.scm (ganeti)[arguments]: Likewise. * gnu/packages/xdisorg.scm (xsecurelock)[arguments]: Likewise. * gnu/services/dbus.scm (dbus-configuration-directory): Likewise. * gnu/services/ganeti.scm (%default-ganeti-environment-variables): Likewise. * gnu/services/monitoring.scm (zabbix-agent-shepherd-service): Likewise. * gnu/tests/ldap.scm (marionette): Likewise. * gnu/tests/monitoring.scm (os): Likewise. Tobias Geerinckx-Rice 2024-08-16gnu: python-libvirt: Use pyproject-build-system....* gnu/packages/virtualization.scm (python-libvirt): Use pyproject-build-system. Change-Id: If4b67308f843bb182b616358911ce9a2f1113bed jgart 2024-08-16gnu: python-libvirt: Update to 10.6.0....* gnu/packages/virtualization.scm (python-libvirt): Update to 10.6.0. Change-Id: I25f9f50d4e397435175ccfa4b5744d9519a299cd jgart 2024-07-30gnu: skopeo: Update to 1.16.0....* gnu/packages/virtualization.scm (skopeo): Update to 1.16.0. [arguments]<#:phases>: Delete the `cc-to-gcc' phase. Change-Id: I35a91219c3c920f37f496df6322ae1e40fa1ccc3 Signed-off-by: Zheng Junjie <zhengjunjie@iscas.ac.cn> Tomas Volf 2024-07-20gnu: skopeo: Update to 1.15.2....* gnu/packages/virtualization.scm (skopeo): Update to 1.15.2. Change-Id: I45baf61208792e71dff8d8e4b8f5bf4f591ed107 Signed-off-by: Ludovic Courtès <ludo@gnu.org> Tomas Volf 2024-07-18gnu: qemu: Enable building without ipxe firmware....* gnu/packages/virtualization.scm (qemu)[arguments]: Adjust the configure-flags to provide a substitute location if built without ipxe-qemu. Adjust the 'replace-firmwares phase to provide a substitute location if built without ipxe-qemu. Add a phase when built without ipxe-qemu to not require those firmware files for building or for tests. [inputs]: Only build with ipxe-qemu when on a supported architecture. Change-Id: If914193827faef6fa18b3cc3268d24cc7db4225e Efraim Flashner 2024-07-17gnu: Fix virt-manager for systems with no GTK cursor....* gnu/packages/patches/virt-manager-fix-gtk-cursor-theme-backtace.patch: New file. * gnu/local.mk (dist_patch_DATA): Register file. * gnu/packages/virtualization.scm (virt-manager)[source]: Use it. Change-Id: I4db2015a5d4ac3eca3cfa5d3eec20b357c2d3ff9 Signed-off-by: Leo Famulari <leo@famulari.name> Karl Hallsby 2024-06-29gnu: skopeo: Apply "-trimpath" flag....* gnu/packages/virtualization.scm (skopeo) [arguments]: <#:make-flags>: Add "-trimpath" to replace 'remove-go-references phase. <#:phases>: Remove 'remove-go-references phase. Change-Id: Idab669576282c81d55ec989dc1a64e87b89699ee Sharlatan Hellseher 2024-06-06Merge branch 'gnome-team'Liliana Marie Prikler 2024-06-04gnu: Add qemu-7.2.4....Version 8.0.5 is the latest version that works reliably as a qemu-binfmt-service for riscv64, which makes 7.2.4 the newest working version that was packaged for Guix. * gnu/packages/patches/qemu-7.2.4-build-info-manual.patch, gnu/packages/patches/qemu-disable-aarch64-migration-test.patch: New files. * gnu/local.mk (dist_patch_DATA): Register them. * gnu/packages/virtualization.scm (qemu-7.2.4): Use them in new package. Change-Id: Iaedc424e619cdc4964945f7383d47cff0c7ed10f Janneke Nieuwenhuizen 2024-06-03gnu: qemu: Disable more tests....* gnu/packages/virtualization.scm (qemu)[disable-unusable-tests]: Also disable qtest/ahci-test and qemu-iotests/copy-before-write. Liliana Marie Prikler 2024-05-27gnu: Use new ovmf firmware packages....* doc/guix.texi (Invoking guix system): Update qemu command to use ovmf-x86-64. * gnu/packages/virtualization.scm (xen)[inputs]: Replace ovmf with ovmf-i686. * gnu/tests/install.scm (uefi-firmware): Use system appropriate ovmf firmware. Change-Id: Ia2ff76eaf766c8d4fb0be4a7cc7b8941574433d0 Efraim Flashner 2024-05-23gnu: skopeo: Update to 1.15.1 [security fixes]....This fixes CVE-2024-3727. * gnu/packages/virtualization.scm (skopeo): Update to 1.15.1. Change-Id: Icebb6f50e7317bce9ff106d71ad30dcfa6665666 Signed-off-by: Zheng Junjie <zhengjunjie@iscas.ac.cn> Tomas Volf 2024-04-05gnu: skopeo: Update to 1.15.0....The package is also converted to gnu-build-system in order to take advantage of already existing Makefile instead of reinventing (parts) of it in Guile. * gnu/packages/virtualization.scm (skopeo)[version]: Update to 1.15.0. [build-system]: Use gnu-build-system. [native-inputs]: Add go-1.21, sort. [inputs]: Add bash-minimal. [arguments]<#:import-path, #:install-source?>: Delete. <#:make-flags, #:test-target, #:imported-modules>: New arguments. <#:phases>{'configure}: Delete. {'set-env, 'cc-to-gcc, 'wrap-skopeo, 'remove-go-references}: New phases. Change-Id: I1010e1f4fbdc093646c2879bdf30125ab2e88bdd Signed-off-by: Christopher Baines <mail@cbaines.net> Tomas Volf 2024-03-20Merge remote-tracking branch 'savannah/master' into gnome-team...Change-Id: Iec8e15b79c6fde516294c2bfcaf8ee3575b1f745 Christopher Baines 2024-03-19gnu: qemu: Update to 8.2.2....* gnu/packages/virtualization.scm (qemu): Update to 8.2.2. [source]: Adjust snippet. [arguments] <phases>: Patch tests sources with native /bin/sh. Also patch /bin/sh references in migration/migration.c, util/envlist.c files. * gnu/packages/patches/qemu-disable-some-qtests-tests.patch: Delete file. * gnu/packages/patches/qemu-disable-bios-tables-test.patch: New file. * gnu/local.mk (dist_patch_DATA): Update accordingly. Change-Id: Ia44017e4d567ede1995ae707ed6acbb1ec5194fe Maxim Cournoyer 2024-03-19gnu: qemu: Re-instate info manual....* gnu/packages/patches/qemu-build-info-manual.patch: Update patch. * gnu/packages/virtualization.scm (qemu): Register it. Change-Id: I804bf7c551904d625fef85de200b9db1462f1093 Maxim Cournoyer