X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Finvokermanagement%2Finvokermanagement_test.go;h=ae79c905bf0d422dbfbc0a9a0767e87299fb1ff7;hb=b70522851289af2045d3d0c950b053b5673705cd;hp=7b929729d8ba234d9314db03dbcec749a639f65f;hpb=6f91b6ac28e733561200c5faf12029cafed39d3f;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/invokermanagement/invokermanagement_test.go b/capifcore/internal/invokermanagement/invokermanagement_test.go index 7b92972..ae79c90 100644 --- a/capifcore/internal/invokermanagement/invokermanagement_test.go +++ b/capifcore/internal/invokermanagement/invokermanagement_test.go @@ -3,7 +3,8 @@ // ========================LICENSE_START================================= // O-RAN-SC // %% -// Copyright (C) 2022: Nordix Foundation +// Copyright (C) 2022-2023: Nordix Foundation +// Copyright (C) 2024: OpenInfra Foundation Europe // %% // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -64,7 +65,7 @@ func TestOnboardInvoker(t *testing.T) { var client keycloak.Client client.Secret = &wantedInvokerSecret publishRegisterMock := publishmocks.PublishRegister{} - publishRegisterMock.On("GetAllPublishedServices").Return(publishedServices) + publishRegisterMock.On("GetAllowedPublishedServices", mock.AnythingOfType("[]publishserviceapi.ServiceAPIDescription")).Return(publishedServices) accessMgmMock := keycloackmocks.AccessManagement{} accessMgmMock.On("AddClient", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(nil) @@ -90,7 +91,9 @@ 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(wantedInvokerId)) assert.True(t, invokerUnderTest.VerifyInvokerSecret(wantedInvokerId, wantedInvokerSecret)) - publishRegisterMock.AssertCalled(t, "GetAllPublishedServices") + + publishRegisterMock.AssertCalled(t, "GetAllowedPublishedServices", mock.AnythingOfType("[]publishserviceapi.ServiceAPIDescription")) + assert.Equal(t, invokermanagementapi.APIList(publishedServices), *resultInvoker.ApiList) if invokerEvent, timeout := waitForEvent(eventChannel, 1*time.Second); timeout { assert.Fail(t, "No event sent") @@ -166,6 +169,29 @@ func TestDeleteInvoker(t *testing.T) { } } +func TestFailedUpdateInvoker(t *testing.T) { + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("GetAllPublishedServices").Return([]publishserviceapi.ServiceAPIDescription{}) + serviceUnderTest, _, requestHandler := getEcho(&publishRegisterMock, nil) + + invokerInfo := "invoker a" + invokerId := "api_invoker_id_" + strings.Replace(invokerInfo, " ", "_", 1) + + // Attempt to update with an invoker without the ApiInvokerId provided in the parameter body. We should get 400 with problem details. + invalidInvoker := getInvoker(invokerInfo) + serviceUnderTest.onboardedInvokers[invokerId] = invalidInvoker + + result := testutil.NewRequest().Put("/onboardedInvokers/"+invokerId).WithJsonBody(invalidInvoker).Go(t, requestHandler) + assert.Equal(t, http.StatusBadRequest, result.Code()) + + var problemDetails common29122.ProblemDetails + err := result.UnmarshalBodyToObject(&problemDetails) + assert.NoError(t, err, "error unmarshaling response") + assert.Equal(t, http.StatusBadRequest, *problemDetails.Status) + + assert.Contains(t, *problemDetails.Cause, "APIInvokerEnrolmentDetails ApiInvokerId doesn't match path parameter") +} + func TestUpdateInvoker(t *testing.T) { publishRegisterMock := publishmocks.PublishRegister{} publishRegisterMock.On("GetAllPublishedServices").Return([]publishserviceapi.ServiceAPIDescription{}) @@ -236,8 +262,7 @@ func TestUpdateInvoker(t *testing.T) { err = result.UnmarshalBodyToObject(&problemDetails) assert.NoError(t, err, "error unmarshaling response") assert.Equal(t, http.StatusBadRequest, *problemDetails.Status) - assert.Contains(t, *problemDetails.Cause, "not matching") - assert.Contains(t, *problemDetails.Cause, "ApiInvokerId") + assert.Contains(t, *problemDetails.Cause, "APIInvokerEnrolmentDetails ApiInvokerId doesn't match path parameter") // Update an invoker that has not been onboarded, should get 404 with problem details missingId := "1"