diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index 64bd63dd00..c906ef2c6e 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -21,9 +21,9 @@ jobs: uses: golangci/golangci-lint-action@v6 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.54 + version: v1.61 args: --timeout=10m - + # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/config/config_test.go b/config/config_test.go index 284a802d7c..ce466b8d08 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -3,7 +3,7 @@ package config import ( "testing" - . "github.com/future-architect/vuls/constant" + "github.com/future-architect/vuls/constant" ) func TestDistro_MajorVersion(t *testing.T) { @@ -13,28 +13,28 @@ func TestDistro_MajorVersion(t *testing.T) { }{ { in: Distro{ - Family: Amazon, + Family: constant.Amazon, Release: "2022 (Amazon Linux)", }, out: 2022, }, { in: Distro{ - Family: Amazon, + Family: constant.Amazon, Release: "2 (2017.12)", }, out: 2, }, { in: Distro{ - Family: Amazon, + Family: constant.Amazon, Release: "2017.12", }, out: 1, }, { in: Distro{ - Family: CentOS, + Family: constant.CentOS, Release: "7.10", }, out: 7, diff --git a/config/os_test.go b/config/os_test.go index d37bfb2646..312bf980bd 100644 --- a/config/os_test.go +++ b/config/os_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - . "github.com/future-architect/vuls/constant" + "github.com/future-architect/vuls/constant" ) func TestEOL_IsStandardSupportEnded(t *testing.T) { @@ -23,7 +23,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { // Amazon Linux { name: "amazon linux 1 supported", - fields: fields{family: Amazon, release: "2018.03"}, + fields: fields{family: constant.Amazon, release: "2018.03"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -31,7 +31,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "amazon linux 1 eol on 2023-12-31", - fields: fields{family: Amazon, release: "2018.03"}, + fields: fields{family: constant.Amazon, release: "2018.03"}, now: time.Date(2024, 1, 1, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -39,7 +39,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "amazon linux 2 supported", - fields: fields{family: Amazon, release: "2 (Karoo)"}, + fields: fields{family: constant.Amazon, release: "2 (Karoo)"}, now: time.Date(2023, 7, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -47,7 +47,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "amazon linux 2022 supported", - fields: fields{family: Amazon, release: "2022 (Amazon Linux)"}, + fields: fields{family: constant.Amazon, release: "2022 (Amazon Linux)"}, now: time.Date(2023, 7, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -55,7 +55,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "amazon linux 2023 supported", - fields: fields{family: Amazon, release: "2023"}, + fields: fields{family: constant.Amazon, release: "2023"}, now: time.Date(2023, 7, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -63,7 +63,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "amazon linux 2031 not found", - fields: fields{family: Amazon, release: "2031"}, + fields: fields{family: constant.Amazon, release: "2031"}, now: time.Date(2023, 7, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -72,7 +72,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { //RHEL { name: "RHEL6 eol", - fields: fields{family: RedHat, release: "6"}, + fields: fields{family: constant.RedHat, release: "6"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: false, @@ -80,7 +80,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "RHEL7 supported", - fields: fields{family: RedHat, release: "7"}, + fields: fields{family: constant.RedHat, release: "7"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -88,7 +88,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "RHEL8 supported", - fields: fields{family: RedHat, release: "8"}, + fields: fields{family: constant.RedHat, release: "8"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -96,7 +96,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "RHEL9 supported", - fields: fields{family: RedHat, release: "9"}, + fields: fields{family: constant.RedHat, release: "9"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -104,7 +104,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "RHEL10 not found", - fields: fields{family: RedHat, release: "10"}, + fields: fields{family: constant.RedHat, release: "10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -113,7 +113,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { //CentOS { name: "CentOS 6 eol", - fields: fields{family: CentOS, release: "6"}, + fields: fields{family: constant.CentOS, release: "6"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -121,7 +121,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "CentOS 7 supported", - fields: fields{family: CentOS, release: "7"}, + fields: fields{family: constant.CentOS, release: "7"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -129,7 +129,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "CentOS 8 supported", - fields: fields{family: CentOS, release: "8"}, + fields: fields{family: constant.CentOS, release: "8"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -137,7 +137,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "CentOS stream8 supported", - fields: fields{family: CentOS, release: "stream8"}, + fields: fields{family: constant.CentOS, release: "stream8"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -145,7 +145,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "CentOS stream9 supported", - fields: fields{family: CentOS, release: "stream9"}, + fields: fields{family: constant.CentOS, release: "stream9"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -153,7 +153,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "CentOS stream10 Not Found", - fields: fields{family: CentOS, release: "stream10"}, + fields: fields{family: constant.CentOS, release: "stream10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -162,7 +162,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { // Alma { name: "Alma Linux 8 supported", - fields: fields{family: Alma, release: "8"}, + fields: fields{family: constant.Alma, release: "8"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -170,7 +170,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alma Linux 9 supported", - fields: fields{family: Alma, release: "9"}, + fields: fields{family: constant.Alma, release: "9"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -178,7 +178,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alma Linux 10 Not Found", - fields: fields{family: Alma, release: "10"}, + fields: fields{family: constant.Alma, release: "10"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -187,7 +187,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { // Rocky { name: "Rocky Linux 8 supported", - fields: fields{family: Rocky, release: "8"}, + fields: fields{family: constant.Rocky, release: "8"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -195,7 +195,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Rocky Linux 9 supported", - fields: fields{family: Rocky, release: "9"}, + fields: fields{family: constant.Rocky, release: "9"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -203,7 +203,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Rocky Linux 10 Not Found", - fields: fields{family: Rocky, release: "10"}, + fields: fields{family: constant.Rocky, release: "10"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -212,7 +212,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { //Oracle { name: "Oracle Linux 6 eol", - fields: fields{family: Oracle, release: "6"}, + fields: fields{family: constant.Oracle, release: "6"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -220,7 +220,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Oracle Linux 7 supported", - fields: fields{family: Oracle, release: "7"}, + fields: fields{family: constant.Oracle, release: "7"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -228,7 +228,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Oracle Linux 8 supported", - fields: fields{family: Oracle, release: "8"}, + fields: fields{family: constant.Oracle, release: "8"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -236,7 +236,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Oracle Linux 9 supported", - fields: fields{family: Oracle, release: "9"}, + fields: fields{family: constant.Oracle, release: "9"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -244,7 +244,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Oracle Linux 10 not found", - fields: fields{family: Oracle, release: "10"}, + fields: fields{family: constant.Oracle, release: "10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -253,7 +253,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { //Ubuntu { name: "Ubuntu 5.10 not found", - fields: fields{family: Ubuntu, release: "5.10"}, + fields: fields{family: constant.Ubuntu, release: "5.10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), found: false, stdEnded: false, @@ -261,7 +261,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 14.04 eol", - fields: fields{family: Ubuntu, release: "14.04"}, + fields: fields{family: constant.Ubuntu, release: "14.04"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: false, @@ -269,7 +269,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 14.10 eol", - fields: fields{family: Ubuntu, release: "14.10"}, + fields: fields{family: constant.Ubuntu, release: "14.10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -277,7 +277,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 16.04 supported", - fields: fields{family: Ubuntu, release: "18.04"}, + fields: fields{family: constant.Ubuntu, release: "18.04"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -285,7 +285,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 18.04 supported", - fields: fields{family: Ubuntu, release: "18.04"}, + fields: fields{family: constant.Ubuntu, release: "18.04"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -293,7 +293,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 18.04 ext supported", - fields: fields{family: Ubuntu, release: "18.04"}, + fields: fields{family: constant.Ubuntu, release: "18.04"}, now: time.Date(2025, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: false, @@ -301,7 +301,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 20.04 supported", - fields: fields{family: Ubuntu, release: "20.04"}, + fields: fields{family: constant.Ubuntu, release: "20.04"}, now: time.Date(2021, 5, 1, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -309,7 +309,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 20.04 ext supported", - fields: fields{family: Ubuntu, release: "20.04"}, + fields: fields{family: constant.Ubuntu, release: "20.04"}, now: time.Date(2025, 5, 1, 23, 59, 59, 0, time.UTC), found: true, stdEnded: true, @@ -317,7 +317,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 20.10 supported", - fields: fields{family: Ubuntu, release: "20.10"}, + fields: fields{family: constant.Ubuntu, release: "20.10"}, now: time.Date(2021, 5, 1, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -325,7 +325,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 21.04 supported", - fields: fields{family: Ubuntu, release: "21.04"}, + fields: fields{family: constant.Ubuntu, release: "21.04"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -333,7 +333,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 21.10 supported", - fields: fields{family: Ubuntu, release: "21.10"}, + fields: fields{family: constant.Ubuntu, release: "21.10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -341,7 +341,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 22.04 supported", - fields: fields{family: Ubuntu, release: "22.04"}, + fields: fields{family: constant.Ubuntu, release: "22.04"}, now: time.Date(2022, 5, 1, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -349,7 +349,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 22.10 supported", - fields: fields{family: Ubuntu, release: "22.10"}, + fields: fields{family: constant.Ubuntu, release: "22.10"}, now: time.Date(2022, 5, 1, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -357,7 +357,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 23.04 supported", - fields: fields{family: Ubuntu, release: "23.04"}, + fields: fields{family: constant.Ubuntu, release: "23.04"}, now: time.Date(2023, 3, 16, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -365,7 +365,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 23.10 supported", - fields: fields{family: Ubuntu, release: "23.10"}, + fields: fields{family: constant.Ubuntu, release: "23.10"}, now: time.Date(2024, 7, 11, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -373,7 +373,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Ubuntu 24.04 supported", - fields: fields{family: Ubuntu, release: "24.04"}, + fields: fields{family: constant.Ubuntu, release: "24.04"}, now: time.Date(2029, 6, 30, 23, 59, 59, 0, time.UTC), found: true, stdEnded: false, @@ -382,7 +382,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { //Debian { name: "Debian 8 supported", - fields: fields{family: Debian, release: "8"}, + fields: fields{family: constant.Debian, release: "8"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -390,7 +390,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Debian 9 supported", - fields: fields{family: Debian, release: "9"}, + fields: fields{family: constant.Debian, release: "9"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -398,7 +398,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Debian 10 supported", - fields: fields{family: Debian, release: "10"}, + fields: fields{family: constant.Debian, release: "10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -406,7 +406,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Debian 11 supported", - fields: fields{family: Debian, release: "11"}, + fields: fields{family: constant.Debian, release: "11"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -414,7 +414,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Debian 12 supported", - fields: fields{family: Debian, release: "12"}, + fields: fields{family: constant.Debian, release: "12"}, now: time.Date(2023, 6, 10, 0, 0, 0, 0, time.UTC), stdEnded: false, extEnded: false, @@ -422,7 +422,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Debian 13 is not supported yet", - fields: fields{family: Debian, release: "13"}, + fields: fields{family: constant.Debian, release: "13"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -431,7 +431,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { //alpine { name: "alpine 3.10 supported", - fields: fields{family: Alpine, release: "3.10"}, + fields: fields{family: constant.Alpine, release: "3.10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -439,7 +439,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.11 supported", - fields: fields{family: Alpine, release: "3.11"}, + fields: fields{family: constant.Alpine, release: "3.11"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -447,7 +447,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.12 supported", - fields: fields{family: Alpine, release: "3.12"}, + fields: fields{family: constant.Alpine, release: "3.12"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -455,7 +455,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.9 eol", - fields: fields{family: Alpine, release: "3.9"}, + fields: fields{family: constant.Alpine, release: "3.9"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -463,7 +463,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.14 supported", - fields: fields{family: Alpine, release: "3.14"}, + fields: fields{family: constant.Alpine, release: "3.14"}, now: time.Date(2022, 5, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -471,7 +471,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.15 supported", - fields: fields{family: Alpine, release: "3.15"}, + fields: fields{family: constant.Alpine, release: "3.15"}, now: time.Date(2022, 11, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -479,7 +479,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.16 supported", - fields: fields{family: Alpine, release: "3.16"}, + fields: fields{family: constant.Alpine, release: "3.16"}, now: time.Date(2024, 5, 23, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -487,7 +487,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.17 supported", - fields: fields{family: Alpine, release: "3.17"}, + fields: fields{family: constant.Alpine, release: "3.17"}, now: time.Date(2022, 1, 14, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -495,7 +495,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.18 supported", - fields: fields{family: Alpine, release: "3.18"}, + fields: fields{family: constant.Alpine, release: "3.18"}, now: time.Date(2025, 5, 9, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -503,7 +503,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.19 supported", - fields: fields{family: Alpine, release: "3.19"}, + fields: fields{family: constant.Alpine, release: "3.19"}, now: time.Date(2025, 11, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -511,7 +511,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.20 supported", - fields: fields{family: Alpine, release: "3.20"}, + fields: fields{family: constant.Alpine, release: "3.20"}, now: time.Date(2026, 4, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -519,7 +519,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Alpine 3.21 not found", - fields: fields{family: Alpine, release: "3.21"}, + fields: fields{family: constant.Alpine, release: "3.21"}, now: time.Date(2026, 4, 1, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -528,7 +528,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { // freebsd { name: "freebsd 10 eol", - fields: fields{family: FreeBSD, release: "10"}, + fields: fields{family: constant.FreeBSD, release: "10"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -536,7 +536,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "freebsd 11 supported", - fields: fields{family: FreeBSD, release: "11"}, + fields: fields{family: constant.FreeBSD, release: "11"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -544,7 +544,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "freebsd 11 eol on 2021-9-30", - fields: fields{family: FreeBSD, release: "11"}, + fields: fields{family: constant.FreeBSD, release: "11"}, now: time.Date(2021, 10, 1, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -552,7 +552,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "freebsd 12 supported", - fields: fields{family: FreeBSD, release: "12"}, + fields: fields{family: constant.FreeBSD, release: "12"}, now: time.Date(2021, 1, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -560,7 +560,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "freebsd 13 supported", - fields: fields{family: FreeBSD, release: "13"}, + fields: fields{family: constant.FreeBSD, release: "13"}, now: time.Date(2021, 7, 2, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -568,7 +568,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "freebsd 14 supported", - fields: fields{family: FreeBSD, release: "14"}, + fields: fields{family: constant.FreeBSD, release: "14"}, now: time.Date(2028, 11, 21, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -577,7 +577,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { // Fedora { name: "Fedora 32 supported", - fields: fields{family: Fedora, release: "32"}, + fields: fields{family: constant.Fedora, release: "32"}, now: time.Date(2021, 5, 24, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -585,7 +585,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 32 eol since 2021-5-25", - fields: fields{family: Fedora, release: "32"}, + fields: fields{family: constant.Fedora, release: "32"}, now: time.Date(2021, 5, 25, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -593,7 +593,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 33 supported", - fields: fields{family: Fedora, release: "33"}, + fields: fields{family: constant.Fedora, release: "33"}, now: time.Date(2021, 11, 29, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -601,7 +601,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 33 eol since 2021-11-30", - fields: fields{family: Fedora, release: "32"}, + fields: fields{family: constant.Fedora, release: "32"}, now: time.Date(2021, 11, 30, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -609,7 +609,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 34 supported", - fields: fields{family: Fedora, release: "34"}, + fields: fields{family: constant.Fedora, release: "34"}, now: time.Date(2022, 6, 6, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -617,7 +617,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 34 eol since 2022-6-7", - fields: fields{family: Fedora, release: "34"}, + fields: fields{family: constant.Fedora, release: "34"}, now: time.Date(2022, 6, 7, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -625,7 +625,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 35 supported", - fields: fields{family: Fedora, release: "35"}, + fields: fields{family: constant.Fedora, release: "35"}, now: time.Date(2022, 12, 12, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -633,7 +633,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 35 eol since 2022-12-13", - fields: fields{family: Fedora, release: "35"}, + fields: fields{family: constant.Fedora, release: "35"}, now: time.Date(2022, 12, 13, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -641,7 +641,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 36 supported", - fields: fields{family: Fedora, release: "36"}, + fields: fields{family: constant.Fedora, release: "36"}, now: time.Date(2023, 5, 16, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -649,7 +649,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 36 eol since 2023-05-17", - fields: fields{family: Fedora, release: "36"}, + fields: fields{family: constant.Fedora, release: "36"}, now: time.Date(2023, 5, 17, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -657,7 +657,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 37 supported", - fields: fields{family: Fedora, release: "37"}, + fields: fields{family: constant.Fedora, release: "37"}, now: time.Date(2023, 12, 5, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -665,7 +665,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 37 eol since 2023-12-6", - fields: fields{family: Fedora, release: "37"}, + fields: fields{family: constant.Fedora, release: "37"}, now: time.Date(2023, 12, 6, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -673,7 +673,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 38 supported", - fields: fields{family: Fedora, release: "38"}, + fields: fields{family: constant.Fedora, release: "38"}, now: time.Date(2024, 5, 21, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -681,7 +681,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 38 eol since 2024-05-22", - fields: fields{family: Fedora, release: "38"}, + fields: fields{family: constant.Fedora, release: "38"}, now: time.Date(2024, 5, 22, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -689,7 +689,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 39 supported", - fields: fields{family: Fedora, release: "39"}, + fields: fields{family: constant.Fedora, release: "39"}, now: time.Date(2024, 11, 12, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -697,7 +697,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 39 eol since 2024-11-13", - fields: fields{family: Fedora, release: "39"}, + fields: fields{family: constant.Fedora, release: "39"}, now: time.Date(2024, 11, 13, 0, 0, 0, 0, time.UTC), stdEnded: true, extEnded: true, @@ -705,7 +705,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Fedora 40 supported", - fields: fields{family: Fedora, release: "40"}, + fields: fields{family: constant.Fedora, release: "40"}, now: time.Date(2025, 5, 13, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -713,7 +713,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Windows 10 EOL", - fields: fields{family: Windows, release: "Windows 10 for x64-based Systems"}, + fields: fields{family: constant.Windows, release: "Windows 10 for x64-based Systems"}, now: time.Date(2022, 12, 8, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -721,7 +721,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Windows 10 Version 22H2 supported", - fields: fields{family: Windows, release: "Windows 10 Version 22H2 for x64-based Systems"}, + fields: fields{family: constant.Windows, release: "Windows 10 Version 22H2 for x64-based Systems"}, now: time.Date(2022, 12, 8, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, @@ -729,7 +729,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "Mac OS X 10.15 EOL", - fields: fields{family: MacOSX, release: "10.15.7"}, + fields: fields{family: constant.MacOSX, release: "10.15.7"}, now: time.Date(2023, 7, 25, 23, 59, 59, 0, time.UTC), stdEnded: true, extEnded: true, @@ -737,7 +737,7 @@ func TestEOL_IsStandardSupportEnded(t *testing.T) { }, { name: "macOS 13.4.1 supported", - fields: fields{family: MacOS, release: "13.4.1"}, + fields: fields{family: constant.MacOS, release: "13.4.1"}, now: time.Date(2023, 7, 25, 23, 59, 59, 0, time.UTC), stdEnded: false, extEnded: false, diff --git a/contrib/future-vuls/cmd/main.go b/contrib/future-vuls/cmd/main.go index 2b56c8ef1e..c2aa52fe3a 100644 --- a/contrib/future-vuls/cmd/main.go +++ b/contrib/future-vuls/cmd/main.go @@ -40,7 +40,7 @@ func main() { Use: "version", Short: "Show version", Long: "Show version", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Printf("future-vuls-%s-%s\n", vulsConfig.Version, vulsConfig.Revision) }, } @@ -49,7 +49,7 @@ func main() { Use: "upload", Short: "Upload to FutureVuls", Long: `Upload to FutureVuls`, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if len(serverUUID) == 0 { serverUUID = os.Getenv("VULS_SERVER_UUID") } @@ -90,7 +90,7 @@ func main() { Use: "discover --cidr --output ", Short: "discover hosts with CIDR range. Run snmp2cpe on active host to get CPE. Default outputFile is ./discover_list.toml", Example: "future-vuls discover --cidr 192.168.0.0/24 --output discover_list.toml", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if len(outputFile) == 0 { outputFile = config.DiscoverTomlFileName } @@ -122,7 +122,7 @@ func main() { Use: "add-cpe --token --output ", Short: "Create a pseudo server in Fvuls and register CPE. Default outputFile is ./discover_list.toml", Example: "future-vuls add-cpe --token ", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if len(token) == 0 { token = os.Getenv("VULS_TOKEN") if len(token) == 0 { diff --git a/contrib/future-vuls/pkg/discover/discover.go b/contrib/future-vuls/pkg/discover/discover.go index 178ef0f7bf..f593450b1e 100644 --- a/contrib/future-vuls/pkg/discover/discover.go +++ b/contrib/future-vuls/pkg/discover/discover.go @@ -4,7 +4,6 @@ package discover import ( "encoding/json" "fmt" - "io" "os" "os/exec" "time" @@ -111,7 +110,7 @@ func executeSnmp2cpe(addr string, snmpVersion string, community string) (cpes ma if err != nil { return nil, fmt.Errorf("failed to convert snmp2cpe result. err: %v", err) } - if _, err := io.WriteString(stdin, string(result)); err != nil { + if _, err := stdin.Write(result); err != nil { return nil, fmt.Errorf("failed to write to stdIn. err: %v", err) } stdin.Close() diff --git a/contrib/trivy/cmd/main.go b/contrib/trivy/cmd/main.go index 9fa6012618..d651d9f78b 100644 --- a/contrib/trivy/cmd/main.go +++ b/contrib/trivy/cmd/main.go @@ -26,7 +26,7 @@ func main() { Use: "parse", Short: "Parse trivy json to vuls results", Long: `Parse trivy json to vuls results`, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { jsonFilePath := filepath.Join(jsonDir, jsonFileName) var trivyJSON []byte if stdIn { @@ -67,7 +67,7 @@ func main() { Use: "version", Short: "Show version", Long: "Show version", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Printf("trivy-to-vuls-%s-%s\n", config.Version, config.Revision) }, } diff --git a/detector/wordpress.go b/detector/wordpress.go index b08aea8a9d..53ef13a829 100644 --- a/detector/wordpress.go +++ b/detector/wordpress.go @@ -313,15 +313,16 @@ func httpRequest(url, token string) (string, error) { fmt.Sprintf("Failed to access to wpscan.com. err: %s", err)) } defer resp.Body.Close() - if resp.StatusCode == 200 { + switch resp.StatusCode { + case 200: return string(body), nil - } else if resp.StatusCode == 404 { + case 404: // This package is not in wpscan return "", nil - } else if resp.StatusCode == 429 { + case 429: return "", errof.New(errof.ErrWpScanAPILimitExceeded, fmt.Sprintf("wpscan.com API limit exceeded: %+v", resp.Status)) - } else { + default: logging.Log.Warnf("wpscan.com unknown status code: %+v", resp.Status) return "", nil } diff --git a/go.mod b/go.mod index 5ee5cf17b5..2e1d27f0d1 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/future-architect/vuls -go 1.22.0 - -toolchain go1.22.3 +go 1.23 require ( github.com/3th1nk/cidr v0.2.0 @@ -406,3 +404,6 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) + +// see https://github.com/aquasecurity/trivy/pull/7427, remove when updating trivy to v0.56.0 +replace github.com/open-policy-agent/opa => github.com/nikpivkin/opa v0.0.0-20240829080621-16999fcb5464 diff --git a/go.sum b/go.sum index 957c59b234..4dd2dcca6d 100644 --- a/go.sum +++ b/go.sum @@ -1120,6 +1120,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/nikpivkin/opa v0.0.0-20240829080621-16999fcb5464 h1:jhZ8nLVxOAslgzmPdKTyctfDJkMfRgksCypFriHzf4E= +github.com/nikpivkin/opa v0.0.0-20240829080621-16999fcb5464/go.mod h1:cvSIxY0dexL39hOPqXSZKdBYFNx2Rv8Fu5n3MmTjqtE= github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481 h1:Up6+btDp321ZG5/zdSLo48H9Iaq0UQGthrhWC6pCxzE= @@ -1149,8 +1151,6 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.31.0 h1:54UJxxj6cPInHS3a35wm6BK/F9nHYueZ1NVujHDrnXE= github.com/onsi/gomega v1.31.0/go.mod h1:DW9aCi7U6Yi40wNVAvT6kzFnEVEI5n3DloYBiKiT6zk= -github.com/open-policy-agent/opa v0.68.0 h1:Jl3U2vXRjwk7JrHmS19U3HZO5qxQRinQbJ2eCJYSqJQ= -github.com/open-policy-agent/opa v0.68.0/go.mod h1:5E5SvaPwTpwt2WM177I9Z3eT7qUpmOGjk1ZdHs+TZ4w= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= diff --git a/reporter/azureblob.go b/reporter/azureblob.go index dbc8ebb74f..e199539300 100644 --- a/reporter/azureblob.go +++ b/reporter/azureblob.go @@ -36,8 +36,7 @@ func (w AzureBlobWriter) Write(rs ...models.ScanResult) (err error) { } if w.FormatOneLineText { - timestr := rs[0].ScannedAt.Format(time.RFC3339) - k := fmt.Sprintf(timestr + "/summary.txt") + k := fmt.Sprintf("%s/summary.txt", rs[0].ScannedAt.Format(time.RFC3339)) text := formatOneLineSummary(rs...) b := []byte(text) if err := w.createBlockBlob(cli, k, b, w.Gzip); err != nil { diff --git a/reporter/s3.go b/reporter/s3.go index d356326c5a..0fdf369fbd 100644 --- a/reporter/s3.go +++ b/reporter/s3.go @@ -73,8 +73,7 @@ func (w S3Writer) Write(rs ...models.ScanResult) (err error) { } if w.FormatOneLineText { - timestr := rs[0].ScannedAt.Format(time.RFC3339) - k := fmt.Sprintf(timestr + "/summary.txt") + k := fmt.Sprintf("%s/summary.txt", rs[0].ScannedAt.Format(time.RFC3339)) text := formatOneLineSummary(rs...) if err := w.putObject(svc, k, []byte(text), w.Gzip); err != nil { return err diff --git a/scanner/alma.go b/scanner/alma.go index 0e238ca6ff..154ff585ef 100644 --- a/scanner/alma.go +++ b/scanner/alma.go @@ -36,11 +36,11 @@ func (o *alma) checkScanMode() error { func (o *alma) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else { - return o.execCheckDeps(o.depsDeep()) } + return o.execCheckDeps(o.depsDeep()) } func (o *alma) depsFast() []string { @@ -70,11 +70,11 @@ func (o *alma) depsDeep() []string { func (o *alma) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *alma) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/amazon.go b/scanner/amazon.go index 8c07a82680..569cc276b2 100644 --- a/scanner/amazon.go +++ b/scanner/amazon.go @@ -41,9 +41,11 @@ func (o *amazon) checkScanMode() error { func (o *amazon) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else if o.getServerInfo().Mode.IsDeep() { + } + if o.getServerInfo().Mode.IsDeep() { return o.execCheckDeps(o.depsDeep()) } return xerrors.New("Unknown scan mode") @@ -84,11 +86,11 @@ func (o *amazon) depsDeep() []string { func (o *amazon) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *amazon) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/centos.go b/scanner/centos.go index bb6fb872d4..808cbec1b2 100644 --- a/scanner/centos.go +++ b/scanner/centos.go @@ -36,11 +36,11 @@ func (o *centos) checkScanMode() error { func (o *centos) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else { - return o.execCheckDeps(o.depsDeep()) } + return o.execCheckDeps(o.depsDeep()) } func (o *centos) depsFast() []string { @@ -70,11 +70,11 @@ func (o *centos) depsDeep() []string { func (o *centos) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *centos) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/debian_test.go b/scanner/debian_test.go index 233e4f2711..df9d682083 100644 --- a/scanner/debian_test.go +++ b/scanner/debian_test.go @@ -221,7 +221,7 @@ systemd (228-5) unstable; urgency=medium`, aCveIDs, aPack := d.getCveIDsFromChangelog(tt.in[2], tt.in[0], tt.in[1]) if len(aCveIDs) != len(tt.cveIDs) { t.Errorf("[%d] Len of return array aren't same. expected %#v, actual %#v", i, tt.cveIDs, aCveIDs) - t.Errorf(pp.Sprintf("%s", tt.in)) + t.Error(pp.Sprintf("%s", tt.in)) continue } for j := range tt.cveIDs { diff --git a/scanner/fedora.go b/scanner/fedora.go index d66cce48eb..09f0b59ff5 100644 --- a/scanner/fedora.go +++ b/scanner/fedora.go @@ -36,11 +36,11 @@ func (o *fedora) checkScanMode() error { func (o *fedora) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else { - return o.execCheckDeps(o.depsDeep()) } + return o.execCheckDeps(o.depsDeep()) } func (o *fedora) depsFast() []string { @@ -68,11 +68,11 @@ func (o *fedora) depsDeep() []string { func (o *fedora) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *fedora) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/library.go b/scanner/library.go index aecbb99201..e564ea82fd 100644 --- a/scanner/library.go +++ b/scanner/library.go @@ -12,7 +12,7 @@ import ( func convertLibWithScanner(apps []ftypes.Application) ([]models.LibraryScanner, error) { for i := range apps { - apps[i].Packages = lo.Filter(apps[i].Packages, func(lib ftypes.Package, index int) bool { + apps[i].Packages = lo.Filter(apps[i].Packages, func(lib ftypes.Package, _ int) bool { return !lib.Dev }) } diff --git a/scanner/oracle.go b/scanner/oracle.go index d9cb6f7291..66ed267da3 100644 --- a/scanner/oracle.go +++ b/scanner/oracle.go @@ -36,11 +36,11 @@ func (o *oracle) checkScanMode() error { func (o *oracle) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else { - return o.execCheckDeps(o.depsDeep()) } + return o.execCheckDeps(o.depsDeep()) } func (o *oracle) depsFast() []string { @@ -62,11 +62,11 @@ func (o *oracle) depsDeep() []string { func (o *oracle) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *oracle) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/redhatbase.go b/scanner/redhatbase.go index a302d96454..8b65d67c04 100644 --- a/scanner/redhatbase.go +++ b/scanner/redhatbase.go @@ -371,9 +371,8 @@ func (o *redhatBase) execCheckDeps(packNames []string) error { for _, name := range packNames { cmd := "rpm -q " + name if r := o.exec(cmd, noSudo); !r.isSuccess() { - msg := fmt.Sprintf("%s is not installed", name) - o.log.Errorf(msg) - return xerrors.New(msg) + o.log.Errorf("%s is not installed", name) + return xerrors.Errorf("%s is not installed", name) } } o.log.Infof("Dependencies ... Pass") diff --git a/scanner/redhatbase_test.go b/scanner/redhatbase_test.go index be0695a386..2c94845f89 100644 --- a/scanner/redhatbase_test.go +++ b/scanner/redhatbase_test.go @@ -740,7 +740,7 @@ func Test_redhatBase_rebootRequired(t *testing.T) { }, }, args: args{ - fn: func(s string) execResult { + fn: func(_ string) execResult { return execResult{ Stdout: `kernel-uek-5.4.17-2102.200.13.el7uek.x86_64 Mon 05 Apr 2021 04:52:06 PM UTC kernel-uek-4.14.35-2047.501.2.el7uek.x86_64 Mon 05 Apr 2021 04:49:39 PM UTC @@ -763,7 +763,7 @@ func Test_redhatBase_rebootRequired(t *testing.T) { }, }, args: args{ - fn: func(s string) execResult { + fn: func(_ string) execResult { return execResult{ Stdout: `kernel-uek-5.4.17-2102.200.13.el7uek.x86_64 Mon 05 Apr 2021 04:52:06 PM UTC kernel-uek-4.14.35-2047.501.2.el7uek.x86_64 Mon 05 Apr 2021 04:49:39 PM UTC @@ -786,7 +786,7 @@ func Test_redhatBase_rebootRequired(t *testing.T) { }, }, args: args{ - fn: func(s string) execResult { + fn: func(_ string) execResult { return execResult{ Stdout: `kernel-3.10.0-1160.24.1.el7.x86_64 Mon 26 Apr 2021 10:13:54 AM UTC kernel-3.10.0-1062.12.1.el7.x86_64 Sat 29 Feb 2020 12:09:00 PM UTC`, @@ -808,7 +808,7 @@ kernel-3.10.0-1062.12.1.el7.x86_64 Sat 29 Feb 2020 12:09:00 PM UTC`, }, }, args: args{ - fn: func(s string) execResult { + fn: func(_ string) execResult { return execResult{ Stdout: `kernel-3.10.0-1160.24.1.el7.x86_64 Mon 26 Apr 2021 10:13:54 AM UTC kernel-3.10.0-1062.12.1.el7.x86_64 Sat 29 Feb 2020 12:09:00 PM UTC`, diff --git a/scanner/rhel.go b/scanner/rhel.go index a56fc17488..dcadf88f37 100644 --- a/scanner/rhel.go +++ b/scanner/rhel.go @@ -37,9 +37,11 @@ func (o *rhel) checkScanMode() error { func (o *rhel) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else if o.getServerInfo().Mode.IsDeep() { + } + if o.getServerInfo().Mode.IsDeep() { return o.execCheckDeps(o.depsDeep()) } return xerrors.New("Unknown scan mode") @@ -66,11 +68,11 @@ func (o *rhel) depsDeep() []string { func (o *rhel) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *rhel) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/rocky.go b/scanner/rocky.go index 8ab4058f31..b1123f113b 100644 --- a/scanner/rocky.go +++ b/scanner/rocky.go @@ -36,11 +36,11 @@ func (o *rocky) checkScanMode() error { func (o *rocky) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else { - return o.execCheckDeps(o.depsDeep()) } + return o.execCheckDeps(o.depsDeep()) } func (o *rocky) depsFast() []string { @@ -70,11 +70,11 @@ func (o *rocky) depsDeep() []string { func (o *rocky) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *rocky) sudoNoPasswdCmdsFast() []cmd { diff --git a/scanner/scanner.go b/scanner/scanner.go index eb233a5624..9d1385c8c7 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -836,7 +836,6 @@ func (s Scanner) checkDependencies() { parallelExec(func(o osTypeInterface) error { return o.checkDeps() }, s.TimeoutSec) - return } // checkIfSudoNoPasswd checks whether vuls can sudo with nopassword via SSH @@ -844,7 +843,6 @@ func (s Scanner) checkIfSudoNoPasswd() { parallelExec(func(o osTypeInterface) error { return o.checkIfSudoNoPasswd() }, s.TimeoutSec) - return } // detectPlatform detects the platform of each servers. diff --git a/scanner/suse.go b/scanner/suse.go index 18d558b0e2..e829271df8 100644 --- a/scanner/suse.go +++ b/scanner/suse.go @@ -112,9 +112,11 @@ func (o *suse) checkScanMode() error { func (o *suse) checkDeps() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckDeps(o.depsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckDeps(o.depsFastRoot()) - } else if o.getServerInfo().Mode.IsDeep() { + } + if o.getServerInfo().Mode.IsDeep() { return o.execCheckDeps(o.depsDeep()) } return xerrors.New("Unknown scan mode") @@ -135,11 +137,11 @@ func (o *suse) depsDeep() []string { func (o *suse) checkIfSudoNoPasswd() error { if o.getServerInfo().Mode.IsFast() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) - } else if o.getServerInfo().Mode.IsFastRoot() { + } + if o.getServerInfo().Mode.IsFastRoot() { return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) - } else { - return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) } func (o *suse) sudoNoPasswdCmdsFast() []cmd { diff --git a/subcmds/discover.go b/subcmds/discover.go index 75ab56de63..a4e29db16d 100644 --- a/subcmds/discover.go +++ b/subcmds/discover.go @@ -43,7 +43,7 @@ func (p *DiscoverCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface logging.Log.Infof("vuls-%s-%s", config.Version, config.Revision) // validate if len(f.Args()) == 0 { - logging.Log.Errorf("Usage: " + p.Usage()) + logging.Log.Errorf("Usage: %s", p.Usage()) return subcommands.ExitUsageError } diff --git a/subcmds/server.go b/subcmds/server.go index e2c46b2a1c..48e4c0fd8f 100644 --- a/subcmds/server.go +++ b/subcmds/server.go @@ -121,7 +121,7 @@ func (p *ServerCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{} http.Handle("/vuls", server.VulsHandler{ ToLocalFile: p.toLocalFile, }) - http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprintf(w, "ok") }) logging.Log.Infof("Listening on %s", p.listen)