Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null checks on role mapping #3800

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ public RoleMapping getRoleMapping(String principalId) {
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Admin)
@RoleBasedAccessApiOperation
public void updateRoleMapping(String principalId, UpdateRole data) {
requireParameter("principalId", principalId);
requireParameter("role", data.getRole());
Copy link
Member

Choose a reason for hiding this comment

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

This null check should be performed in more places, basically, the entire AdminResourceImpl.java file should be reviewed.
A couple of additional places where a similar should be reproducible:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @andreaTP for the review.
I'll look for related beginner friendly issues and add the checks there as well.

storage.updateRoleMapping(principalId, data.getRole().name());
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/test/java/io/apicurio/registry/rbac/AdminResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,16 @@ public void testRoleMappings() throws Exception {
.body("error_code", equalTo(404))
.body("message", equalTo("No mapping for principal 'UnknownPrincipal' and role 'READ_ONLY' was found."));

//Update a mapping with null RoleType
Copy link
Member

Choose a reason for hiding this comment

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

👍

update.setRole(null);
given()
.when()
.contentType(CT_JSON)
.body(update)
.put("/registry/v2/admin/roleMappings/TestUser")
.then()
.statusCode(400);

// Delete a role mapping
given()
.when()
Expand Down