Skip to content

Commit

Permalink
feat: add wellknown
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Nov 6, 2024
1 parent a06875a commit af43bfe
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 8 deletions.
7 changes: 0 additions & 7 deletions pkg/service/oidc4ci/oidc4ci_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/service/wellknown/provider/api.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
Copyright Gen Digital Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package provider

type DynamicWellKnownStore dynamicWellKnownStore
6 changes: 6 additions & 0 deletions pkg/service/wellknown/provider/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
Copyright Gen Digital Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package provider

import (
Expand Down
12 changes: 11 additions & 1 deletion pkg/storage/redis/dynamicwellknown/dynamicwellknown.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
Copyright Gen Digital Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package dynamicwellknown

import (
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
85 changes: 85 additions & 0 deletions pkg/storage/redis/dynamicwellknown/dynamicwellknown_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
6 changes: 6 additions & 0 deletions pkg/storage/redis/dynamicwellknown/interfaces.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit af43bfe

Please sign in to comment.