From cff8006c3d2451d01c5034b0e74c23f4e633b8bb Mon Sep 17 00:00:00 2001 From: DenisGNoonan Date: Thu, 25 Jan 2024 18:53:57 +0000 Subject: [PATCH] NONRTRIC-946: Validate ApiProvDomId for PUT Issue-ID: NONRTRIC-946 Change-Id: Ic91437458be3fa7290f8782d7964949ec5e5ea5f Signed-off-by: DenisGNoonan --- .../providermanagement/providermanagement.go | 6 +++ .../providermanagement/providermanagement_test.go | 43 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) 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() -- 2.16.6