From 2ba4580c67fbe7994141e4cd2701f7bd22b69ebf Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Mon, 14 Nov 2022 17:13:21 +0100 Subject: [PATCH] Rename APIRegister to PublishRegister Issue-ID: NONRTRIC-814 Signed-off-by: elinuxhenrik Change-Id: I93acc1b752cad65ca1418daae82aebfccd506330 --- .../invokermanagement/invokermanagement.go | 12 ++--- .../invokermanagement/invokermanagement_test.go | 18 +++---- .../internal/publishservice/mocks/APIRegister.go | 57 ---------------------- .../publishservice/mocks/PublishRegister.go | 57 ++++++++++++++++++++++ .../internal/publishservice/publishservice.go | 12 ++--- .../internal/publishservice/publishservice_test.go | 4 +- capifcore/internal/securityservice/security.go | 8 +-- .../internal/securityservice/security_test.go | 18 +++---- 8 files changed, 93 insertions(+), 93 deletions(-) delete mode 100644 capifcore/internal/publishservice/mocks/APIRegister.go create mode 100644 capifcore/internal/publishservice/mocks/PublishRegister.go diff --git a/capifcore/internal/invokermanagement/invokermanagement.go b/capifcore/internal/invokermanagement/invokermanagement.go index 20bba33..7f5782e 100644 --- a/capifcore/internal/invokermanagement/invokermanagement.go +++ b/capifcore/internal/invokermanagement/invokermanagement.go @@ -46,15 +46,15 @@ type InvokerRegister interface { type InvokerManager struct { onboardedInvokers map[string]invokerapi.APIInvokerEnrolmentDetails - apiRegister publishservice.APIRegister + publishRegister publishservice.PublishRegister nextId int64 lock sync.Mutex } -func NewInvokerManager(apiRegister publishservice.APIRegister) *InvokerManager { +func NewInvokerManager(publishRegister publishservice.PublishRegister) *InvokerManager { return &InvokerManager{ onboardedInvokers: make(map[string]invokerapi.APIInvokerEnrolmentDetails), - apiRegister: apiRegister, + publishRegister: publishRegister, nextId: 1000, } } @@ -179,18 +179,18 @@ func (im *InvokerManager) validateInvoker(invoker invokerapi.APIInvokerEnrolment return true, sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required OnboardingInformation.ApiInvokerPublicKey") } - if !im.areAPIsRegistered(invoker.ApiList) { + if !im.areAPIsPublished(invoker.ApiList) { return true, sendCoreError(ctx, http.StatusBadRequest, "Some APIs needed by invoker are not registered") } return false, nil } -func (im *InvokerManager) areAPIsRegistered(apis *invokerapi.APIList) bool { +func (im *InvokerManager) areAPIsPublished(apis *invokerapi.APIList) bool { if apis == nil { return true } - return im.apiRegister.AreAPIsRegistered((*[]publishapi.ServiceAPIDescription)(apis)) + return im.publishRegister.AreAPIsPublished((*[]publishapi.ServiceAPIDescription)(apis)) } func (im *InvokerManager) getId(invokerInfo *string) *string { diff --git a/capifcore/internal/invokermanagement/invokermanagement_test.go b/capifcore/internal/invokermanagement/invokermanagement_test.go index 4aae429..507a69b 100644 --- a/capifcore/internal/invokermanagement/invokermanagement_test.go +++ b/capifcore/internal/invokermanagement/invokermanagement_test.go @@ -44,9 +44,9 @@ import ( ) func TestOnboardInvoker(t *testing.T) { - apiRegisterMock := publishmocks.APIRegister{} - apiRegisterMock.On("AreAPIsRegistered", mock.Anything).Return(true) - invokerUnderTest, requestHandler := getEcho(&apiRegisterMock) + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("AreAPIsPublished", mock.Anything).Return(true) + invokerUnderTest, requestHandler := getEcho(&publishRegisterMock) aefProfiles := []publishserviceapi.AefProfile{ getAefProfile("aefId"), @@ -74,7 +74,7 @@ func TestOnboardInvoker(t *testing.T) { assert.Equal(t, "http://example.com/onboardedInvokers/"+*resultInvoker.ApiInvokerId, result.Recorder.Header().Get(echo.HeaderLocation)) assert.True(t, invokerUnderTest.IsInvokerRegistered("api_invoker_id_invoker_a")) assert.True(t, invokerUnderTest.VerifyInvokerSecret("api_invoker_id_invoker_a", "onboarding_secret_invoker_a")) - apiRegisterMock.AssertCalled(t, "AreAPIsRegistered", mock.Anything) + publishRegisterMock.AssertCalled(t, "AreAPIsPublished", mock.Anything) // Onboard an invoker missing required NotificationDestination, should get 400 with problem details invalidInvoker := invokermanagementapi.APIInvokerEnrolmentDetails{ @@ -218,9 +218,9 @@ func TestUpdateInvoker(t *testing.T) { } func TestGetInvokerApiList(t *testing.T) { - apiRegisterMock := publishmocks.APIRegister{} - apiRegisterMock.On("AreAPIsRegistered", mock.Anything).Return(true) - invokerUnderTest, requestHandler := getEcho(&apiRegisterMock) + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("AreAPIsPublished", mock.Anything).Return(true) + invokerUnderTest, requestHandler := getEcho(&publishRegisterMock) // Onboard two invokers aefProfiles := []publishserviceapi.AefProfile{ @@ -253,7 +253,7 @@ func TestGetInvokerApiList(t *testing.T) { assert.Equal(t, apiId, *(*wantedApiList)[0].ApiId) } -func getEcho(apiRegister publishservice.APIRegister) (*InvokerManager, *echo.Echo) { +func getEcho(publishRegister publishservice.PublishRegister) (*InvokerManager, *echo.Echo) { swagger, err := invokermanagementapi.GetSwagger() if err != nil { fmt.Fprintf(os.Stderr, "Error loading swagger spec\n: %s", err) @@ -262,7 +262,7 @@ func getEcho(apiRegister publishservice.APIRegister) (*InvokerManager, *echo.Ech swagger.Servers = nil - im := NewInvokerManager(apiRegister) + im := NewInvokerManager(publishRegister) e := echo.New() e.Use(echomiddleware.Logger()) diff --git a/capifcore/internal/publishservice/mocks/APIRegister.go b/capifcore/internal/publishservice/mocks/APIRegister.go deleted file mode 100644 index 0ee0a14..0000000 --- a/capifcore/internal/publishservice/mocks/APIRegister.go +++ /dev/null @@ -1,57 +0,0 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. - -package mocks - -import ( - mock "github.com/stretchr/testify/mock" - - publishserviceapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi" -) - -// APIRegister is an autogenerated mock type for the APIRegister type -type APIRegister struct { - mock.Mock -} - -// AreAPIsRegistered provides a mock function with given fields: serviceDescriptions -func (_m *APIRegister) AreAPIsRegistered(serviceDescriptions *[]publishserviceapi.ServiceAPIDescription) bool { - ret := _m.Called(serviceDescriptions) - - var r0 bool - if rf, ok := ret.Get(0).(func(*[]publishserviceapi.ServiceAPIDescription) bool); ok { - r0 = rf(serviceDescriptions) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// IsAPIRegistered provides a mock function with given fields: aefId, path -func (_m *APIRegister) IsAPIRegistered(aefId string, path string) bool { - ret := _m.Called(aefId, path) - - var r0 bool - if rf, ok := ret.Get(0).(func(string, string) bool); ok { - r0 = rf(aefId, path) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -type mockConstructorTestingTNewAPIRegister interface { - mock.TestingT - Cleanup(func()) -} - -// NewAPIRegister creates a new instance of APIRegister. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAPIRegister(t mockConstructorTestingTNewAPIRegister) *APIRegister { - mock := &APIRegister{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/capifcore/internal/publishservice/mocks/PublishRegister.go b/capifcore/internal/publishservice/mocks/PublishRegister.go new file mode 100644 index 0000000..b264825 --- /dev/null +++ b/capifcore/internal/publishservice/mocks/PublishRegister.go @@ -0,0 +1,57 @@ +// Code generated by mockery v2.14.0. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + publishserviceapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi" +) + +// PublishRegister is an autogenerated mock type for the PublishRegister type +type PublishRegister struct { + mock.Mock +} + +// AreAPIsPublished provides a mock function with given fields: serviceDescriptions +func (_m *PublishRegister) AreAPIsPublished(serviceDescriptions *[]publishserviceapi.ServiceAPIDescription) bool { + ret := _m.Called(serviceDescriptions) + + var r0 bool + if rf, ok := ret.Get(0).(func(*[]publishserviceapi.ServiceAPIDescription) bool); ok { + r0 = rf(serviceDescriptions) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// IsAPIPublished provides a mock function with given fields: aefId, path +func (_m *PublishRegister) IsAPIPublished(aefId string, path string) bool { + ret := _m.Called(aefId, path) + + var r0 bool + if rf, ok := ret.Get(0).(func(string, string) bool); ok { + r0 = rf(aefId, path) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +type mockConstructorTestingTNewPublishRegister interface { + mock.TestingT + Cleanup(func()) +} + +// NewPublishRegister creates a new instance of PublishRegister. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewPublishRegister(t mockConstructorTestingTNewPublishRegister) *PublishRegister { + mock := &PublishRegister{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/capifcore/internal/publishservice/publishservice.go b/capifcore/internal/publishservice/publishservice.go index c62e73b..e073e38 100644 --- a/capifcore/internal/publishservice/publishservice.go +++ b/capifcore/internal/publishservice/publishservice.go @@ -38,10 +38,10 @@ import ( log "github.com/sirupsen/logrus" ) -//go:generate mockery --name APIRegister -type APIRegister interface { - AreAPIsRegistered(serviceDescriptions *[]publishserviceapi.ServiceAPIDescription) bool - IsAPIRegistered(aefId, path string) bool +//go:generate mockery --name PublishRegister +type PublishRegister interface { + AreAPIsPublished(serviceDescriptions *[]publishserviceapi.ServiceAPIDescription) bool + IsAPIPublished(aefId, path string) bool } type PublishService struct { @@ -59,7 +59,7 @@ func NewPublishService(serviceRegister providermanagement.ServiceRegister, hm he } } -func (ps *PublishService) AreAPIsRegistered(serviceDescriptions *[]publishserviceapi.ServiceAPIDescription) bool { +func (ps *PublishService) AreAPIsPublished(serviceDescriptions *[]publishserviceapi.ServiceAPIDescription) bool { if serviceDescriptions != nil { registeredApis := ps.getAllAefIds() @@ -115,7 +115,7 @@ func checkProfiles(newProfiles *[]publishserviceapi.AefProfile, registeredAefIds return allRegistered } -func (ps *PublishService) IsAPIRegistered(aefId, path string) bool { +func (ps *PublishService) IsAPIPublished(aefId, path string) bool { return slices.Contains(ps.getAllAefIds(), aefId) } diff --git a/capifcore/internal/publishservice/publishservice_test.go b/capifcore/internal/publishservice/publishservice_test.go index db23ce1..eccca15 100644 --- a/capifcore/internal/publishservice/publishservice_test.go +++ b/capifcore/internal/publishservice/publishservice_test.go @@ -75,8 +75,8 @@ func TestPublishUnpublishService(t *testing.T) { assert.Equal(t, "http://example.com/"+apfId+"/service-apis/"+*resultService.ApiId, result.Recorder.Header().Get(echo.HeaderLocation)) newServiceDescription.ApiId = &newApiId wantedAPILIst := []publishapi.ServiceAPIDescription{newServiceDescription} - assert.True(t, serviceUnderTest.AreAPIsRegistered(&wantedAPILIst)) - assert.True(t, serviceUnderTest.IsAPIRegistered("aefId", "app-management")) + assert.True(t, serviceUnderTest.AreAPIsPublished(&wantedAPILIst)) + assert.True(t, serviceUnderTest.IsAPIPublished("aefId", "app-management")) serviceRegisterMock.AssertCalled(t, "GetAefsForPublisher", apfId) helmManagerMock.AssertCalled(t, "InstallHelmChart", "namespace", "repoName", "chartName", "releaseName") assert.ElementsMatch(t, []string{aefId}, serviceUnderTest.getAllAefIds()) diff --git a/capifcore/internal/securityservice/security.go b/capifcore/internal/securityservice/security.go index ab0abde..3df2918 100644 --- a/capifcore/internal/securityservice/security.go +++ b/capifcore/internal/securityservice/security.go @@ -36,14 +36,14 @@ import ( type Security struct { serviceRegister providermanagement.ServiceRegister - apiRegister publishservice.APIRegister + publishRegister publishservice.PublishRegister invokerRegister invokermanagement.InvokerRegister } -func NewSecurity(serviceRegister providermanagement.ServiceRegister, apiRegister publishservice.APIRegister, invokerRegister invokermanagement.InvokerRegister) *Security { +func NewSecurity(serviceRegister providermanagement.ServiceRegister, publishRegister publishservice.PublishRegister, invokerRegister invokermanagement.InvokerRegister) *Security { return &Security{ serviceRegister: serviceRegister, - apiRegister: apiRegister, + publishRegister: publishRegister, invokerRegister: invokerRegister, } } @@ -64,7 +64,7 @@ func (s *Security) PostSecuritiesSecurityIdToken(ctx echo.Context, securityId st if !s.serviceRegister.IsFunctionRegistered(scopeData[0]) { return sendCoreError(ctx, http.StatusBadRequest, "Function not registered") } - if !s.apiRegister.IsAPIRegistered(scopeData[0], scopeData[1]) { + if !s.publishRegister.IsAPIPublished(scopeData[0], scopeData[1]) { return sendCoreError(ctx, http.StatusBadRequest, "API not published") } } diff --git a/capifcore/internal/securityservice/security_test.go b/capifcore/internal/securityservice/security_test.go index 2abc33b..33e19c1 100644 --- a/capifcore/internal/securityservice/security_test.go +++ b/capifcore/internal/securityservice/security_test.go @@ -54,10 +54,10 @@ func TestPostSecurityIdTokenInvokerRegistered(t *testing.T) { invokerRegisterMock.On("VerifyInvokerSecret", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(true) serviceRegisterMock := servicemocks.ServiceRegister{} serviceRegisterMock.On("IsFunctionRegistered", mock.AnythingOfType("string")).Return(true) - apiRegisterMock := publishmocks.APIRegister{} - apiRegisterMock.On("IsAPIRegistered", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(true) + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("IsAPIPublished", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(true) - requestHandler := getEcho(&serviceRegisterMock, &apiRegisterMock, &invokerRegisterMock) + requestHandler := getEcho(&serviceRegisterMock, &publishRegisterMock, &invokerRegisterMock) data := url.Values{} data.Set("client_id", "id") @@ -79,7 +79,7 @@ func TestPostSecurityIdTokenInvokerRegistered(t *testing.T) { invokerRegisterMock.AssertCalled(t, "IsInvokerRegistered", "id") invokerRegisterMock.AssertCalled(t, "VerifyInvokerSecret", "id", "secret") serviceRegisterMock.AssertCalled(t, "IsFunctionRegistered", "aefId") - apiRegisterMock.AssertCalled(t, "IsAPIRegistered", "aefId", "path") + publishRegisterMock.AssertCalled(t, "IsAPIPublished", "aefId", "path") } func TestPostSecurityIdTokenInvokerNotRegistered(t *testing.T) { @@ -167,10 +167,10 @@ func TestPostSecurityIdTokenAPINotPublished(t *testing.T) { invokerRegisterMock.On("VerifyInvokerSecret", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(true) serviceRegisterMock := servicemocks.ServiceRegister{} serviceRegisterMock.On("IsFunctionRegistered", mock.AnythingOfType("string")).Return(true) - apiRegisterMock := publishmocks.APIRegister{} - apiRegisterMock.On("IsAPIRegistered", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(false) + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("IsAPIPublished", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(false) - requestHandler := getEcho(&serviceRegisterMock, &apiRegisterMock, &invokerRegisterMock) + requestHandler := getEcho(&serviceRegisterMock, &publishRegisterMock, &invokerRegisterMock) data := url.Values{} data.Set("client_id", "id") @@ -191,7 +191,7 @@ func TestPostSecurityIdTokenAPINotPublished(t *testing.T) { assert.Equal(t, &errMsg, problemDetails.Cause) } -func getEcho(serviceRegister providermanagement.ServiceRegister, apiRegister publishservice.APIRegister, invokerRegister invokermanagement.InvokerRegister) *echo.Echo { +func getEcho(serviceRegister providermanagement.ServiceRegister, publishRegister publishservice.PublishRegister, invokerRegister invokermanagement.InvokerRegister) *echo.Echo { swagger, err := securityapi.GetSwagger() if err != nil { fmt.Fprintf(os.Stderr, "Error loading swagger spec\n: %s", err) @@ -200,7 +200,7 @@ func getEcho(serviceRegister providermanagement.ServiceRegister, apiRegister pub swagger.Servers = nil - s := NewSecurity(serviceRegister, apiRegister, invokerRegister) + s := NewSecurity(serviceRegister, publishRegister, invokerRegister) e := echo.New() e.Use(echomiddleware.Logger()) -- 2.16.6