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

Bug fix for: Admin Users must be able to access all monitors #139 #280

Merged
merged 1 commit into from
Jan 15, 2022
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 @@ -86,6 +86,8 @@ interface SecureTransportAction {
)
)
return false
} else if (isAdmin(user)) {
return true
} else if (user.backendRoles.isNullOrEmpty()) {
actionListener.onFailure(
AlertingException.wrap(
Expand All @@ -112,7 +114,7 @@ interface SecureTransportAction {
resourceId: String
): Boolean {

if (!filterByEnabled) return true
if (!doFilterForUser(requesterUser)) return true

val resourceBackendRoles = resourceUser?.backendRoles
val requesterBackendRoles = requesterUser?.backendRoles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,25 @@ class SecureMonitorRestApiIT : AlertingRestTestCase() {
)
assertEquals("Search monitor failed", RestStatus.OK, adminSearchResponse.restStatus())
assertEquals("Monitor not found during search", 1, getDocs(adminSearchResponse))

// get as "admin" - must get 1 docs
val id: String = monitorJson["_id"] as String
Copy link
Contributor

Choose a reason for hiding this comment

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

Add assertion check for ID?

val adminGetResponse = client().makeRequest(
"GET",
"$ALERTING_BASE_URI/$id",
emptyMap(),
NStringEntity(search, ContentType.APPLICATION_JSON)
)
assertEquals("Get monitor failed", RestStatus.OK, adminGetResponse.restStatus())
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a more descriptive error message?

Copy link
Member

Choose a reason for hiding this comment

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

I think that is fine since its is part of the assertion failure which would mean the request failed to get the monitor


// delete as "admin"
val adminDeleteResponse = client().makeRequest(
"DELETE",
"$ALERTING_BASE_URI/$id",
emptyMap(),
NStringEntity(search, ContentType.APPLICATION_JSON)
)
assertEquals("Delete monitor failed", RestStatus.OK, adminGetResponse.restStatus())
} finally {
deleteRoleMapping("hr_role")
deleteRole("hr_role")
Expand Down