Limit image spec's hash length

To be able to properly limit the length of hash string we should limit
after encoding to base, not before.
This commit is contained in:
Maciej Szulik 2021-04-15 15:36:47 +02:00
parent 74497632f4
commit 8acab3cc49
No known key found for this signature in database
GPG Key ID: F15E55D276FA84C4
2 changed files with 2 additions and 2 deletions

View File

@ -306,7 +306,7 @@ func getRepositoryMappedConfig(index int, config Config, repo string) Config {
h := sha256.New()
h.Write([]byte(pullSpec))
hash := base64.RawURLEncoding.EncodeToString(h.Sum(nil)[:16])
hash := base64.RawURLEncoding.EncodeToString(h.Sum(nil))[:16]
shortName := reCharSafe.ReplaceAllLiteralString(pullSpec, "-")
shortName = reDashes.ReplaceAllLiteralString(shortName, "-")

View File

@ -149,7 +149,7 @@ func TestGetMappedImageConfigs(t *testing.T) {
actual[source.GetE2EImage()] = mapping.GetE2EImage()
}
expected := map[string]string{
"docker.io/source/repo:1.0": "quay.io/repo/for-test:e2e-0-docker-io-source-repo-1-0-72R4aXm7YnxQ4_ekf1DrFA",
"docker.io/source/repo:1.0": "quay.io/repo/for-test:e2e-0-docker-io-source-repo-1-0-72R4aXm7YnxQ4_ek",
}
if !reflect.DeepEqual(expected, actual) {
t.Fatal(diff.ObjectReflectDiff(expected, actual))