From c608e56b37ac3575595d0da985d3d5cae25f3d78 Mon Sep 17 00:00:00 2001 From: totegamma Date: Sun, 25 Feb 2024 13:24:20 +0900 Subject: [PATCH] fix test --- cmd/api/wire_gen.go | 2 +- cmd/gateway/wire_gen.go | 2 +- x/key/repository_test.go | 5 ++++- x/key/service.go | 6 ++++++ x/key/service_test.go | 5 ++++- x/stream/mock/service.go | 8 ++++---- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/api/wire_gen.go b/cmd/api/wire_gen.go index 000ca8da..2ea38470 100644 --- a/cmd/api/wire_gen.go +++ b/cmd/api/wire_gen.go @@ -45,7 +45,7 @@ func SetupAckService(db *gorm.DB, rdb *redis.Client, mc *memcache.Client, config } func SetupKeyService(db *gorm.DB, rdb *redis.Client, mc *memcache.Client, config util.Config) key.Service { - repository := key.NewRepository(db) + repository := key.NewRepository(db, mc) service := SetupEntityService(db, rdb, mc, config) keyService := key.NewService(repository, service, config) return keyService diff --git a/cmd/gateway/wire_gen.go b/cmd/gateway/wire_gen.go index 000ca8da..2ea38470 100644 --- a/cmd/gateway/wire_gen.go +++ b/cmd/gateway/wire_gen.go @@ -45,7 +45,7 @@ func SetupAckService(db *gorm.DB, rdb *redis.Client, mc *memcache.Client, config } func SetupKeyService(db *gorm.DB, rdb *redis.Client, mc *memcache.Client, config util.Config) key.Service { - repository := key.NewRepository(db) + repository := key.NewRepository(db, mc) service := SetupEntityService(db, rdb, mc, config) keyService := key.NewService(repository, service, config) return keyService diff --git a/x/key/repository_test.go b/x/key/repository_test.go index 15dc9070..17bb89ce 100644 --- a/x/key/repository_test.go +++ b/x/key/repository_test.go @@ -16,7 +16,10 @@ func TestRepository(t *testing.T) { db, cleanup_db := testutil.CreateDB() defer cleanup_db() - repo := NewRepository(db) + mc, cleanup_mc := testutil.CreateMC() + defer cleanup_mc() + + repo := NewRepository(db, mc) newkey := core.Key{ ID: "CKb72AAc9dcF088F7088b6718BE5a494fBB3861439", diff --git a/x/key/service.go b/x/key/service.go index 7c98fa91..233f6ad8 100644 --- a/x/key/service.go +++ b/x/key/service.go @@ -323,6 +323,7 @@ func (s *service) GetKeyResolution(ctx context.Context, keyID string) ([]core.Ke defer span.End() var keys []core.Key + var currentDepth = 0 for { if IsCCID(keyID) { return keys, nil @@ -335,6 +336,11 @@ func (s *service) GetKeyResolution(ctx context.Context, keyID string) ([]core.Ke keys = append(keys, key) keyID = key.Parent + + currentDepth++ + if currentDepth >= 8 { + return nil, fmt.Errorf("KeyDepth is too deep") + } } } diff --git a/x/key/service_test.go b/x/key/service_test.go index f341e82f..77eb02a8 100644 --- a/x/key/service_test.go +++ b/x/key/service_test.go @@ -33,13 +33,16 @@ func TestService(t *testing.T) { db, cleanup_db := testutil.CreateDB() defer cleanup_db() + mc, cleanup_mc := testutil.CreateMC() + defer cleanup_mc() + ctrl := gomock.NewController(t) defer ctrl.Finish() mockEntity := mock_entity.NewMockService(ctrl) mockEntity.EXPECT().ResolveHost(gomock.Any(), gomock.Any(), gomock.Any()).Return("", nil).AnyTimes() - test_repo := NewRepository(db) + test_repo := NewRepository(db, mc) test_service := NewService(test_repo, mockEntity, util.Config{}) // Test1. 登録してないサブキーで署名されたオブジェクトを検証する diff --git a/x/stream/mock/service.go b/x/stream/mock/service.go index 73f154b4..d76d3fe1 100644 --- a/x/stream/mock/service.go +++ b/x/stream/mock/service.go @@ -38,17 +38,17 @@ func (m *MockService) EXPECT() *MockServiceMockRecorder { } // Checkpoint mocks base method. -func (m *MockService) Checkpoint(ctx context.Context, stream string, item core.StreamItem, body interface{}, principal string) error { +func (m *MockService) Checkpoint(ctx context.Context, stream string, item core.StreamItem, body interface{}, principal, requesterDomain string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Checkpoint", ctx, stream, item, body, principal) + ret := m.ctrl.Call(m, "Checkpoint", ctx, stream, item, body, principal, requesterDomain) ret0, _ := ret[0].(error) return ret0 } // Checkpoint indicates an expected call of Checkpoint. -func (mr *MockServiceMockRecorder) Checkpoint(ctx, stream, item, body, principal interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) Checkpoint(ctx, stream, item, body, principal, requesterDomain interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Checkpoint", reflect.TypeOf((*MockService)(nil).Checkpoint), ctx, stream, item, body, principal) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Checkpoint", reflect.TypeOf((*MockService)(nil).Checkpoint), ctx, stream, item, body, principal, requesterDomain) } // Count mocks base method.