all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists.
@ 2021-09-28 19:09 Xinglu Chen
  2021-10-02 15:15 ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Xinglu Chen @ 2021-09-28 19:09 UTC (permalink / raw)
  To: 50874

* 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(-)

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))

base-commit: 009f0fc3dde0c2162c6df02fc4790a9f1d909e99
-- 
2.33.0







^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists.
  2021-09-28 19:09 [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists Xinglu Chen
@ 2021-10-02 15:15 ` Ludovic Courtès
  2021-10-09  9:57   ` Xinglu Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2021-10-02 15:15 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 50874

Hi,

Xinglu Chen <public@yoctocell.xyz> skribis:

> * guix/lint.scm (check-if-https-uri-exists?): New procedure.
> (check-home-page, check-source): Use it.

Applied, thanks!

> I don’t really know how to test this while making it future-proof, any
> suggestions?

I don’t know either, since we don’t have an easy way to spin up an HTTPS
server.  I think it’s okay to leave it as is, for lack of a better idea.

However, this version of the patch leads to test failures in
tests/lint.scm (“Connection refused”).

Ludo’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists.
  2021-10-02 15:15 ` Ludovic Courtès
@ 2021-10-09  9:57   ` Xinglu Chen
  2021-10-09 10:11     ` Xinglu Chen
  2021-10-10 13:12     ` Ludovic Courtès
  0 siblings, 2 replies; 5+ messages in thread
From: Xinglu Chen @ 2021-10-09  9:57 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 50874

[-- Attachment #1: Type: text/plain, Size: 747 bytes --]

On Sat, Oct 02 2021, Ludovic Courtès wrote:

> Hi,
>
> Xinglu Chen <public@yoctocell.xyz> skribis:
>
>> * guix/lint.scm (check-if-https-uri-exists?): New procedure.
>> (check-home-page, check-source): Use it.
>
> Applied, thanks!

Was it?  I don’t see it in the log.

>> I don’t really know how to test this while making it future-proof, any
>> suggestions?
>
> I don’t know either, since we don’t have an easy way to spin up an HTTPS
> server.  I think it’s okay to leave it as is, for lack of a better idea.
>
> However, this version of the patch leads to test failures in
> tests/lint.scm (“Connection refused”).

Thanks for catching this; I will look into it.  Good that you didn’t
apply it then.  :-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists.
  2021-10-09  9:57   ` Xinglu Chen
@ 2021-10-09 10:11     ` Xinglu Chen
  2021-10-10 13:12     ` Ludovic Courtès
  1 sibling, 0 replies; 5+ messages in thread
From: Xinglu Chen @ 2021-10-09 10:11 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 50874

[-- Attachment #1: Type: text/plain, Size: 911 bytes --]

On Sat, Oct 09 2021, Xinglu Chen wrote:

> On Sat, Oct 02 2021, Ludovic Courtès wrote:
>
>> Hi,
>>
>> Xinglu Chen <public@yoctocell.xyz> skribis:
>>
>>> * guix/lint.scm (check-if-https-uri-exists?): New procedure.
>>> (check-home-page, check-source): Use it.
>>
>> Applied, thanks!
>
> Was it?  I don’t see it in the log.
>
>>> I don’t really know how to test this while making it future-proof, any
>>> suggestions?
>>
>> I don’t know either, since we don’t have an easy way to spin up an HTTPS
>> server.  I think it’s okay to leave it as is, for lack of a better idea.
>>
>> However, this version of the patch leads to test failures in
>> tests/lint.scm (“Connection refused”).
>
> Thanks for catching this; I will look into it.  Good that you didn’t
> apply it then.  :-)

Hm, I am not able to reproduce this.  All the tests in ‘tests/lint.scm’
pass for me.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists.
  2021-10-09  9:57   ` Xinglu Chen
  2021-10-09 10:11     ` Xinglu Chen
@ 2021-10-10 13:12     ` Ludovic Courtès
  1 sibling, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2021-10-10 13:12 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 50874

Hi!

Xinglu Chen <public@yoctocell.xyz> skribis:

> On Sat, Oct 02 2021, Ludovic Courtès wrote:
>
>> Hi,
>>
>> Xinglu Chen <public@yoctocell.xyz> skribis:
>>
>>> * guix/lint.scm (check-if-https-uri-exists?): New procedure.
>>> (check-home-page, check-source): Use it.
>>
>> Applied, thanks!
>
> Was it?  I don’t see it in the log.

Actually no.  :-)  I initially applied it, started replying, noticed
there was a problem, and then sent that inconsistent reply.

>>> I don’t really know how to test this while making it future-proof, any
>>> suggestions?
>>
>> I don’t know either, since we don’t have an easy way to spin up an HTTPS
>> server.  I think it’s okay to leave it as is, for lack of a better idea.
>>
>> However, this version of the patch leads to test failures in
>> tests/lint.scm (“Connection refused”).
>
> Thanks for catching this; I will look into it.  Good that you didn’t
> apply it then.  :-)

Here’s what I see (among others):

--8<---------------cut here---------------start------------->8---
test-name: home-page: 200
location: /home/ludo/src/guix/tests/lint.scm:650
source:
+ (test-equal
+   "home-page: 200"
+   '()
+   (with-http-server
+     `((200 ,%long-string))
+     (let ((pkg (package
+                  (inherit (dummy-package "x"))
+                  (home-page (%local-url)))))
+       (check-home-page pkg))))
expected-value: ()
actual-value: #f
actual-error:
+ (system-error
+   connect*
+   "~A"
+   ("Connection refused")
+   (111))
result: FAIL

[…]

test-name: source: 200
location: /home/ludo/src/guix/tests/lint.scm:917
source:
+ (test-equal
+   "source: 200"
+   '()
+   (with-http-server
+     `((200 ,%long-string))
+     (let ((pkg (package
+                  (inherit (dummy-package "x"))
+                  (source
+                    (origin
+                      (method url-fetch)
+                      (uri (%local-url))
+                      (sha256 %null-sha256))))))
+       (check-source pkg))))
expected-value: ()
actual-value: #f
actual-error:
+ (system-error
+   connect*
+   "~A"
+   ("Connection refused")
+   (111))
result: FAIL
--8<---------------cut here---------------end--------------->8---

I believe that’s because, in addition to (%local-url), ‘check-home-page’
& co. now try to connect on port 443 of the same host, and there’s
nothing listening to that port on my machine.

Ludo’.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-10 13:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 19:09 [bug#50874] [PATCH] lint: Check if HTTPS version of HTTP URL exists Xinglu Chen
2021-10-02 15:15 ` Ludovic Courtès
2021-10-09  9:57   ` Xinglu Chen
2021-10-09 10:11     ` Xinglu Chen
2021-10-10 13:12     ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.