pam.scm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  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.
  10. ;;;
  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.
  15. ;;;
  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/>.
  18. (define-module (gnu tests pam)
  19. #:use-module (gnu tests)
  20. #:use-module (gnu services)
  21. #:use-module (gnu services base)
  22. #:use-module (gnu system)
  23. #:use-module (gnu system pam)
  24. #:use-module (gnu system vm)
  25. #:use-module (guix gexp)
  26. #:use-module (ice-9 format)
  27. #:export (%test-pam-limits
  28. %test-pam-limits-deprecated))
  29. ;;;
  30. ;;; pam-limits-service-type
  31. ;;;
  32. (define pam-limit-entries
  33. (list
  34. (pam-limits-entry "@realtime" 'both 'rtprio 99)
  35. (pam-limits-entry "@realtime" 'both 'memlock 'unlimited)))
  36. (define (run-test-pam-limits config)
  37. "Run tests in a os with pam-limits-service-type configured."
  38. (define os
  39. (marionette-operating-system
  40. (simple-operating-system
  41. (service pam-limits-service-type config))))
  42. (define vm
  43. (virtual-machine os))
  44. (define name (format #f "pam-limit-service~:[~;-deprecated~]"
  45. (file-like? config)))
  46. (define test
  47. (with-imported-modules '((gnu build marionette))
  48. #~(begin
  49. (use-modules (gnu build marionette)
  50. (srfi srfi-64))
  51. (let ((marionette (make-marionette (list #$vm))))
  52. (test-runner-current (system-test-runner #$output))
  53. (test-begin #$name)
  54. (test-assert "/etc/security/limits.conf ready"
  55. (wait-for-file "/etc/security/limits.conf" marionette))
  56. (test-equal "/etc/security/limits.conf content matches"
  57. #$(string-join (map pam-limits-entry->string pam-limit-entries)
  58. "\n" 'suffix)
  59. (marionette-eval
  60. '(begin
  61. (use-modules (rnrs io ports))
  62. (call-with-input-file "/etc/security/limits.conf"
  63. get-string-all))
  64. marionette))
  65. (test-end)))))
  66. (gexp->derivation (string-append name "-test") test))
  67. (define %test-pam-limits
  68. (system-test
  69. (name "pam-limits-service")
  70. (description "Test that pam-limits-service can serialize its config
  71. (as a list) to @file{limits.conf}.")
  72. (value (run-test-pam-limits pam-limit-entries))))
  73. (define %test-pam-limits-deprecated
  74. (system-test
  75. (name "pam-limits-service-deprecated")
  76. (description "Test that pam-limits-service can serialize its config
  77. (as a file-like object) to @file{limits.conf}.")
  78. (value (run-test-pam-limits
  79. (plain-file "limits.conf"
  80. (string-join (map pam-limits-entry->string
  81. pam-limit-entries)
  82. "\n" 'suffix))))))