From 1aca952f8083e4d5f63ad6ad33a700c90f67be2e Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Fri, 24 Nov 2023 16:21:36 +0100 Subject: [PATCH] fix(referrer): remove sha256 digest validation Signed-off-by: Miguel Martinez Trivino --- app/controlplane/internal/biz/referrer.go | 4 ---- .../internal/biz/referrer_integration_test.go | 13 ++++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/controlplane/internal/biz/referrer.go b/app/controlplane/internal/biz/referrer.go index e3e17239c..1fa79d5c4 100644 --- a/app/controlplane/internal/biz/referrer.go +++ b/app/controlplane/internal/biz/referrer.go @@ -153,10 +153,6 @@ func (s *ReferrerUseCase) GetFromRoot(ctx context.Context, digest, rootKind, use return nil, NewErrInvalidUUID(err) } - if _, err = cr_v1.NewHash(digest); err != nil { - return nil, NewErrValidation(fmt.Errorf("invalid digest format: %w", err)) - } - // We pass the list of organizationsIDs from where to look for the referrer // For now we just pass the list of organizations the user is member of // in the future we will expand this to publicly available orgs and so on. diff --git a/app/controlplane/internal/biz/referrer_integration_test.go b/app/controlplane/internal/biz/referrer_integration_test.go index f7ef3008b..2bb6ee262 100644 --- a/app/controlplane/internal/biz/referrer_integration_test.go +++ b/app/controlplane/internal/biz/referrer_integration_test.go @@ -197,6 +197,12 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() { s.Equal([]uuid.UUID{s.workflow1.ID}, got.WorkflowIDs) }) + s.T().Run("can get sha1 digests too", func(t *testing.T) { + got, err := s.Referrer.GetFromRoot(ctx, wantReferrerCommit.Digest, "", s.user.ID) + s.NoError(err) + s.Equal(wantReferrerCommit.Digest, got.Digest) + }) + s.T().Run("can't be accessed by a second user in another org", func(t *testing.T) { // the user2 has not access to org1 got, err := s.Referrer.GetFromRoot(ctx, wantReferrerAtt.Digest, "", s.user2.ID) @@ -255,13 +261,6 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() { require.Len(t, got.References, 0) }) - s.T().Run("or it's an invalid digest", func(t *testing.T) { - got, err := s.Referrer.GetFromRoot(ctx, "sha256:deadbeef", "", s.user.ID) - s.True(biz.IsErrValidation(err)) - s.ErrorContains(err, "invalid digest format") - s.Nil(got) - }) - s.T().Run("or it does not exist", func(t *testing.T) { got, err := s.Referrer.GetFromRoot(ctx, "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "", s.user.ID) s.True(biz.IsNotFound(err))