@@ -418,6 +418,49 @@ public void test_CreateSearchSourceBuilder() {
418418 assertNotNull (modelAccessControlHelper .createSearchSourceBuilder (user ));
419419 }
420420
421+ public void test_MultiTenancyEnabled_BypassesValidation () {
422+ // Test that when multi-tenancy is enabled, validation is bypassed and returns true
423+ User user = User .parse ("owner|IT,HR|myTenant" );
424+ when (mlFeatureEnabledSetting .isMultiTenancyEnabled ()).thenReturn (true );
425+
426+ modelAccessControlHelper
427+ .validateModelGroupAccess (user , mlFeatureEnabledSetting , null , "testGroupID" , client , sdkClient , actionListener );
428+
429+ ArgumentCaptor <Boolean > argumentCaptor = ArgumentCaptor .forClass (Boolean .class );
430+ verify (actionListener ).onResponse (argumentCaptor .capture ());
431+ assertTrue (argumentCaptor .getValue ());
432+ }
433+
434+ public void test_MultiTenancyDisabled_ProceedsWithValidation () throws IOException {
435+ // Test that when multi-tenancy is disabled, normal validation logic proceeds
436+ User user = User .parse ("owner|IT,HR|myTenant" );
437+ when (mlFeatureEnabledSetting .isMultiTenancyEnabled ()).thenReturn (false );
438+
439+ // Setup a public model group to ensure validation passes
440+ String owner = "owner|IT,HR|myTenant" ;
441+ List <String > backendRoles = Arrays .asList ("IT" , "HR" );
442+ setupModelGroup (owner , AccessMode .PUBLIC .getValue (), backendRoles );
443+
444+ PlainActionFuture <GetResponse > future = PlainActionFuture .newFuture ();
445+ future .onResponse (getResponse );
446+ when (client .get (any ())).thenReturn (future );
447+
448+ CountDownLatch latch = new CountDownLatch (1 );
449+ LatchedActionListener <Boolean > latchedActionListener = new LatchedActionListener <>(actionListener , latch );
450+ modelAccessControlHelper
451+ .validateModelGroupAccess (user , mlFeatureEnabledSetting , null , "testGroupID" , client , sdkClient , latchedActionListener );
452+
453+ try {
454+ latch .await (500 , TimeUnit .MILLISECONDS );
455+ } catch (InterruptedException e ) {
456+ Thread .currentThread ().interrupt ();
457+ }
458+
459+ ArgumentCaptor <Boolean > argumentCaptor = ArgumentCaptor .forClass (Boolean .class );
460+ verify (actionListener ).onResponse (argumentCaptor .capture ());
461+ assertTrue (argumentCaptor .getValue ());
462+ }
463+
421464 private GetResponse modelGroupBuilder (List <String > backendRoles , String access , String owner ) throws IOException {
422465 MLModelGroup mlModelGroup = MLModelGroup
423466 .builder ()
0 commit comments