File tree Expand file tree Collapse file tree
integrationTest/java/org/opensearch/security/privileges/dlsfls
main/java/org/opensearch/security/privileges/dlsfls Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6767
6868import static org .hamcrest .MatcherAssert .assertThat ;
6969import static org .hamcrest .Matchers .containsString ;
70+ import static org .hamcrest .Matchers .equalTo ;
7071import static org .opensearch .security .util .MockIndexMetadataBuilder .dataStreams ;
7172import static org .opensearch .security .util .MockIndexMetadataBuilder .indices ;
7273import static org .junit .Assert .assertEquals ;
@@ -386,6 +387,10 @@ public void queryPatternTemplate() throws Exception {
386387 if (index == index_a1 ) {
387388 if (userSpec .roles .contains ("dls_role_1" ) && userSpec .roles .contains ("dls_role_2" )) {
388389 assertNotNull (exception );
390+ assertThat (
391+ exception .getMessage (),
392+ equalTo ("DLS query references undefined user attributes: [attr.attr_a]. Available attributes are: [none]" )
393+ );
389394 }
390395 }
391396 } else if (userSpec .roles .contains ("non_dls_role" ) && dfmEmptyOverridesAll ) {
Original file line number Diff line number Diff line change @@ -168,12 +168,17 @@ RenderedDlsQuery evaluate(PrivilegesEvaluationContext context) throws Privileges
168168 if (UserAttributes .needsAttributeSubstitution (effectiveQueryString )) {
169169 List <String > unresolved = UserAttributes .findUnresolvedAttributes (effectiveQueryString );
170170 Set <String > available = context .getUser ().getCustomAttributesMap ().keySet ();
171- String availableStr = available .size () > MAX_ATTRIBUTES_IN_ERROR_MESSAGE
172- ? available .stream ().limit (MAX_ATTRIBUTES_IN_ERROR_MESSAGE ).collect (Collectors .joining (", " ))
171+ String availableStr ;
172+ if (available .size () > MAX_ATTRIBUTES_IN_ERROR_MESSAGE ) {
173+ availableStr = available .stream ().limit (MAX_ATTRIBUTES_IN_ERROR_MESSAGE ).collect (Collectors .joining (", " ))
173174 + " ... and "
174175 + (available .size () - MAX_ATTRIBUTES_IN_ERROR_MESSAGE )
175- + " more"
176- : String .join (", " , available );
176+ + " more" ;
177+ } else if (!available .isEmpty ()) {
178+ availableStr = String .join (", " , available );
179+ } else {
180+ availableStr = "[none]" ;
181+ }
177182 throw new PrivilegesEvaluationException (
178183 "DLS query references undefined user attributes: " + unresolved + ". Available attributes are: " + availableStr ,
179184 new OpenSearchSecurityException ("User attribute substitution failed" )
You can’t perform that action at this time.
0 commit comments