From 2553d114627ae4d4609c7150ee5a791e3c8b4ab8 Mon Sep 17 00:00:00 2001 From: Adam Korczynski Date: Tue, 18 Jun 2024 13:20:17 +0100 Subject: [PATCH 1/5] export API to set RefTime of Updater Signed-off-by: Adam Korczynski --- metadata/updater/updater.go | 4 ++++ metadata/updater/updater_top_level_update_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/metadata/updater/updater.go b/metadata/updater/updater.go index 7d723dfa..53ee7d8a 100644 --- a/metadata/updater/updater.go +++ b/metadata/updater/updater.go @@ -662,6 +662,10 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata { return *update.trusted } +func (update *Updater) SetRefTime(t time.Time) { + update.trusted.RefTime = t +} + func IsWindowsPath(path string) bool { match, _ := regexp.MatchString(`^[a-zA-Z]:\\`, path) return match diff --git a/metadata/updater/updater_top_level_update_test.go b/metadata/updater/updater_top_level_update_test.go index 42715fb0..c3b12a18 100644 --- a/metadata/updater/updater_top_level_update_test.go +++ b/metadata/updater/updater_top_level_update_test.go @@ -98,7 +98,7 @@ func runRefresh(updaterConfig *config.UpdaterConfig, moveInTime time.Time) (Upda } if moveInTime != time.Now() { - updater.trusted.RefTime = moveInTime + updater.SetRefTime(moveInTime) } return *updater, updater.Refresh() From a2d58b631e60176c90844be7ee094da3dbcdd622 Mon Sep 17 00:00:00 2001 From: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:33:29 +0100 Subject: [PATCH 2/5] Update metadata/updater/updater.go Co-authored-by: Fredrik Skogman Signed-off-by: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> --- metadata/updater/updater.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/updater/updater.go b/metadata/updater/updater.go index 53ee7d8a..19fbf86d 100644 --- a/metadata/updater/updater.go +++ b/metadata/updater/updater.go @@ -662,7 +662,7 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata { return *update.trusted } -func (update *Updater) SetRefTime(t time.Time) { +func (update *Updater) UnsafeSetRefTime(t time.Time) { update.trusted.RefTime = t } From de4dcfc8d0558df8091479cedbc34c81d0ff4a30 Mon Sep 17 00:00:00 2001 From: Adam Korczynski Date: Tue, 18 Jun 2024 13:43:50 +0100 Subject: [PATCH 3/5] update name in test Signed-off-by: Adam Korczynski --- metadata/updater/updater_top_level_update_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/updater/updater_top_level_update_test.go b/metadata/updater/updater_top_level_update_test.go index c3b12a18..214105b4 100644 --- a/metadata/updater/updater_top_level_update_test.go +++ b/metadata/updater/updater_top_level_update_test.go @@ -98,7 +98,7 @@ func runRefresh(updaterConfig *config.UpdaterConfig, moveInTime time.Time) (Upda } if moveInTime != time.Now() { - updater.SetRefTime(moveInTime) + updater.UnsafeSetRefTime(moveInTime) } return *updater, updater.Refresh() From faf9792df89ebd60c16f13d49d22d6ea13868b1d Mon Sep 17 00:00:00 2001 From: Adam Korczynski Date: Tue, 18 Jun 2024 14:15:01 +0100 Subject: [PATCH 4/5] add comment to UnsafeSetRefTime Signed-off-by: Adam Korczynski --- metadata/updater/updater.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metadata/updater/updater.go b/metadata/updater/updater.go index 19fbf86d..68333c82 100644 --- a/metadata/updater/updater.go +++ b/metadata/updater/updater.go @@ -662,6 +662,9 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata { return *update.trusted } +// Sets the reference time that the updater uses. +// This should only be done in tests. +// UnsafeSetRefTime is useful when testing time-related behavior in go-tuf. func (update *Updater) UnsafeSetRefTime(t time.Time) { update.trusted.RefTime = t } From ee97dd4b0d0c8c4bb888d2c46b80162aed06ed70 Mon Sep 17 00:00:00 2001 From: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:25:01 +0100 Subject: [PATCH 5/5] Update metadata/updater/updater.go Co-authored-by: Fredrik Skogman Signed-off-by: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> --- metadata/updater/updater.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metadata/updater/updater.go b/metadata/updater/updater.go index 68333c82..8433cefb 100644 --- a/metadata/updater/updater.go +++ b/metadata/updater/updater.go @@ -662,9 +662,9 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata { return *update.trusted } -// Sets the reference time that the updater uses. +// UnsafeSetRefTime sets the reference time that the updater uses. // This should only be done in tests. -// UnsafeSetRefTime is useful when testing time-related behavior in go-tuf. +// Using this function is useful when testing time-related behavior in go-tuf. func (update *Updater) UnsafeSetRefTime(t time.Time) { update.trusted.RefTime = t }