// ========================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.
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)
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")
}
}
+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{})
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"