diff --git a/pkg/service/oidc4ci/oidc4ci_service.go b/pkg/service/oidc4ci/oidc4ci_service.go index ee40812e6..6834271b8 100644 --- a/pkg/service/oidc4ci/oidc4ci_service.go +++ b/pkg/service/oidc4ci/oidc4ci_service.go @@ -783,13 +783,6 @@ func (s *Service) PrepareCredential( //nolint:funlen return nil, err } - id := requestedTxCredentialConfigurationIDs - b, _ := json.Marshal(id) - logger.Info(fmt.Sprintf("requestedTxCredentialConfigurationIDs : %v", string(b))) - - b1, _ := json.Marshal(tx) - logger.Info(fmt.Sprintf("tx : %v", string(b1))) - requestedTxCredentialConfigurationIDs[txCredentialConfiguration.ID] = struct{}{} cred, ackID, prepareCredError := s.prepareCredential(ctx, tx, txCredentialConfiguration, requestedCredential) diff --git a/pkg/service/wellknown/provider/api.go b/pkg/service/wellknown/provider/api.go index 7b15bfe86..fc3a5c4d6 100644 --- a/pkg/service/wellknown/provider/api.go +++ b/pkg/service/wellknown/provider/api.go @@ -1,3 +1,9 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + package provider type DynamicWellKnownStore dynamicWellKnownStore diff --git a/pkg/service/wellknown/provider/interfaces.go b/pkg/service/wellknown/provider/interfaces.go index 4c06d3771..3922007ef 100644 --- a/pkg/service/wellknown/provider/interfaces.go +++ b/pkg/service/wellknown/provider/interfaces.go @@ -1,3 +1,9 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + package provider import ( diff --git a/pkg/storage/redis/dynamicwellknown/dynamicwellknown.go b/pkg/storage/redis/dynamicwellknown/dynamicwellknown.go index e623e8b06..40fc7b3a5 100644 --- a/pkg/storage/redis/dynamicwellknown/dynamicwellknown.go +++ b/pkg/storage/redis/dynamicwellknown/dynamicwellknown.go @@ -1,3 +1,9 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + package dynamicwellknown import ( @@ -66,6 +72,10 @@ func (s *Store) Get(ctx context.Context, id string) (map[string]*profileapi.Cred return nil, err } + if len(b) == 0 { + return map[string]*profileapi.CredentialsConfigurationSupported{}, nil + } + var result map[string]*profileapi.CredentialsConfigurationSupported if err = json.Unmarshal(b, &result); err != nil { return nil, err @@ -75,5 +85,5 @@ func (s *Store) Get(ctx context.Context, id string) (map[string]*profileapi.Cred } func (s *Store) resolveRedisKey(id string) string { - return fmt.Sprintf("%s-%s", keyPrefix, id) + return fmt.Sprintf("%s:%s", keyPrefix, id) } diff --git a/pkg/storage/redis/dynamicwellknown/dynamicwellknown_test.go b/pkg/storage/redis/dynamicwellknown/dynamicwellknown_test.go new file mode 100644 index 000000000..7fbb017b3 --- /dev/null +++ b/pkg/storage/redis/dynamicwellknown/dynamicwellknown_test.go @@ -0,0 +1,85 @@ +package dynamicwellknown_test + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/golang/mock/gomock" + redisapi "github.com/redis/go-redis/v9" + "github.com/stretchr/testify/assert" + + profileapi "github.com/trustbloc/vcs/pkg/profile" + "github.com/trustbloc/vcs/pkg/storage/redis/dynamicwellknown" +) + +func TestUpsert(t *testing.T) { + t.Run("no existing", func(t *testing.T) { + cl := NewMockredisClient(gomock.NewController(t)) + api := NewMockredisApi(gomock.NewController(t)) + + cl.EXPECT().API().Return(api).AnyTimes() + + store := dynamicwellknown.New(cl, time.Hour) + + api.EXPECT().Get(context.TODO(), "dynamic_well_known:1234").Return( + redisapi.NewStringResult("", nil)) + + api.EXPECT().Set(gomock.Any(), "dynamic_well_known:1234", gomock.Any(), time.Hour). + Return(redisapi.NewStatusResult("", nil)) + + assert.NoError(t, store.Upsert(context.TODO(), "1234", + map[string]*profileapi.CredentialsConfigurationSupported{ + "key1": {}, + }), + ) + }) + + t.Run("err get", func(t *testing.T) { + cl := NewMockredisClient(gomock.NewController(t)) + api := NewMockredisApi(gomock.NewController(t)) + + cl.EXPECT().API().Return(api).AnyTimes() + + store := dynamicwellknown.New(cl, time.Hour) + + api.EXPECT().Get(context.TODO(), "dynamic_well_known:1234").Return( + redisapi.NewStringResult("", errors.New("unexpected err"))) + + assert.ErrorContains(t, store.Upsert(context.TODO(), "1234", + map[string]*profileapi.CredentialsConfigurationSupported{ + "key1": {}, + }), "unexpected err") + }) + + t.Run("not found err", func(t *testing.T) { + cl := NewMockredisClient(gomock.NewController(t)) + api := NewMockredisApi(gomock.NewController(t)) + + cl.EXPECT().API().Return(api).AnyTimes() + + store := dynamicwellknown.New(cl, time.Hour) + api.EXPECT().Get(context.TODO(), "dynamic_well_known:1234").Return( + redisapi.NewStringResult("", redisapi.Nil)) + + resp, err := store.Get(context.TODO(), "1234") + assert.NoError(t, err) + assert.NotNil(t, resp) + }) + + t.Run("err", func(t *testing.T) { + cl := NewMockredisClient(gomock.NewController(t)) + api := NewMockredisApi(gomock.NewController(t)) + + cl.EXPECT().API().Return(api).AnyTimes() + + store := dynamicwellknown.New(cl, time.Hour) + api.EXPECT().Get(context.TODO(), "dynamic_well_known:1234").Return( + redisapi.NewStringResult("", errors.New("unexpected err"))) + + resp, err := store.Get(context.TODO(), "1234") + assert.ErrorContains(t, err, "unexpected err") + assert.Nil(t, resp) + }) +} diff --git a/pkg/storage/redis/dynamicwellknown/interfaces.go b/pkg/storage/redis/dynamicwellknown/interfaces.go index 1def233ca..72065e77e 100644 --- a/pkg/storage/redis/dynamicwellknown/interfaces.go +++ b/pkg/storage/redis/dynamicwellknown/interfaces.go @@ -1,3 +1,9 @@ +/* +Copyright Gen Digital Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + package dynamicwellknown import redisapi "github.com/redis/go-redis/v9"