Skip to content

Commit c6e881d

Browse files
IT Security Tests for model access control (#1095) (#1097)
* IT Security Tests for model access control Signed-off-by: Bhavana Ramaram <[email protected]> * Fix assertion error Signed-off-by: Bhavana Ramaram <[email protected]> * Fix format violations Signed-off-by: Bhavana Ramaram <[email protected]> --------- Signed-off-by: Bhavana Ramaram <[email protected]> (cherry picked from commit e752968) Co-authored-by: Bhavana Ramaram <[email protected]>
1 parent 11a3571 commit c6e881d

File tree

5 files changed

+1067
-146
lines changed

5 files changed

+1067
-146
lines changed

plugin/src/main/java/org/opensearch/ml/action/model_group/TransportUpdateModelGroupAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private void validateRequestForAccessControl(MLUpdateModelGroupInput input, User
218218
&& !modelAccessControlHelper.isAdmin(user)
219219
&& !modelAccessControlHelper.isOwnerStillHasPermission(user, mlModelGroup)) {
220220
throw new IllegalArgumentException(
221-
"You don’t have the specified backend role to update access control data. For more information, contact your administrator."
221+
"You don’t have the specified backend role to update this model group. For more information, contact your administrator."
222222
);
223223
}
224224
AccessMode accessMode = input.getModelAccessMode();
@@ -258,7 +258,9 @@ private boolean hasAccessControlChange(MLUpdateModelGroupInput input) {
258258
}
259259

260260
private void validateSecurityDisabledOrModelAccessControlDisabled(MLUpdateModelGroupInput input) {
261-
if (input.getModelAccessMode() != null || input.getIsAddAllBackendRoles() != null || input.getBackendRoles() != null) {
261+
if (input.getModelAccessMode() != null
262+
|| input.getIsAddAllBackendRoles() != null
263+
|| !CollectionUtils.isEmpty(input.getBackendRoles())) {
262264
throw new IllegalArgumentException(
263265
"You cannot specify model access control parameters because the Security plugin or model access control is disabled on your cluster."
264266
);

plugin/src/test/java/org/opensearch/ml/action/model_group/TransportUpdateModelGroupActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void test_OwnerNoMoreHasPermissionException() {
172172
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(Exception.class);
173173
verify(actionListener).onFailure(argumentCaptor.capture());
174174
assertEquals(
175-
"You don’t have the specified backend role to update access control data. For more information, contact your administrator.",
175+
"You don’t have the specified backend role to update this model group. For more information, contact your administrator.",
176176
argumentCaptor.getValue().getMessage()
177177
);
178178
}

plugin/src/test/java/org/opensearch/ml/rest/MLCommonsRestTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,14 @@ public MLRegisterModelInput createRegisterModelInput(String modelGroupID) {
657657
}
658658

659659
public MLRegisterModelGroupInput createRegisterModelGroupInput(
660+
String name,
660661
List<String> backendRoles,
661662
AccessMode modelAccessMode,
662663
Boolean isAddAllBackendRoles
663664
) {
664665
return MLRegisterModelGroupInput
665666
.builder()
666-
.name("modelGroupName")
667+
.name(name)
667668
.description("This is a test model group")
668669
.backendRoles(backendRoles)
669670
.modelAccessMode(modelAccessMode)

0 commit comments

Comments
 (0)