From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6EVxFfy76WEjcgAAgWs5BA (envelope-from ) for ; Thu, 20 Jan 2022 20:46:04 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id aIJIDvy76WFnDgEAG6o9tA (envelope-from ) for ; Thu, 20 Jan 2022 20:46:04 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AD318AE06 for ; Thu, 20 Jan 2022 20:46:03 +0100 (CET) Received: from localhost ([::1]:56758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAdNf-00029O-ET for larch@yhetil.org; Thu, 20 Jan 2022 14:46:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAXCX-0004EH-8r for guix-patches@gnu.org; Thu, 20 Jan 2022 08:10:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:35574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAXCW-0006T3-6g for guix-patches@gnu.org; Thu, 20 Jan 2022 08:10:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nAXCW-0004tH-0k for guix-patches@gnu.org; Thu, 20 Jan 2022 08:10:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53389] [PATCH 7/9] tests: Allow checking the URI of a HTTP request. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 Jan 2022 13:10:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53389 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53389@debbugs.gnu.org Cc: ludo@gnu.org, Maxime Devos Received: via spool by 53389-submit@debbugs.gnu.org id=B53389.164268415918695 (code B ref 53389); Thu, 20 Jan 2022 13:10:03 +0000 Received: (at 53389) by debbugs.gnu.org; 20 Jan 2022 13:09:19 +0000 Received: from localhost ([127.0.0.1]:56702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAXBm-0004rM-O7 for submit@debbugs.gnu.org; Thu, 20 Jan 2022 08:09:19 -0500 Received: from baptiste.telenet-ops.be ([195.130.132.51]:42074) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAXBM-0004oy-Kt for 53389@debbugs.gnu.org; Thu, 20 Jan 2022 08:08:54 -0500 Received: from localhost.localdomain ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by baptiste.telenet-ops.be with bizsmtp id l18q2600H4UW6Th0118rNy; Thu, 20 Jan 2022 14:08:52 +0100 From: Maxime Devos Date: Thu, 20 Jan 2022 13:08:47 +0000 Message-Id: <20220120130849.292178-7-maximedevos@telenet.be> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220120130849.292178-1-maximedevos@telenet.be> References: <20220120130849.292178-1-maximedevos@telenet.be> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r22; t=1642684132; bh=qXHokLrX3UhbhK5gTp4pjeibyVHhQkw8mgeu4FprdvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iLbuSuI+tlgqAs2dSPW9TEL1ZAVxHeXW6ERMQ25+EMz0xNLPqaHzwunTKHbbVkUQZ 9YlY7WhcCTBxuLqm3TE31LjXtn4JePGVnbyOp3Nmry7b87ykxSL2xhPtpi1LN//WzA 0kL+xoMUJDjUXx/dqg/46PdDJkeiDzDrODUzfJoYFZDM5lvYeOJ45ZK9tAYpgBUG4s kCzOqEWH0DM4Xyb+RwtuOonBLr0yzNtYv6L+7YrEj78sCNqGE+uNgAAOHpniB3NZy8 GrGWOOi/QvCYdl7cdl9wTimzDIrNC3PDt+DFOB3lS3fdSo76MiR/sGX5r9/UxAgNuH Nyl5OHZWLtQSQ== 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1642707963; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=qXHokLrX3UhbhK5gTp4pjeibyVHhQkw8mgeu4FprdvI=; b=TLwGGCwUwAUys4D9zwTJvYf/rCI5+n5GjNE2AGmbhi7tObl+1+vC0k3J5hTXE/uSYOFcRs HUKavPr/I9Py6Lq88B4UsTTPbXdsgTFh30t7wqFTW0XR7omxzIUaR1PuHsialCbxuUwXkJ 0jAum7eTgN2Xo3H1QLWwwHzNVSUmJuzr+slLeCWaKU55xX18Zl6FWnN3fbuJUNmyNhMVDy Dpyu7DMff0/p4GhCs2AVOOp+Vm/ZXiQlJXL6Ra3U2JulZBueJ40O3C4VKY6NnhnIdYj27m R265XV+cgY7N9uHHlUR0HtE/ZZw7wSvAx+7WJOKoaBfTF/TGP/ES5Dp+bhaQXA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642707963; a=rsa-sha256; cv=none; b=us/D+Rg9lXo/OXc3HEe0TlxXfOWg2ok+JMSjmDGuNosgcltUsUe2yyvf3EX/8h8QII4Boo 1k3Mpdiy2wQT9gIZJ4cUFBKxsXRe34v0IAnEi745/QObCeeE+xItbflUG23n4i5iYz0mCb PiJRa2Vbrlj6ZzsByOrAaGK5eqsncGAbCuAze56VOwYt5HiYWM04CiwEvAHwIK1DFwbgfM qiOCaLAHGNWTacxRQz665kPyKImyIyA0k+7V9FKRaVHmV5TA5dj5DUIfgLmoTSvU7d5jL8 iciDwZFWA7Qv4iHsgGzP6WerM9UZKtNmvX8MdhXx94nUBG1atrLFyKYRvsWrAA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r22 header.b=iLbuSuI+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -0.62 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r22 header.b=iLbuSuI+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: AD318AE06 X-Spam-Score: -0.62 X-Migadu-Scanner: scn1.migadu.com X-TUID: 7Dol6h00j8T6 * guix/tests/http.scm (call-with-http-server): Thunk RESPONSES+DATA. [maybe-uri?]: New procedure. [sanitize-response+data]: New procedure extracted from the definition of 'responses', support triples containing a URI. [responses]: Thunk. [handle]: Verify the URI. Adjust for thunking. (with-http-server): Adjust for thunking. --- guix/tests/http.scm | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/guix/tests/http.scm b/guix/tests/http.scm index 2f65df4029..6af1948211 100644 --- a/guix/tests/http.scm +++ b/guix/tests/http.scm @@ -21,7 +21,9 @@ #:use-module (ice-9 threads) #:use-module (web server) #:use-module (web server http) + #:use-module (web request) #:use-module (web response) + #:use-module (web uri) #:use-module (srfi srfi-11) #:use-module (srfi srfi-39) #:use-module (ice-9 match) @@ -144,7 +146,10 @@ It will also quit if LAST-RESPONSE? returns true." (define* (call-with-http-server responses+data thunk #:key (keep-lingering? #false)) "Call THUNK with an HTTP server running and returning RESPONSES+DATA on HTTP requests. Each element of RESPONSES+DATA must be a tuple containing a -response and a string, or an HTTP response code and a string. +response and a string, or an HTTP response code and a string. Alternatively, +the elements can triples with the URI path (including the query, if any) +as the first part of the triple. In that case, the request URI is verified +against the URI in RESPONSES+DATA. The argument RESPONSES+DATA is thunked. As such, RESPONSES+DATA can use %http-server-port. %http-server-port will be set to the port listened at. @@ -152,18 +157,28 @@ It will be set for the dynamic extent of THUNK and RESPONSES+DATA. The server will exit after the last response. When KEEP-LINGERING? is false, the server will also exit after THUNK returns." + (define (maybe-uri? object) + (or (string? object) (eq? object 'any))) + (define (sanitize-response+data response+data) + (match response+data + ((response data) + (sanitize-response+data (list 'any response data))) + (((? maybe-uri? uri) (? response? response) data) + (list uri response data)) + (((? maybe-uri? uri) (? integer? code) data) + (list uri + (build-response #:code code + #:reason-phrase "Such is life") + data)))) (define (responses) - (map (match-lambda - (((? response? response) data) - (list response data)) - (((? integer? code) data) - (list (build-response #:code code - #:reason-phrase "Such is life") - data))) - (responses+data))) + (map sanitize-response+data (responses+data))) (define (handle request body) (match (responses) - (((response data) rest ...) + (((uri response data) rest ...) + (unless (or (eq? uri 'any) + (string=? uri (uri->string (request-uri request)))) + (error "this URI should not be contacted!" + (request-uri request))) (set! responses (const rest)) (values response data)))) (call-with-http-server* handle thunk #:keep-lingering? keep-lingering? -- 2.30.2