summaryrefslogtreecommitdiff
path: root/gnu/tests
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2024-10-30 22:27:19 +0900
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2025-02-13 00:07:21 +0900
commita595a52b7b0849bc159fbf1d7cb0823444bd7449 (patch)
tree259cc9987faa60aaee2e135021a86adc2d39a28b /gnu/tests
parent5074871043806d747b16c62b081b9db8b813dd7c (diff)
tests: Add anonip system test.
* gnu/tests/web.scm (%test-anonip): New test. (%anonip-os): New variables. (run-anonip-test): New procedure. Change-Id: Ieed210a784dbdeee8a498e74b6c0e31cb72cd9b8
Diffstat (limited to 'gnu/tests')
-rw-r--r--gnu/tests/web.scm122
1 files changed, 122 insertions, 0 deletions
diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm
index 509ca336926..f04f6b244a3 100644
--- a/gnu/tests/web.scm
+++ b/gnu/tests/web.scm
@@ -4,6 +4,7 @@
4;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org> 4;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
5;;; Copyright © 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr> 5;;; Copyright © 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
6;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com> 6;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
7;;; Copyright © 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
7;;; 8;;;
8;;; This file is part of GNU Guix. 9;;; This file is part of GNU Guix.
9;;; 10;;;
@@ -33,6 +34,7 @@
33 #:use-module (gnu services networking) 34 #:use-module (gnu services networking)
34 #:use-module (gnu services shepherd) 35 #:use-module (gnu services shepherd)
35 #:use-module (gnu services mail) 36 #:use-module (gnu services mail)
37 #:use-module (gnu packages base)
36 #:use-module (gnu packages databases) 38 #:use-module (gnu packages databases)
37 #:use-module (gnu packages guile-xyz) 39 #:use-module (gnu packages guile-xyz)
38 #:use-module (gnu packages patchutils) 40 #:use-module (gnu packages patchutils)
@@ -52,6 +54,7 @@
52 %test-php-fpm 54 %test-php-fpm
53 %test-hpcguix-web 55 %test-hpcguix-web
54 %test-tailon 56 %test-tailon
57 %test-anonip
55 %test-patchwork 58 %test-patchwork
56 %test-agate)) 59 %test-agate))
57 60
@@ -511,6 +514,125 @@ HTTP-PORT."
511 514
512 515
513;;; 516;;;
517;;; Anonip
518;;;
519(define %anonip-os
520 ;; Operating system under test.
521 (simple-operating-system
522 (service anonip-service-type
523 (anonip-configuration
524 (input "/var/run/anonip/access.log")
525 (output "/var/log/anonip/access.log")
526 (debug? #t)))))
527
528(define (run-anonip-test)
529 (define os
530 (marionette-operating-system
531 %anonip-os
532 #:imported-modules '((gnu services herd)
533 (guix combinators))))
534
535 (define vm
536 (virtual-machine
537 (operating-system os)
538 ;; We are interested in verifying if anonip still launches following a
539 ;; reboot; thus make the base image writable.
540 (volatile? #f)))
541
542 (define test
543 (with-imported-modules '((gnu build marionette))
544 #~(begin
545 (use-modules (ice-9 match)
546 (srfi srfi-64)
547 (gnu build marionette))
548
549 (define marionette
550 (make-marionette (list #$vm)))
551
552 (test-runner-current (system-test-runner #$output))
553 (test-begin "anonip")
554
555 (test-assert "service is running"
556 (marionette-eval
557 '(begin
558 (use-modules (gnu services herd))
559 (wait-for-service 'anonip-/var/log/anonip/access.log))
560 marionette))
561
562 (test-assert "service can be restarted"
563 (marionette-eval
564 '(begin
565 (use-modules (gnu services herd))
566 (restart-service 'anonip-/var/log/anonip/access.log)
567 (wait-for-service 'anonip-/var/log/anonip/access.log))
568 marionette))
569
570 (test-assert "ip addresses are anonymized"
571 (marionette-eval
572 '(begin
573 (use-modules (ice-9 textual-ports))
574 (call-with-output-file "/var/run/anonip/access.log"
575 (lambda (port)
576 (display "192.168.100.200 - - \
577[30/Oct/2024:14:57:44 +0100] GET /xxx.narinfo HTTP/1.1\" 200 1065 \
578\"-\" \"GNU Guile\"\n" port)
579 (display "2001:0db8:85a3:0000:0000:8a2e:0370:7334 - - \
580[30/Oct/2024:14:57:44 +0100] \"GET /xxx.narinfo HTTP/1.1\" 200 1065 \
581\"-\" \"GNU Guile\"\n" port)))
582 (#$retry-on-error
583 (lambda ()
584 (call-with-input-file "/var/log/anonip/access.log"
585 (lambda (port)
586 (let ((content (get-string-all port)))
587 ;; The expected values are taken from anonip's test
588 ;; suite (see its test_module.py file).
589 (or (and (string-contains content "192.168.96.0")
590 (string-contains content "2001:db8:85a0::"))
591 (error "could not find expected anonymized IPs"
592 content))))))
593 #:times 20
594 #:delay 1))
595 marionette))
596
597 (test-assert "service is running after reboot"
598 (begin
599 (marionette-eval
600 '(begin
601 (use-modules (gnu services herd))
602 (eval-there '(begin
603 (use-modules (shepherd system))
604 (sync) ;ensure the log is fully written
605 (reboot))))
606 marionette)
607 ;; Note: a distinct marionette-eval call is needed here; if
608 ;; included in the previous one issuing the reboot,
609 ;; 'wait-for-service' would apparently run before the system had
610 ;; rebooted (and succeed), which would defeat the test.
611 (marionette-eval
612 '(begin
613 (use-modules (gnu services herd))
614 (wait-for-service 'anonip-/var/log/anonip/access.log))
615 marionette)))
616
617 (test-assert "service can be stopped"
618 (marionette-eval
619 '(begin
620 (use-modules (gnu services herd))
621 (stop-service 'anonip-/var/log/anonip/access.log))
622 marionette))
623
624 (test-end))))
625
626 (gexp->derivation "anonip-test" test))
627
628(define %test-anonip
629 (system-test
630 (name "anonip")
631 (description "Anonymize logs via Anonip")
632 (value (run-anonip-test))))
633
634
635;;;
514;;; Patchwork 636;;; Patchwork
515;;; 637;;;
516 638