From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6BT6A+ZpU2HKDgAAgWs5BA (envelope-from ) for ; Tue, 28 Sep 2021 21:15:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UH5fO+VpU2FscgAA1q6Kng (envelope-from ) for ; Tue, 28 Sep 2021 19:15:49 +0000 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 A8D2E2907 for ; Tue, 28 Sep 2021 21:15:49 +0200 (CEST) Received: from localhost ([::1]:59060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVIZw-0000aR-QE for larch@yhetil.org; Tue, 28 Sep 2021 15:15:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVIUM-0001eI-Pz for guix-patches@gnu.org; Tue, 28 Sep 2021 15:10:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVIUM-0008Fl-GM for guix-patches@gnu.org; Tue, 28 Sep 2021 15:10:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mVIUM-0005gV-9r for guix-patches@gnu.org; Tue, 28 Sep 2021 15:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 28 Sep 2021 19:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50874 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50874@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163285615921794 (code B ref -1); Tue, 28 Sep 2021 19:10:02 +0000 Received: (at submit) by debbugs.gnu.org; 28 Sep 2021 19:09:19 +0000 Received: from localhost ([127.0.0.1]:47008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVITf-0005fR-7b for submit@debbugs.gnu.org; Tue, 28 Sep 2021 15:09:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:50524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVITc-0005fH-Vg for submit@debbugs.gnu.org; Tue, 28 Sep 2021 15:09:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVITc-0000Id-I7 for guix-patches@gnu.org; Tue, 28 Sep 2021 15:09:16 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:55210 helo=mail.yoctocell.xyz) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVITa-0007XC-Oy for guix-patches@gnu.org; Tue, 28 Sep 2021 15:09:16 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1632856151; bh=87pvJRcTIZ6md0/oxoEicnuYl6vLgh09JJMH/G4RTfQ=; h=From:To:Subject:Date; b=G2voEGkMeXyNE9v8fZHtdmXgJ4jTx/26okBOrnIr5y7UWfefhdlNmMtosZxs657ZD YdMkbmixMfI9mhE9SMoHhuoZsbc05G0Vs6ydm31+vNO8Bzlx5yfII6DPr71eQcUFTB k5spVMMXa3kPSRfs3vaeT9TBlJMLnLTUSqUxQI9A= Message-Id: Date: Tue, 28 Sep 2021 21:09:10 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=87.96.130.155; envelope-from=public@yoctocell.xyz; helo=mail.yoctocell.xyz X-Spam_score_int: 39 X-Spam_score: 3.9 X-Spam_bar: +++ X-Spam_report: (3.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499, FROM_SUSPICIOUS_NTLD_FP=0.229, PDS_OTHER_BAD_TLD=1.999, PDS_RDNS_DYNAMIC_FP=0.001, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TO_NO_BRKTS_DYNIP=2.299 autolearn=no autolearn_force=no X-Spam_action: no action 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1632856549; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=dQqvSU7TL7+s8RbrraZ17zhHwGkSJysvZbYXcErcgpk=; b=MPJGRm5hrxMUNYWE6gCdqJAVTihcv0uNp4DVD/k0qAOs9x3HWLWCAYjvP//n0jR0RC8IFO 5H2Q5TdlWdVEgm++8i+cJehnCl1DNRePF1czYhQZkLJamABY3UTsAVO75BeddABjWx+sOB UVIGm6hq17ViMgQk9HhoWaA2w0buHL6ssu09SK4MeDcuR1x66EHyznIb0CVkYXwwr11igx JiwDbTMt5tSyeWh40KCYQHSUwF1As71Wnr5yXJ4w/ZwAevs8YVYSP8i5kAvKGqnf963At7 IqW5CjB6PNdP1Ee305vpRG7mUWIEY6ZWhOEwFLC0lX2OjOcA/xeHLjCMk8LPCw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1632856549; a=rsa-sha256; cv=none; b=c1aLp9lpFm+3D22+kCB+zC4O7foLOrMUbjYfZJb4e+HtODn6uw7XVIH/UJ6FQnPoZjmb/d NnNvMbObh18FdZW9RFjhRtFcd9xHrZQwf4PTHKPzyWKNsGRfl6TTqSWcDi9Qpg9hul13T2 NWk4UVF2uC+LUxOyOzFauO1bhFt1Z+/Xvb+khoKbO6tiyi/rCxsl1lGmBbLWy77dLwD2ML QpSbeWfGsb7h+ALHemL0MsSZSJJiGqZT9rAsBiz5RQIQEqdfVs+4YeB558/ma2fQy2TTOR Weny/DmHs4+Y1OZJMoAUL/4IQ9E7SuFgZU69YQH0duOVtpwVOrIA57V7XD68Ig== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=G2voEGkM; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 0.60 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=G2voEGkM; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: A8D2E2907 X-Spam-Score: 0.60 X-Migadu-Scanner: scn1.migadu.com X-TUID: mieUP+ONKxab * guix/lint.scm (check-if-https-uri-exists?): New procedure. (check-home-page, check-source): Use it. --- I don=E2=80=99t really know how to test this while making it future-proof, = any suggestions? guix/lint.scm | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/guix/lint.scm b/guix/lint.scm index 527fda165a..246a5ab9c8 100644 --- a/guix/lint.scm +++ b/guix/lint.scm @@ -875,17 +875,44 @@ (define (validate-uri uri package field) (else (error "internal linter error" status))))) =20 +(define (check-if-https-uri-exists? uri field package) + "Given a URI that uses HTTP, check whether a HTTPS version exists." + (guard (c ((http-get-error? c) + #f)) + (catch #t + (lambda () + (let* ((url (uri->string uri)) + (https-url (string-append + "https" (string-drop url (string-length "http")= ))) + (https-uri (string->uri https-url))) + (when (http-fetch/cached https-uri) + (make-warning package + (G_ "HTTPS version is available for: ~a") + (list url) + #:field field)))) + (match-lambda* + ((or ('gnutls-error _ ...) ('tls-certificate-error _ ...)) + #f) + (args + (apply throw args)))))) + (define (check-home-page package) "Emit a warning if PACKAGE has an invalid 'home-page' field, or if that 'home-page' is not reachable." - (let ((uri (and=3D> (package-home-page package) string->uri))) + (let* ((home-page (package-home-page package)) + (uri (and=3D> home-page string->uri))) (cond ((uri? uri) (match (validate-uri uri package 'home-page) ((and (? lint-warning? warning) warning) (list warning)) - (_ '()))) - ((not (package-home-page package)) + (_ (if (eq? (uri-scheme uri) 'http) + (match (check-if-https-uri-exists? uri 'home-page package) + ((? lint-warning? warning) + (list warning)) + (_ '())) + '())))) + ((not home-page) (if (or (string-contains (package-name package) "bootstrap") (string=3D? (package-name package) "ld-wrapper")) '() @@ -1079,8 +1106,12 @@ (define (warnings-for-uris uris) ((uri rest ...) (match (validate-uri uri package 'source) (#t - ;; We found a working URL, so stop right away. - '()) + (if (eq? (uri-scheme uri) 'http) + (match (check-if-https-uri-exists? uri 'source package) + ((? lint-warning? warning) + (list warning)) + (_ '())) + '())) (#f ;; Unsupported URL or other error, skip. (loop rest warnings)) base-commit: 009f0fc3dde0c2162c6df02fc4790a9f1d909e99 --=20 2.33.0