From patchwork Fri Nov 1 12:39:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 32777 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E39F527BBE9; Fri, 1 Nov 2024 12:43:57 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 513BF27BBE2 for ; Fri, 1 Nov 2024 12:43:57 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6qzc-0007hA-Rq; Fri, 01 Nov 2024 08:43:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t6qzb-0007gW-5T for guix-patches@gnu.org; Fri, 01 Nov 2024 08:43:07 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t6qza-0000Ru-PP for guix-patches@gnu.org; Fri, 01 Nov 2024 08:43:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=kMjCf3cPPZRr8OCAqtYI6tknoCszAU8a+phN/eICsWk=; b=v31Go2AVvDNHKcTn/IeDRT7e5MUkypYIXSSm63hoh5r6oQ7fN6NkTHiRo6PZ+dq1ZTHMasapkVKubqO1uf9JLkCm2uh663BCcEDNEKKbwKnFVPHL0xI3QePOV7FGaRmIAcREbc/kWtJav6o43T47JIYKXsvuSXXj34hkSgtxyKloZoStuzymRCRNac1mcy5pWnd4yMrsiHUiBaK2+jHWpqct8TR34vq4K9aAVJdYtxMpeIh6FRkole+79W34RKYrUc1mHIzNdfi1/ZzKufkLQqcbthbDgJTremHUhSvZpdukzrIxWz2GaIZhWOJdocS0pwEGf6xUjSJ0ntp7aYJWtQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t6qza-0007vw-I7; Fri, 01 Nov 2024 08:43:06 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#74151] [PATCH v2 7/9] tests: Add anonip system test. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Fri, 01 Nov 2024 12:43:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74151 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74151@debbugs.gnu.org Cc: Maxim Cournoyer , Maxim Cournoyer X-Debbugs-Original-Xcc: Maxim Cournoyer Received: via spool by 74151-submit@debbugs.gnu.org id=B74151.173046495230414 (code B ref 74151); Fri, 01 Nov 2024 12:43:06 +0000 Received: (at 74151) by debbugs.gnu.org; 1 Nov 2024 12:42:32 +0000 Received: from localhost ([127.0.0.1]:49226 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6qz1-0007uU-Hx for submit@debbugs.gnu.org; Fri, 01 Nov 2024 08:42:32 -0400 Received: from mail-pl1-f169.google.com ([209.85.214.169]:56470) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6qyy-0007tu-79 for 74151@debbugs.gnu.org; Fri, 01 Nov 2024 08:42:30 -0400 Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-20cf6eea3c0so16443585ad.0 for <74151@debbugs.gnu.org>; Fri, 01 Nov 2024 05:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730464882; x=1731069682; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kMjCf3cPPZRr8OCAqtYI6tknoCszAU8a+phN/eICsWk=; b=ZunRk6dLYBOp4Co2E48c78JsHeEU9J/3ppfXwNneQd6Fkn2HkwYzM4FomarDoYLc26 1NU5ler9G05v9QiIgPOSmnr4l4LGU40bClX3kGKrEGiv71FC4Qv+u6fFnB2nd3cdJgI0 YUhIRf05aWo73/T+24vmdhEvdomeP3xK9RHZP2Qv5jnKWBy7q6GBtLCzuTh/w3RB7lAq zZC480rv7tYMd81wdaeIj79N6w6bmBVrCATak9ozqX3HxfCvPjl65L3BbrioXRyJ3h34 /1D0kIQmqMOyHRcrroaegO54wsDa5L9ZVCnhSaMlf5WIObOLWvleLlxNO/OKmtf5JBpu LXuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730464882; x=1731069682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kMjCf3cPPZRr8OCAqtYI6tknoCszAU8a+phN/eICsWk=; b=RxslGkTMu8CB4rrbXiyCXLaziVX+8tZzVoO1v4PJwxdjVMa5d75Q+/fnTDAB/pqPrC aNDMgu6EGyb5NEAoEGEfy4XKzzLEA3HedXm3arILxn95CL1886gcUJEZPMiZuH9sKTx4 QMDSaKe3Xf9a4heGQZfTI8tEgfK+rT+pezur8jJFBRX7EL8jLpJuMLnyMHaEDfY1aEqZ A0Ja2DgwuSBFUzDWbQNa9Qcgx5xH3PJmdWogpJH8uMj8JCe8/tPZrtGGV0En1WveutzQ mdYnQFWiPLJv5NYplJKWcFJZGEyqYMvxUEnopeG63g+BNyslrQ/vKcS9X9eSW9zWzo2Z BceA== X-Gm-Message-State: AOJu0YzpQiP93tdL+7ZRUvAXvoJh7JkpxARQI8vHpyKxIxLZnORPUW5Y Ye7Z2VWpb7dAnXlJN2h55R2hvVeVSNYyJXGCHjIkbPrnhfCB02uKrwOGOATV X-Google-Smtp-Source: AGHT+IHXgUlU0aGzZssVqVXOtvsA7sBwtPCwweWxoR8L7CDgpWr1n2A6xzPBgo2C68RKhGX+B/nf6g== X-Received: by 2002:a17:902:d485:b0:20c:7c09:b2ac with SMTP id d9443c01a7336-210c6c5db72mr278342325ad.52.1730464881901; Fri, 01 Nov 2024 05:41:21 -0700 (PDT) Received: from localhost.localdomain ([2405:6586:be0:0:c8ff:1707:9b9:af89]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e92fa0ea9bsm4819463a91.10.2024.11.01.05.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 05:41:21 -0700 (PDT) From: Maxim Cournoyer Date: Fri, 1 Nov 2024 21:39:27 +0900 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: <281a4773768a6c271ff464f473fdbc333a58c348.1730464675.git.maxim.cournoyer@gmail.com> References: <281a4773768a6c271ff464f473fdbc333a58c348.1730464675.git.maxim.cournoyer@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/tests/web.scm (%test-anonip): New test. (%anonip-os): New variables. (run-anonip-test): New procedure. Change-Id: Ieed210a784dbdeee8a498e74b6c0e31cb72cd9b8 --- gnu/tests/web.scm | 122 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 5c50322cef..6ef32138ed 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2017, 2018 Clément Lassieur ;;; Copyright © 2018 Pierre-Antoine Rouby ;;; Copyright © 2018 Marius Bakke +;;; Copyright © 2024 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -33,6 +34,7 @@ (define-module (gnu tests web) #:use-module (gnu services networking) #:use-module (gnu services shepherd) #:use-module (gnu services mail) + #:use-module (gnu packages base) #:use-module (gnu packages databases) #:use-module (gnu packages guile-xyz) #:use-module (gnu packages patchutils) @@ -52,6 +54,7 @@ (define-module (gnu tests web) %test-php-fpm %test-hpcguix-web %test-tailon + %test-anonip %test-patchwork %test-agate)) @@ -509,6 +512,125 @@ (define %test-tailon (description "Connect to a running Tailon server.") (value (run-tailon-test)))) + +;;; +;;; Anonip +;;; +(define %anonip-os + ;; Operating system under test. + (simple-operating-system + (service anonip-service-type + (anonip-configuration + (input "/var/run/anonip/access.log") + (output "/var/log/anonip/access.log") + (debug? #t))))) + +(define (run-anonip-test) + (define os + (marionette-operating-system + %anonip-os + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define vm + (virtual-machine + (operating-system os) + ;; We are interested in verifying if anonip still launches following a + ;; reboot; thus make the base image writable. + (volatile? #f))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (ice-9 match) + (srfi srfi-64) + (gnu build marionette)) + + (define marionette + (make-marionette (list #$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "anonip") + + (test-assert "service is running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (wait-for-service 'anonip-/var/log/anonip/access.log)) + marionette)) + + (test-assert "service can be restarted" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (restart-service 'anonip-/var/log/anonip/access.log) + (wait-for-service 'anonip-/var/log/anonip/access.log)) + marionette)) + + (test-assert "ip addresses are anonymized" + (marionette-eval + '(begin + (use-modules (ice-9 textual-ports)) + (call-with-output-file "/var/run/anonip/access.log" + (lambda (port) + (display "192.168.100.200 - - \ +[30/Oct/2024:14:57:44 +0100] GET /xxx.narinfo HTTP/1.1\" 200 1065 \ +\"-\" \"GNU Guile\"\n" port) + (display "2001:0db8:85a3:0000:0000:8a2e:0370:7334 - - \ +[30/Oct/2024:14:57:44 +0100] \"GET /xxx.narinfo HTTP/1.1\" 200 1065 \ +\"-\" \"GNU Guile\"\n" port))) + (#$retry-on-error + (lambda () + (call-with-input-file "/var/log/anonip/access.log" + (lambda (port) + (let ((content (get-string-all port))) + ;; The expected values are taken from anonip's test + ;; suite (see its test_module.py file). + (or (and (string-contains content "192.168.96.0") + (string-contains content "2001:db8:85a0::")) + (error "could not find expected anonymized IPs" + content)))))) + #:times 20 + #:delay 1)) + marionette)) + + (test-assert "service is running after reboot" + (begin + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (eval-there '(begin + (use-modules (shepherd system)) + (sync) ;ensure the log is fully written + (reboot)))) + marionette) + ;; Note: a distinct marionette-eval call is needed here; if + ;; included in the previous one issuing the reboot, + ;; 'wait-for-service' would apparently run before the system had + ;; rebooted (and succeed), which would defeat the test. + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (wait-for-service 'anonip-/var/log/anonip/access.log)) + marionette))) + + (test-assert "service can be stopped" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (stop-service 'anonip-/var/log/anonip/access.log)) + marionette)) + + (test-end)))) + + (gexp->derivation "anonip-test" test)) + +(define %test-anonip + (system-test + (name "anonip") + (description "Anonymize logs via Anonip") + (value (run-anonip-test)))) + ;;; ;;; Patchwork