From: John Keeney Date: Fri, 26 Jan 2024 15:34:18 +0000 (+0000) Subject: Merge "NONRTRIC-946: Validate ApiProvDomId for PUT" X-Git-Tag: 1.3.1~18 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=c4121cc21b3b088df1ee22a9bf7645e5dddb1f6a;hp=a98d361fe90ebac93c13a599529c4b743e11ace2;p=nonrtric%2Fplt%2Fsme.git Merge "NONRTRIC-946: Validate ApiProvDomId for PUT" --- diff --git a/capifcore/internal/providermanagement/providermanagement.go b/capifcore/internal/providermanagement/providermanagement.go index 2d6bd61..51abd74 100644 --- a/capifcore/internal/providermanagement/providermanagement.go +++ b/capifcore/internal/providermanagement/providermanagement.go @@ -153,6 +153,12 @@ func (pm *ProviderManager) PutRegistrationsRegistrationId(ctx echo.Context, regi return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, err)) } + // Additional validation for PUT + if updatedProvider.ApiProvDomId == nil { + errDetail := "APIProviderEnrolmentDetails missing required ApiProvDomId" + return sendCoreError(ctx, http.StatusNotFound, fmt.Sprintf(errMsg, errDetail)) + } + if err = pm.updateProvider(updatedProvider, registeredProvider); err != nil { return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, err)) } diff --git a/capifcore/internal/providermanagement/providermanagement_test.go b/capifcore/internal/providermanagement/providermanagement_test.go index 010e7c5..7d52729 100644 --- a/capifcore/internal/providermanagement/providermanagement_test.go +++ b/capifcore/internal/providermanagement/providermanagement_test.go @@ -49,6 +49,49 @@ var ( funcIdAEF = "AEF_id_rApp_as_AEF" ) +func TestFailedUpdateValidProviderWithNewFunction(t *testing.T) { + managerUnderTest, requestHandler := getEcho() + + provider := getProvider() + provider.ApiProvDomId = &domainID + (*provider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF + (*provider.ApiProvFuncs)[1].ApiProvFuncId = &funcIdAMF + (*provider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF + managerUnderTest.registeredProviders[domainID] = provider + + // Modify the provider + updatedProvider := getProvider() + + // We omit to set updatedProvider.ApiProvDomId + (*updatedProvider.ApiProvFuncs)[0].ApiProvFuncId = &funcIdAPF + (*updatedProvider.ApiProvFuncs)[1].ApiProvFuncId = &funcIdAMF + (*updatedProvider.ApiProvFuncs)[2].ApiProvFuncId = &funcIdAEF + newDomainInfo := "New domain info" + updatedProvider.ApiProvDomInfo = &newDomainInfo + newFunctionInfo := "New function info" + (*updatedProvider.ApiProvFuncs)[0].ApiProvFuncInfo = &newFunctionInfo + newFuncInfoAEF := "new func as AEF" + testFuncs := *updatedProvider.ApiProvFuncs + testFuncs = append(testFuncs, provapi.APIProviderFunctionDetails{ + ApiProvFuncInfo: &newFuncInfoAEF, + ApiProvFuncRole: provapi.ApiProviderFuncRoleAEF, + RegInfo: provapi.RegistrationInformation{ + ApiProvPubKey: "key", + }, + }) + updatedProvider.ApiProvFuncs = &testFuncs + + result := testutil.NewRequest().Put("/registrations/"+domainID).WithJsonBody(updatedProvider).Go(t, requestHandler) + assert.Equal(t, http.StatusNotFound, result.Code()) + + var resultError common29122.ProblemDetails + err := result.UnmarshalJsonToObject(&resultError) + assert.NoError(t, err, "error unmarshaling response") + + assert.Contains(t, *resultError.Cause, "APIProviderEnrolmentDetails missing required ApiProvDomId") + assert.False(t, managerUnderTest.IsFunctionRegistered("AEF_id_new_func_as_AEF")) +} + func TestRegisterValidProvider(t *testing.T) { managerUnderTest, requestHandler := getEcho()