From 0738734c228460e6bac22ef30e568424d7ab327c Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Wed, 18 Dec 2024 10:13:05 -0800 Subject: [PATCH] fix_: ensure that identity images are generated with a current-time clock value instead of zero by default --- images/main.go | 2 ++ images/main_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/images/main.go b/images/main.go index bcee823b5bd..d1f87969225 100644 --- a/images/main.go +++ b/images/main.go @@ -3,6 +3,7 @@ package images import ( "bytes" "image" + "time" ) func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error) { @@ -25,6 +26,7 @@ func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error) { Height: rImg.Bounds().Dy(), FileSize: bb.Len(), ResizeTarget: int(s), + Clock: uint64(time.Now().UnixMilli()), } iis = append(iis, ii) diff --git a/images/main_test.go b/images/main_test.go index 97c3110308b..8448087407b 100644 --- a/images/main_test.go +++ b/images/main_test.go @@ -44,3 +44,27 @@ func TestGenerateBannerImage_ShrinkOnly(t *testing.T) { require.Exactly(t, identityImage.Width, int(BannerDim)) require.Exactly(t, identityImage.Height, 805) } + +func TestGenerateIdentityImages(t *testing.T) { + // Create image data + testImage := image.NewRGBA(image.Rect(0, 0, int(BannerDim)+10, int(BannerDim)+20)) + + // Create a temporary file for storing the image data + tmpTestFilePath := t.TempDir() + "/test.png" + file, err := os.Create(tmpTestFilePath) + require.NoError(t, err) + defer file.Close() + + // Save the image data to the temporary file + err = png.Encode(file, testImage) + require.NoError(t, err) + + // Generate the identity images + identityImages, err := GenerateIdentityImages(tmpTestFilePath, 100, 100, 500, 500) + require.NoError(t, err) + + // Check the identity images have a valid clock value + for _, image := range identityImages { + require.NotEqual(t, image.Clock, uint64(0)) + } +}