pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint pkgtools/pkglint: update to 19.4.7



details:   https://anonhg.NetBSD.org/pkgsrc/rev/62f59a3501f1
branches:  trunk
changeset: 422841:62f59a3501f1
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Feb 05 04:09:00 2020 +0000

description:
pkgtools/pkglint: update to 19.4.7

Changes since 19.4.6:

HOMEPAGE definitions that use http no longer get a warning that they
should migrate to https. Those that could be migrated have been migrated,
and the remaining homepages are not yet ready, so there's no benefit in
having this warning by default. Only in --network mode and when the https
site is indeed reachable, the warning is shown.

In long continued lines, the continuation backslash should be preceded by
a single space. Pkglint had wrongly removed that space in a few cases
before.

diffstat:

 pkgtools/pkglint/Makefile                     |    5 +-
 pkgtools/pkglint/files/homepage.go            |   89 ++++++++--------
 pkgtools/pkglint/files/homepage_test.go       |  137 +++++++++++++++++++------
 pkgtools/pkglint/files/line.go                |    3 +
 pkgtools/pkglint/files/logging.go             |    3 +
 pkgtools/pkglint/files/pkgver/vercmp_test.go  |   16 +++
 pkgtools/pkglint/files/redundantscope_test.go |    5 +-
 pkgtools/pkglint/files/varalignblock.go       |    6 +
 pkgtools/pkglint/files/varalignblock_test.go  |   25 ++++-
 pkgtools/pkglint/files/vartypecheck_test.go   |    1 -
 10 files changed, 204 insertions(+), 86 deletions(-)

diffs (truncated from 556 to 300 lines):

diff -r f552573a32e5 -r 62f59a3501f1 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Wed Feb 05 03:32:26 2020 +0000
+++ b/pkgtools/pkglint/Makefile Wed Feb 05 04:09:00 2020 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.629 2020/02/02 14:19:09 bsiegert Exp $
+# $NetBSD: Makefile,v 1.630 2020/02/05 04:09:00 rillig Exp $
 
-PKGNAME=       pkglint-19.4.6
-PKGREVISION=   1
+PKGNAME=       pkglint-19.4.7
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r f552573a32e5 -r 62f59a3501f1 pkgtools/pkglint/files/homepage.go
--- a/pkgtools/pkglint/files/homepage.go        Wed Feb 05 03:32:26 2020 +0000
+++ b/pkgtools/pkglint/files/homepage.go        Wed Feb 05 04:09:00 2020 +0000
@@ -40,10 +40,15 @@
        ValueNoVar string
        MkLine     *MkLine
        MkLines    *MkLines
+
+       // Can be mocked for the tests.
+       isReachable func(url string) YesNoUnknown
 }
 
 func NewHomepageChecker(value string, valueNoVar string, mkline *MkLine, mklines *MkLines) *HomepageChecker {
-       return &HomepageChecker{value, valueNoVar, mkline, mklines}
+       ck := HomepageChecker{value, valueNoVar, mkline, mklines, nil}
+       ck.isReachable = ck.isReachableOnline
+       return &ck
 }
 
 func (ck *HomepageChecker) Check() {
@@ -119,41 +124,41 @@
                return
        }
 
-       shouldAutofix, from, to := ck.toHttps(ck.Value)
-       if from == "" {
+       migrate, from, to := ck.migrate(ck.Value)
+       if !migrate {
                return
        }
 
        fix := ck.MkLine.Autofix()
        fix.Warnf("HOMEPAGE should migrate from %s to %s.", from, to)
-       if shouldAutofix {
-               fix.Replace(from, to)
+       fix.Replace(from, to)
+       if from == "http" && to == "https" {
+               fix.Explain(
+                       "To provide secure communication by default,",
+                       "the HOMEPAGE URL should use the https protocol if available.",
+                       "",
+                       "If the HOMEPAGE really does not support https,",
+                       "add a comment near the HOMEPAGE variable stating this clearly.")
        }
-       fix.Explain(
-               "To provide secure communication by default,",
-               "the HOMEPAGE URL should use the https protocol if available.",
-               "",
-               "If the HOMEPAGE really does not support https,",
-               "add a comment near the HOMEPAGE variable stating this clearly.")
        fix.Apply()
 }
 
-// toHttps checks whether the homepage should be migrated from http to https
+// migrate checks whether the homepage should be migrated from http to https
 // and which part of the homepage URL needs to be modified for that.
 //
 // If for some reason the https URL should not be reachable but the
 // corresponding http URL is, the homepage is changed back to http.
-func (ck *HomepageChecker) toHttps(url string) (bool, string, string) {
-       m, scheme, host, port := match3(url, `(https?)://([A-Za-z0-9-.]+)(:[0-9]+)?`)
-       if !m {
+func (ck *HomepageChecker) migrate(url string) (bool, string, string) {
+       m, scheme, host := match2(url, `(https?)://([A-Za-z0-9-.]+)(?:/|$)?`)
+       if !m || containsVarRefLong(url) {
                return false, "", ""
        }
 
-       if ck.hasAnySuffix(host,
-               "www.gnustep.org",           // 2020-01-18
-               "aspell.net",                // 2020-01-18
+       if scheme == "http" && ck.hasAnySuffix(host,
+               "www.gnustep.org",           // no https as of 2020-01-18
+               "aspell.net",                // no https as of 2020-01-18
                "downloads.sourceforge.net", // gets another warning already
-               ".dl.sourceforge.net",       // gets another warning already
+               "dl.sourceforge.net",        // gets another warning already
        ) {
                return false, "", ""
        }
@@ -174,39 +179,36 @@
                "nongnu.org",
                "tryton.org",
                "tug.org") {
-               return port == "", "http", "https"
+               return true, "http", "https"
        }
 
-       if scheme == "http" && host == "sf.net" {
-               return port == "", "http://sf.net";, "https://sourceforge.net";
+       if host == "sf.net" {
+               // sf.net redirects to sourceforge.net
+               return true, scheme + "://sf.net", "https://sourceforge.net";
        }
 
        from := scheme
        to := "https"
-       toReachable := unknown
 
        // SourceForge projects use either http://project.sourceforge.net or
        // https://project.sourceforge.io (not net).
-       if m, project := match1(host, `^([\w-]+)\.(?:sf|sourceforge)\.net$`); m {
+       if m, project, domain := match2(host, `^([\w-]+)\.((?:sf|sourceforge)\.net)$`); m {
+
                if scheme == "http" {
-                       from = scheme + "://" + host
                        // See https://sourceforge.net/p/forge/documentation/Custom%20VHOSTs
+                       from = "http://"; + host
                        to = "https://"; + project + ".sourceforge.io"
                } else {
-                       from = "sourceforge.net"
+                       from = domain
                        to = "sourceforge.io"
 
                        // Roll back wrong https SourceForge homepages generated by:
                        // https://mail-index.netbsd.org/pkgsrc-changes/2020/01/18/msg205146.html
-                       if port == "" && G.Opts.Network {
-                               _, migrated := replaceOnce(url, from, to)
-                               if ck.isReachable(migrated) == no {
-                                       ok, httpOnly := replaceOnce(url, "https://";, "http://";)
-                                       if ok && ck.isReachable(httpOnly) == yes && ck.isReachable(url) == no {
-                                               from = "https"
-                                               to = "http"
-                                               toReachable = yes
-                                       }
+                       _, migrated := replaceOnce(url, from, to)
+                       if ck.isReachable(migrated) == no {
+                               _, httpOnly := replaceOnce(url, "https://";, "http://";)
+                               if ck.isReachable(httpOnly) == yes && ck.isReachable(url) == no {
+                                       return true, "https", "http"
                                }
                        }
                }
@@ -216,16 +218,13 @@
                return false, "", ""
        }
 
-       shouldAutofix := toReachable == yes
-       if port == "" && G.Opts.Network && toReachable == unknown {
-               _, migrated := replaceOnce(url, from, to)
-               if ck.isReachable(migrated) == yes {
-                       shouldAutofix = true
-               } else {
-                       return false, "", ""
-               }
+       _, migrated := replaceOnce(url, from, to)
+       migrate := ck.isReachable(migrated)
+       if migrate == yes {
+               return true, from, to
        }
-       return shouldAutofix, from, to
+
+       return false, "", ""
 }
 
 func (ck *HomepageChecker) checkBadUrls() {
@@ -292,7 +291,7 @@
        }
 }
 
-func (*HomepageChecker) isReachable(url string) YesNoUnknown {
+func (*HomepageChecker) isReachableOnline(url string) YesNoUnknown {
        switch {
        case !G.Opts.Network,
                containsVarRefLong(url),
diff -r f552573a32e5 -r 62f59a3501f1 pkgtools/pkglint/files/homepage_test.go
--- a/pkgtools/pkglint/files/homepage_test.go   Wed Feb 05 03:32:26 2020 +0000
+++ b/pkgtools/pkglint/files/homepage_test.go   Wed Feb 05 04:09:00 2020 +0000
@@ -132,14 +132,8 @@
                "http://asf.net/";)
 
        vt.Output(
-               "WARN: filename.mk:2: HOMEPAGE should migrate from http to https.",
-               "WARN: filename.mk:3: HOMEPAGE should migrate "+
-                       "from http://project.sourceforge.net "+
-                       "to https://project.sourceforge.io.";,
-               "WARN: filename.mk:4: HOMEPAGE should migrate "+
-                       "from http://sf.net to https://sourceforge.net.";,
-               "WARN: filename.mk:5: HOMEPAGE should migrate from http to https.",
-               "WARN: filename.mk:8: HOMEPAGE should migrate from http to https.")
+               "WARN: filename.mk:4: HOMEPAGE should migrate " +
+                       "from http://sf.net to https://sourceforge.net.";)
 
        t.SetUpCommandLine("--autofix")
        vt.Values(
@@ -162,38 +156,119 @@
                "AUTOFIX: filename.mk:18: Replacing \"http\" with \"https\".")
 }
 
-func (s *Suite) Test_HomepageChecker_toHttps(c *check.C) {
+func (s *Suite) Test_HomepageChecker_migrate(c *check.C) {
        t := s.Init(c)
 
-       test := func(url string, shouldAutofix bool, from, to string) {
-               toHttps := (*HomepageChecker).toHttps
-               actualShouldAutofix, actualFrom, actualTo := toHttps(nil, url)
-               t.CheckDeepEquals(
-                       []interface{}{actualShouldAutofix, actualFrom, actualTo},
-                       []interface{}{shouldAutofix, from, to})
+       reachable := map[string]YesNoUnknown{}
+       used := map[string]bool{}
+
+       isReachable := func(url string) YesNoUnknown {
+               if r, ok := reachable[url]; ok {
+                       used[url] = true
+                       return r
+               }
+               panic(url)
        }
 
-       test("http://localhost/";, false, "http", "https")
+       test := func(url string, migrate bool, from, to string) {
+               ck := NewHomepageChecker(url, url, nil, nil)
+               ck.isReachable = isReachable
+
+               actualMigrate, actualFrom, actualTo := ck.migrate(url)
+
+               t.CheckDeepEquals(
+                       []interface{}{actualMigrate, actualFrom, actualTo},
+                       []interface{}{migrate, from, to})
+
+               for key, _ := range reachable {
+                       assertf(used[key], "Reachability of %q was not used.", key)
+                       delete(reachable, key)
+               }
+       }
 
+       reachable["https://localhost/";] = unknown
+       test(
+               "http://localhost/";,
+               false,
+               "",
+               "")
+
+       reachable["https://localhost/";] = yes
+       test(
+               "http://localhost/";,
+               true,
+               "http",
+               "https")
+
+       reachable["https://project.sourceforge.io/";] = unknown
        test(
                "http://project.sourceforge.net/";,
                false,
+               "",
+               "")
+
+       reachable["https://project.sourceforge.io/";] = yes
+       test(
+               "http://project.sourceforge.net/";,
+               true,
                "http://project.sourceforge.net";,
                "https://project.sourceforge.io";)
 
        // To clean up the wrong autofix from 2020-01-18:
        // https://mail-index.netbsd.org/pkgsrc-changes/2020/01/18/msg205146.html
+       reachable["https://project.sourceforge.io/";] = yes
        test(
                "https://project.sourceforge.net/";,
-               false,
+               true,
                "sourceforge.net",
                "sourceforge.io")
 
+       // To clean up the wrong autofix from 2020-01-18:
+       // https://mail-index.netbsd.org/pkgsrc-changes/2020/01/18/msg205146.html
+       //
+       // If neither of the https URLs is reachable, the homepage
+       // is rolled back to the http URL.
+       reachable["https://project.sourceforge.io/";] = no
+       reachable["http://project.sourceforge.net/";] = yes
+       reachable["https://project.sourceforge.net/";] = no
+       test(
+               "https://project.sourceforge.net/";,
+               true,
+               "https",
+               "http")
+
+       // To clean up the wrong autofix from 2020-01-18:
+       // https://mail-index.netbsd.org/pkgsrc-changes/2020/01/18/msg205146.html
+       //
+       // If the https URL of sourceforge.net is reachable,
+       // it is preferred over the http URL,
+       // even though it is not mentioned in the SourceForge documentation.
+       reachable["https://project.sourceforge.io/";] = no
+       reachable["http://project.sourceforge.net/";] = yes



Home | Main Index | Thread Index | Old Index