From be711f1d7f00fe7bd4b13196cae4b45ff41c1857 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 3 Aug 2022 14:11:57 -0700 Subject: [PATCH 1/2] check shas of new archs --- deploy/minikube/release_sanity_test.go | 83 +++++++++++++++++++------- pkg/minikube/notify/notify.go | 4 +- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/deploy/minikube/release_sanity_test.go b/deploy/minikube/release_sanity_test.go index 4dd248dae0..761cfd40ee 100644 --- a/deploy/minikube/release_sanity_test.go +++ b/deploy/minikube/release_sanity_test.go @@ -21,7 +21,6 @@ import ( "encoding/hex" "fmt" "io" - "runtime" "testing" retryablehttp "github.com/hashicorp/go-retryablehttp" @@ -46,45 +45,83 @@ func getSHAFromURL(url string) (string, error) { } // TestReleasesJSON checks if all *GA* releases -// enlisted in https://storage.googleapis.com/minikube/releases.json -// are available to download and have correct hashsum +// enlisted in https://storage.googleapis.com/minikube/releases-v2.json +// are available to download and have correct hashsum func TestReleasesJSON(t *testing.T) { releases, err := notify.AllVersionsFromURL(notify.GithubMinikubeReleasesURL) if err != nil { t.Fatalf("Error getting releases.json: %v", err) } - checkReleases(t, releases) + checkReleasesV2(t, releases) } // TestBetaReleasesJSON checks if all *BETA* releases -// enlisted in https://storage.googleapis.com/minikube/releases-beta.json -// are available to download and have correct hashsum +// enlisted in https://storage.googleapis.com/minikube/releases-beta-v2.json +// are available to download and have correct hashsum func TestBetaReleasesJSON(t *testing.T) { releases, err := notify.AllVersionsFromURL(notify.GithubMinikubeBetaReleasesURL) if err != nil { t.Fatalf("Error getting releases-bets.json: %v", err) } - checkReleases(t, releases) + checkReleasesV2(t, releases) } -func checkReleases(t *testing.T, rs notify.Releases) { +func checkReleasesV1(t *testing.T, r notify.Release) { + checksums := map[string]string{ + "darwin": r.Checksums.Darwin, + "linux": r.Checksums.Linux, + "windows": r.Checksums.Windows, + } + for platform, sha := range checksums { + fmt.Printf("Checking SHA for %s.\n", platform) + actualSha, err := getSHAFromURL(util.GetBinaryDownloadURL(r.Name, platform, "amd64")) + if err != nil { + t.Errorf("Error calculating SHA for %s-%s. Error: %v", r.Name, platform, err) + continue + } + if actualSha != sha { + t.Errorf("ERROR: SHA does not match for version %s, platform %s. Expected %s, got %s.", r.Name, platform, sha, actualSha) + continue + } + } +} + +func getSHAMap(c notify.Checksums) map[string]map[string]string { + return map[string]map[string]string{ + "darwin": { + "amd64": c.AMD64.Darwin, + "arm64": c.ARM64.Darwin, + }, + "linux": { + "amd64": c.AMD64.Linux, + "arm": c.ARM.Linux, + "arm64": c.ARM64.Linux, + "ppc64le": c.PPC64LE.Linux, + "s390x": c.S390X.Linux, + }, + "windows": { + "amd64": c.AMD64.Windows, + }, + } +} + +func checkReleasesV2(t *testing.T, rs notify.Releases) { for _, r := range rs.Releases { fmt.Printf("Checking release: %s\n", r.Name) - checksums := map[string]string{ - "darwin": r.Checksums.Darwin, - "linux": r.Checksums.Linux, - "windows": r.Checksums.Windows, - } - for platform, sha := range checksums { - fmt.Printf("Checking SHA for %s.\n", platform) - actualSha, err := getSHAFromURL(util.GetBinaryDownloadURL(r.Name, platform, runtime.GOARCH)) - if err != nil { - t.Errorf("Error calculating SHA for %s-%s. Error: %v", r.Name, platform, err) - continue - } - if actualSha != sha { - t.Errorf("ERROR: SHA does not match for version %s, platform %s. Expected %s, got %s.", r.Name, platform, sha, actualSha) - continue + checkReleasesV1(t, r) + release := getSHAMap(r.Checksums) + for os, archs := range release { + for arch, sha := range archs { + fmt.Printf("Checking SHA for %s-%s.\n", os, arch) + actualSha, err := getSHAFromURL(util.GetBinaryDownloadURL(r.Name, os, arch)) + if err != nil { + t.Errorf("Error calculating SHA for %s-%s-%s. Error: %v", r.Name, os, arch, err) + continue + } + if actualSha != sha { + t.Errorf("ERROR: SHA does not match for version %s, os %s, arch %s. Expected %s, got %s.", r.Name, os, arch, sha, actualSha) + continue + } } } } diff --git a/pkg/minikube/notify/notify.go b/pkg/minikube/notify/notify.go index f3a8912591..7ba97dbe1f 100644 --- a/pkg/minikube/notify/notify.go +++ b/pkg/minikube/notify/notify.go @@ -136,7 +136,7 @@ type operatingSystems struct { Windows string `json:"windows,omitempty"` } -type checksums struct { +type Checksums struct { AMD64 *operatingSystems `json:"amd64,omitempty"` ARM *operatingSystems `json:"arm,omitempty"` ARM64 *operatingSystems `json:"arm64,omitempty"` @@ -146,7 +146,7 @@ type checksums struct { } type Release struct { - Checksums checksums `json:"checksums"` + Checksums Checksums `json:"checksums"` Name string `json:"name"` } From 22af24426b1f8d8401b549ede649ea2fef92dd2d Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 3 Aug 2022 15:55:48 -0700 Subject: [PATCH 2/2] keep checksums private --- deploy/minikube/release_sanity_test.go | 5 +++-- pkg/minikube/notify/notify.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/deploy/minikube/release_sanity_test.go b/deploy/minikube/release_sanity_test.go index 761cfd40ee..0c5292a384 100644 --- a/deploy/minikube/release_sanity_test.go +++ b/deploy/minikube/release_sanity_test.go @@ -86,7 +86,8 @@ func checkReleasesV1(t *testing.T, r notify.Release) { } } -func getSHAMap(c notify.Checksums) map[string]map[string]string { +func getSHAMap(r notify.Release) map[string]map[string]string { + c := r.Checksums return map[string]map[string]string{ "darwin": { "amd64": c.AMD64.Darwin, @@ -109,7 +110,7 @@ func checkReleasesV2(t *testing.T, rs notify.Releases) { for _, r := range rs.Releases { fmt.Printf("Checking release: %s\n", r.Name) checkReleasesV1(t, r) - release := getSHAMap(r.Checksums) + release := getSHAMap(r) for os, archs := range release { for arch, sha := range archs { fmt.Printf("Checking SHA for %s-%s.\n", os, arch) diff --git a/pkg/minikube/notify/notify.go b/pkg/minikube/notify/notify.go index 7ba97dbe1f..f3a8912591 100644 --- a/pkg/minikube/notify/notify.go +++ b/pkg/minikube/notify/notify.go @@ -136,7 +136,7 @@ type operatingSystems struct { Windows string `json:"windows,omitempty"` } -type Checksums struct { +type checksums struct { AMD64 *operatingSystems `json:"amd64,omitempty"` ARM *operatingSystems `json:"arm,omitempty"` ARM64 *operatingSystems `json:"arm64,omitempty"` @@ -146,7 +146,7 @@ type Checksums struct { } type Release struct { - Checksums Checksums `json:"checksums"` + Checksums checksums `json:"checksums"` Name string `json:"name"` }