Refactor check earlier registration 96/10396/1
authorelinuxhenrik <henrik.b.andersson@est.tech>
Mon, 6 Feb 2023 08:59:28 +0000 (09:59 +0100)
committerHenrik Andersson <henrik.b.andersson@est.tech>
Mon, 6 Feb 2023 12:58:15 +0000 (12:58 +0000)
Issue-ID: NONRTRIC-814
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: Ia1a921c13234f848138607edd4c294a322663d80

capifcore/internal/invokermanagement/invokermanagement.go
capifcore/internal/invokermanagementapi/typevalidation.go
capifcore/internal/invokermanagementapi/typevalidation_test.go
capifcore/internal/providermanagement/providermanagement.go
capifcore/internal/providermanagementapi/typevalidation.go
capifcore/internal/providermanagementapi/typevalidation_test.go
capifcore/internal/publishservice/publishservice.go
capifcore/internal/publishserviceapi/typevalidation.go
capifcore/internal/publishserviceapi/typevalidation_test.go

index 5d4ba25..c6f2db3 100644 (file)
@@ -133,7 +133,7 @@ func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error {
 
 func (im *InvokerManager) isInvokerOnboarded(newInvoker invokerapi.APIInvokerEnrolmentDetails) bool {
        for _, invoker := range im.onboardedInvokers {
-               if newInvoker.OnboardingInformation.ApiInvokerPublicKey == invoker.OnboardingInformation.ApiInvokerPublicKey {
+               if invoker.IsOnboarded(newInvoker) {
                        return true
                }
        }
index be29481..8bfb784 100644 (file)
@@ -41,3 +41,7 @@ func (ied *APIInvokerEnrolmentDetails) Validate() error {
 
        return nil
 }
+
+func (ied *APIInvokerEnrolmentDetails) IsOnboarded(otherInvoker APIInvokerEnrolmentDetails) bool {
+       return ied.OnboardingInformation.ApiInvokerPublicKey == otherInvoker.OnboardingInformation.ApiInvokerPublicKey
+}
index 58cd655..499b0a1 100644 (file)
@@ -53,3 +53,22 @@ func TestValidateInvoker(t *testing.T) {
        err = invokerUnderTest.Validate()
        assert.Nil(t, err)
 }
+
+func TestIsOnboarded(t *testing.T) {
+       publicKey := "publicKey"
+       invokerUnderTest := APIInvokerEnrolmentDetails{
+               OnboardingInformation: OnboardingInformation{
+                       ApiInvokerPublicKey: publicKey,
+               },
+       }
+
+       otherInvoker := APIInvokerEnrolmentDetails{
+               OnboardingInformation: OnboardingInformation{
+                       ApiInvokerPublicKey: "otherPublicKey",
+               },
+       }
+       assert.False(t, invokerUnderTest.IsOnboarded(otherInvoker))
+
+       otherInvoker.OnboardingInformation.ApiInvokerPublicKey = publicKey
+       assert.True(t, invokerUnderTest.IsOnboarded(otherInvoker))
+}
index 6ca4a7c..5e9211e 100644 (file)
@@ -97,7 +97,7 @@ func (pm *ProviderManager) PostRegistrations(ctx echo.Context) error {
 
 func (pm *ProviderManager) isProviderRegistered(newProvider provapi.APIProviderEnrolmentDetails) bool {
        for _, prov := range pm.registeredProviders {
-               if newProvider.RegSec == prov.RegSec {
+               if prov.IsRegistered(newProvider) {
                        return true
                }
        }
index c873f30..3c514a8 100644 (file)
@@ -67,3 +67,7 @@ func (pd APIProviderEnrolmentDetails) validateFunctions() error {
        }
        return nil
 }
+
+func (pd APIProviderEnrolmentDetails) IsRegistered(otherProvider APIProviderEnrolmentDetails) bool {
+       return pd.RegSec == otherProvider.RegSec
+}
index 7698aab..b79a13b 100644 (file)
@@ -106,6 +106,21 @@ func TestValidateAPIProviderEnrolmentDetails(t *testing.T) {
        assert.Nil(t, providerDetailsUnderTest.Validate())
 }
 
+func TestIsRegistered(t *testing.T) {
+       regSec := "regSec"
+       providerUnderTest := APIProviderEnrolmentDetails{
+               RegSec: regSec,
+       }
+
+       otherProvider := APIProviderEnrolmentDetails{
+               RegSec: "otherRegSec",
+       }
+       assert.False(t, providerUnderTest.IsRegistered(otherProvider))
+
+       otherProvider.RegSec = regSec
+       assert.True(t, providerUnderTest.IsRegistered(otherProvider))
+}
+
 func getProvider() APIProviderEnrolmentDetails {
        testFuncs := []APIProviderFunctionDetails{
                {
index 5cea538..ee3efef 100644 (file)
@@ -211,7 +211,7 @@ func (ps *PublishService) PostApfIdServiceApis(ctx echo.Context, apfId string) e
 func (ps *PublishService) isServicePublished(newService publishapi.ServiceAPIDescription) bool {
        for _, services := range ps.publishedServices {
                for _, service := range services {
-                       if newService.ApiName == service.ApiName {
+                       if service.IsPublished(newService) {
                                return true
                        }
                }
index ee331ad..ad19324 100644 (file)
@@ -31,3 +31,7 @@ func (sd ServiceAPIDescription) Validate() error {
        }
        return nil
 }
+
+func (sd ServiceAPIDescription) IsPublished(otherService ServiceAPIDescription) bool {
+       return sd.ApiName == otherService.ApiName
+}
index ef4e35b..39e3619 100644 (file)
@@ -38,3 +38,18 @@ func TestValidate(t *testing.T) {
        assert.Nil(t, err)
 
 }
+
+func TestIsServicePublished(t *testing.T) {
+       apiName := "apiName"
+       serviceUnderTest := ServiceAPIDescription{
+               ApiName: apiName,
+       }
+
+       otherService := ServiceAPIDescription{
+               ApiName: "otherApiName",
+       }
+       assert.False(t, serviceUnderTest.IsPublished(otherService))
+
+       otherService.ApiName = apiName
+       assert.True(t, serviceUnderTest.IsPublished(otherService))
+}