From patchwork Tue Sep 28 19:09:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 33401 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 85FDD27BBE3; Tue, 28 Sep 2021 20:16:00 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4EA1527BBE1 for ; Tue, 28 Sep 2021 20:16:00 +0100 (BST) Received: from localhost ([::1]:59060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVIa7-0000aR-F5 for patchwork@mira.cbaines.net; Tue, 28 Sep 2021 15:15:59 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/lint.scm (check-if-https-uri-exists?): New procedure. (check-home-page, check-source): Use it. --- I don’t really know how to test this while making it future-proof, any suggestions? guix/lint.scm | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) base-commit: 009f0fc3dde0c2162c6df02fc4790a9f1d909e99 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))))) +(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=> (package-home-page package) string->uri))) + (let* ((home-page (package-home-page package)) + (uri (and=> 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=? (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))