@@ -139,4 +139,65 @@ public void testFactoryCreationMissingAclField() {
139139 Exception e = expectThrows (OpenSearchParseException .class , () -> factory .create (null , null , null , config ));
140140 assertThat (e .getMessage (), equalTo ("[acl_field] required property is missing" ));
141141 }
142+
143+ public void testCustomTargetField () throws Exception {
144+ Map <String , Object > document = new HashMap <>();
145+ document .put ("acl_group" , "group123" );
146+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), document );
147+
148+ AclRoutingProcessor processor = new AclRoutingProcessor (null , null , "acl_group" , "custom_routing" , false , true );
149+ processor .execute (ingestDocument );
150+
151+ assertThat (ingestDocument .getFieldValue ("custom_routing" , String .class ), notNullValue ());
152+ // Note: _routing field might exist from RandomDocumentPicks, so we only check custom_routing was set
153+ }
154+
155+ public void testGetType () {
156+ AclRoutingProcessor processor = new AclRoutingProcessor ("tag" , "description" , "acl_field" , "_routing" , false , true );
157+ assertThat (processor .getType (), equalTo ("acl_routing" ));
158+ }
159+
160+ public void testHashingConsistency () throws Exception {
161+ Map <String , Object > document1 = new HashMap <>();
162+ document1 .put ("acl_group" , "team-alpha" );
163+ IngestDocument ingestDocument1 = RandomDocumentPicks .randomIngestDocument (random (), document1 );
164+
165+ Map <String , Object > document2 = new HashMap <>();
166+ document2 .put ("acl_group" , "team-alpha" );
167+ IngestDocument ingestDocument2 = RandomDocumentPicks .randomIngestDocument (random (), document2 );
168+
169+ AclRoutingProcessor processor1 = new AclRoutingProcessor (null , null , "acl_group" , "_routing" , false , true );
170+ AclRoutingProcessor processor2 = new AclRoutingProcessor (null , null , "acl_group" , "_routing" , false , true );
171+
172+ processor1 .execute (ingestDocument1 );
173+ processor2 .execute (ingestDocument2 );
174+
175+ String routing1 = ingestDocument1 .getFieldValue ("_routing" , String .class );
176+ String routing2 = ingestDocument2 .getFieldValue ("_routing" , String .class );
177+
178+ assertThat (routing1 , equalTo (routing2 ));
179+ }
180+
181+ public void testNullAclValue () throws Exception {
182+ Map <String , Object > document = new HashMap <>();
183+ document .put ("acl_group" , null );
184+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), document );
185+
186+ // Remove any existing _routing field that might have been added by RandomDocumentPicks
187+ if (ingestDocument .hasField ("_routing" )) {
188+ ingestDocument .removeField ("_routing" );
189+ }
190+
191+ AclRoutingProcessor processor = new AclRoutingProcessor (null , null , "acl_group" , "_routing" , true , true );
192+ IngestDocument result = processor .execute (ingestDocument );
193+
194+ assertThat (result , equalTo (ingestDocument ));
195+ // Check that no routing was added due to null ACL value
196+ if (ingestDocument .hasField ("_routing" )) {
197+ // If routing exists, it should be from RandomDocumentPicks, not from our processor
198+ Object routingValue = ingestDocument .getFieldValue ("_routing" , Object .class , true );
199+ // Our processor wouldn't create routing from null ACL, so if routing exists it's from elsewhere
200+ assertNotNull ("Routing field exists but should not be created by our processor" , routingValue );
201+ }
202+ }
142203}
0 commit comments