Moti Asayag has uploaded a new change for review. Change subject: restapi: Assure network existence when adding a vnic profile ......................................................................
restapi: Assure network existence when adding a vnic profile In order to create a vnic profile, the user must provide the network id to which he wishes to add the profile. If a network cannot be obtained by the id, the parameters should consider invalid and a proper message should be returned. The backend has logic for this scenario, however when performing this action with a user that its permissions should be verified, there is a generic "User is not authorized to perform this action" even though the message refers to a non-existing network entity. Change-Id: Ib517cc0fd04c4f0e12fd6bdbdca8c6277600e325 Bug-Url: https://bugzilla.redhat.com/1031369 Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResourceTest.java 3 files changed, 23 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/24327/1 diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java index 079755d..5fcf215 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResource.java @@ -9,6 +9,8 @@ import org.ovirt.engine.api.model.VnicProfiles; import org.ovirt.engine.api.resource.VnicProfileResource; import org.ovirt.engine.api.resource.VnicProfilesResource; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -31,6 +33,10 @@ @Override protected void validateParameters(VnicProfile vnicProfile) { validateParameters(vnicProfile, "name", "network.id"); + String networkId = vnicProfile.getNetwork().getId(); + // verify the network.id is well provided + getEntity(Network.class, VdcQueryType.GetNetworkById, new IdQueryParameters(asGuid(networkId)), "Network: id=" + + networkId); } @SingleEntityResource diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResourceTest.java index 0864306..e313e78 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResourceTest.java @@ -110,6 +110,7 @@ @Test public void testAddVnicProfile() throws Exception { setUriInfo(setUpBasicUriExpectations()); + setUpNetworkQueryExpectations(); setUpCreationExpectations(VdcActionType.AddVnicProfile, VnicProfileParameters.class, new String[] {}, @@ -134,11 +135,13 @@ @Test public void testAddVnicProfileCantDo() throws Exception { + setUpNetworkQueryExpectations(); doTestBadAddVnicProfile(false, true, CANT_DO); } @Test public void testAddVnicProfileFailure() throws Exception { + setUpNetworkQueryExpectations(); doTestBadAddVnicProfile(true, false, FAILURE); } @@ -313,6 +316,9 @@ index); } + protected void setUpNetworkQueryExpectations() { + } + static org.ovirt.engine.core.common.businessentities.network.VnicProfile setUpEntityExpectations(org.ovirt.engine.core.common.businessentities.network.VnicProfile entity, int index) { expect(entity.getId()).andReturn(GUIDS[index]).anyTimes(); diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResourceTest.java index 5ac7287..488195d 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVnicProfilesResourceTest.java @@ -3,6 +3,8 @@ import java.util.List; import org.ovirt.engine.api.model.VnicProfile; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -28,4 +30,13 @@ protected List<VnicProfile> getCollection() { return collection.list().getVnicProfiles(); } + + @Override + protected void setUpNetworkQueryExpectations() { + setUpEntityQueryExpectations(VdcQueryType.GetNetworkById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { NETWORK_ID }, + new Network()); + } } -- To view, visit http://gerrit.ovirt.org/24327 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib517cc0fd04c4f0e12fd6bdbdca8c6277600e325 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
