2023-03-04 16:17:39 -05:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
|
2023-05-12 14:52:47 -04:00
|
|
|
|
;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
|
2023-03-04 16:17:39 -05:00
|
|
|
|
;;;
|
|
|
|
|
;;; 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/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu tests pam)
|
|
|
|
|
#:use-module (gnu tests)
|
|
|
|
|
#:use-module (gnu services)
|
|
|
|
|
#:use-module (gnu services base)
|
|
|
|
|
#:use-module (gnu system)
|
|
|
|
|
#:use-module (gnu system pam)
|
|
|
|
|
#:use-module (gnu system vm)
|
|
|
|
|
#:use-module (guix gexp)
|
|
|
|
|
#:use-module (ice-9 format)
|
2023-05-12 14:52:47 -04:00
|
|
|
|
#:export (%test-pam-limits))
|
2023-03-04 16:17:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; pam-limits-service-type
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define pam-limit-entries
|
|
|
|
|
(list
|
2023-05-12 14:52:47 -04:00
|
|
|
|
;; make sure the limits apply to root (uid 0)
|
|
|
|
|
(pam-limits-entry ":0" 'both 'rtprio 99) ;default is 0
|
|
|
|
|
(pam-limits-entry ":0" 'both 'memlock 'unlimited))) ;default is 8192 kbytes
|
2023-03-04 16:17:39 -05:00
|
|
|
|
|
|
|
|
|
(define (run-test-pam-limits config)
|
|
|
|
|
"Run tests in a os with pam-limits-service-type configured."
|
|
|
|
|
(define os
|
|
|
|
|
(marionette-operating-system
|
|
|
|
|
(simple-operating-system
|
2023-05-12 14:52:47 -04:00
|
|
|
|
(service pam-limits-service-type config))
|
|
|
|
|
#:imported-modules '((gnu services herd))))
|
2023-03-04 16:17:39 -05:00
|
|
|
|
|
|
|
|
|
(define vm
|
|
|
|
|
(virtual-machine os))
|
|
|
|
|
|
2023-05-12 14:52:47 -04:00
|
|
|
|
(define name "pam-limits-service")
|
2023-03-04 16:17:39 -05:00
|
|
|
|
|
|
|
|
|
(define test
|
2023-05-12 14:52:47 -04:00
|
|
|
|
(with-imported-modules '((gnu build marionette)
|
|
|
|
|
(guix build syscalls))
|
2023-03-04 16:17:39 -05:00
|
|
|
|
#~(begin
|
|
|
|
|
(use-modules (gnu build marionette)
|
2023-05-12 14:52:47 -04:00
|
|
|
|
(guix build syscalls)
|
2023-03-04 16:17:39 -05:00
|
|
|
|
(srfi srfi-64))
|
|
|
|
|
|
|
|
|
|
(let ((marionette (make-marionette (list #$vm))))
|
|
|
|
|
|
|
|
|
|
(test-runner-current (system-test-runner #$output))
|
|
|
|
|
|
|
|
|
|
(test-begin #$name)
|
|
|
|
|
|
2023-05-12 14:52:47 -04:00
|
|
|
|
(test-equal "log in on tty1 and read limits"
|
|
|
|
|
'(("99") ;real-time priority
|
|
|
|
|
("unlimited")) ;max locked memory
|
|
|
|
|
|
|
|
|
|
(begin
|
|
|
|
|
;; Wait for tty1.
|
|
|
|
|
(marionette-eval '(begin
|
|
|
|
|
(use-modules (gnu services herd))
|
|
|
|
|
(start-service 'term-tty1))
|
|
|
|
|
marionette)
|
|
|
|
|
|
|
|
|
|
(marionette-control "sendkey ctrl-alt-f1" marionette)
|
|
|
|
|
|
|
|
|
|
;; Now we can type.
|
|
|
|
|
(marionette-type "root\n" marionette)
|
|
|
|
|
(marionette-type "ulimit -r > real-time-priority\n" marionette)
|
|
|
|
|
(marionette-type "ulimit -l > max-locked-memory\n" marionette)
|
|
|
|
|
|
|
|
|
|
;; Read the two files.
|
|
|
|
|
(marionette-eval '(use-modules (rnrs io ports)) marionette)
|
|
|
|
|
(let ((guest-file (lambda (file)
|
|
|
|
|
(string-tokenize
|
|
|
|
|
(wait-for-file file marionette
|
|
|
|
|
#:read 'get-string-all)))))
|
|
|
|
|
(list (guest-file "/root/real-time-priority")
|
|
|
|
|
(guest-file "/root/max-locked-memory")))))
|
2023-03-04 16:17:39 -05:00
|
|
|
|
|
|
|
|
|
(test-end)))))
|
|
|
|
|
|
|
|
|
|
(gexp->derivation (string-append name "-test") test))
|
|
|
|
|
|
|
|
|
|
(define %test-pam-limits
|
|
|
|
|
(system-test
|
|
|
|
|
(name "pam-limits-service")
|
2023-05-12 14:52:47 -04:00
|
|
|
|
(description "Test that pam-limits-service actually sets the limits as
|
|
|
|
|
configured.")
|
2023-03-04 16:17:39 -05:00
|
|
|
|
(value (run-test-pam-limits pam-limit-entries))))
|