func TestK8sReleases(t *testing.T) {
	releases, err := kubernetes_versions.GetK8sVersionsFromURL(constants.KubernetesVersionGCSURL)
	if err != nil {
		t.Fatalf("Error getting k8s_releases.json: %s", err)
	}

	for _, r := range releases {
		fmt.Printf("Checking release: %s\n", r.Version)
		url, err := util.GetLocalkubeDownloadURL(r.Version, constants.LocalkubeLinuxFilename)
		if err != nil {
			t.Errorf("Error getting URL for %s. Error: %s", r.Version, err)
			continue
		}
		shaURL := fmt.Sprintf("%s%s", url, constants.ShaSuffix)
		expectedSha, err := util.ParseSHAFromURL(shaURL)
		if err != nil {
			t.Errorf("Error retrieving SHA for %s. Error: %s", r.Version, err)
			continue
		}
		actualSha, err := getShaFromURL(url)
		if err != nil {
			t.Errorf("Error calculating SHA for %s. Error: %s", r.Version, err)
			continue
		}
		if expectedSha != actualSha {
			t.Errorf("ERROR: SHA does not match for version %s. Expected %s, got %s.", r.Version, expectedSha, actualSha)
			continue
		}
	}
}
示例#2
0
func isIsoChecksumValid(isoData *[]byte, shaURL string) bool {
	expectedSum, err := util.ParseSHAFromURL(shaURL)
	if err != nil {
		glog.Errorf("Error retrieving SHA from URL: %s. Error: %s.", shaURL, err)
		return false
	}

	b := sha256.Sum256(*isoData)
	actualSum := hex.EncodeToString(b[:])
	if string(expectedSum) != actualSum {
		glog.Errorf("Downloaded ISO checksum does not match expected value. Actual: %s. Expected: %s", actualSum, expectedSum)
		return false
	}
	return true
}