Skip to content

Conversation

@Avinash1423
Copy link
Contributor

Fix for #1201

Discription:

Added null Check for checkUserPermissions and moved isAdmin() to be executed prior to the checkUserPermissions().

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.43%. Comparing base (4ffc945) to head (23934b1).

Files with missing lines Patch % Lines
.../org/opensearch/flowframework/util/ParseUtils.java 14.28% 4 Missing and 2 partials ⚠️

❌ Your patch check has failed because the patch coverage (14.28%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1292      +/-   ##
============================================
- Coverage     77.46%   77.43%   -0.03%     
- Complexity     1260     1263       +3     
============================================
  Files           106      106              
  Lines          5901     5904       +3     
  Branches        612      614       +2     
============================================
+ Hits           4571     4572       +1     
  Misses         1034     1034              
- Partials        296      298       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix! A suggestion to combine the conditionals into one.

Also need a unit test or integ test validating this new behavior, and a CHANGELOG entry.

Comment on lines 378 to 383
if (requestedUser == null || resourceUser == null) {
return false;
}
if (resourceUser.getBackendRoles() == null || requestedUser.getBackendRoles() == null) {
return false;
}
Copy link
Member

@dbwiddis dbwiddis Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines can probably be combined into one conditional, or maybe we can create a helper method taking varargs User... that we can iterate over and just call if (nullOrNoRoles(requestedUser, resourceUsers)) { return false; }.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbwiddis Thanks for the feedback. Sure, will take a look

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Avinash1423 sorry for slowness with the holidays and catching up this week. I'll take a good look at this this weekend.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress, see comments below.

Comment on lines +370 to +377
private static boolean hasUsersAndRoles(User requestedUser, User resourceUser) {

return requestedUser != null
&& resourceUser != null
&& resourceUser.getBackendRoles() != null
&& requestedUser.getBackendRoles() != null;

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static boolean hasUsersAndRoles(User requestedUser, User resourceUser) {
return requestedUser != null
&& resourceUser != null
&& resourceUser.getBackendRoles() != null
&& requestedUser.getBackendRoles() != null;
}
private static boolean hasUsersAndRoles(User... users) {
boolean nonNull = true;
for (User user: users) {
if (user == null || user.getBakendRoles() == null) {
nonNull = false;
break;
}
}
return nonNull;
}

Or you can possibly use a stream.

return false;
}

if (!hasUsersAndRoles(requestedUser, resourceUser)) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but given the negation we may want to make the helper method nullUsersOrRoles and reverse the true/false in it.

return false;
}

// method to expose checkUserPermissions for testing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to just make the existing method package private with this comment than have a wrapper method to do the same thing.

It actually wouldn't hurt to just make the method public.

Comment on lines +448 to +458
public void testCheckUserPermissionsWithNullUsers() throws Exception {

User mockrequestedUser = null;
User mockresourceUser = new User();
String mockWorkFlowId = "mockWorkFlowId";

boolean res = ParseUtils.exposeCheckUserPermissions(mockrequestedUser, mockresourceUser, mockWorkFlowId);

assertFalse(res);

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good test case but you need to test all the conditional cases (null/non-null on both requested and resource user).

### Features
### Enhancements
### Bug Fixes
- Fixed user permission validation to correctly handle null users and backend roles.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the format of our change log entries (see the release notes for where they eventually go) and add a blank line after this so the markdown properly renders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants