Skip to content
Closed
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: audit.connect
Title: Posit Connect Health Check
Version: 0.8.12
Version: 0.8.13
Authors@R:
person("Jumping", "Rivers", , "info@jumpingrivers.com", role = c("aut", "cre"))
Description: Posit Connect Health Check. Deploys various content types to
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# audit.connect 0.8.13

## Bug fixes and minor improvements

* `sanitise()` also removes the auditor's name, email and username, every user's GUID and URL, and the usernames of locked users who own content (#69).

# audit.connect 0.8.12

## Bug fixes and minor improvements
Expand Down
27 changes: 23 additions & 4 deletions R/sanitise.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
#' Sanitise audit.connect object
#'
#' This function removes user-identifying data from an audit.connect object
#' This function removes user-identifying data from an audit.connect object:
#' the auditor's name, email, username and GUID, the same fields for every
#' user, each user's GUID and URL, and the usernames of locked users who own
#' content. Counts, roles and dates are kept, so the report still renders.
#' @param audit_connect_check An object from `audit.connect::check()`
#' @export
sanitise = function(audit_connect_check) {
# Wipe any user-identifiable data
for (value in c("email", "first_name", "last_name", "username")) {
audit_connect_check$users_details$user_list$users[, value] = NA_character_
personal = c("email", "first_name", "last_name", "username")

for (value in c(personal, "guid")) {
if (!is.null(audit_connect_check$audit_details[[value]])) {
audit_connect_check$audit_details[[value]] = NA_character_
}
}

users = audit_connect_check$users_details$user_list$users
if (!is.null(users)) {
users[intersect(personal, colnames(users))] = NA_character_
users = users[setdiff(colnames(users), c("guid", "url"))]
audit_connect_check$users_details$user_list$users = users
}

locked_apps = audit_connect_check$users_details$locked_apps
if (!is.null(locked_apps)) {
locked_apps$username = NA_character_
audit_connect_check$users_details$locked_apps = locked_apps
}
audit_connect_check
}
5 changes: 4 additions & 1 deletion man/sanitise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 33 additions & 18 deletions tests/testthat/test-sanitise.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
describe("Checking sanitize function", {
skip_if_not_live()
dir = withr::local_tempdir()
# Skip report checks for speed
create_config(dir = dir, default = FALSE, type = "force")
rtn = suppressMessages(check(dir = dir))
sanitize_rtn = sanitise(rtn)

it(
"Check users have been changed",
expect_false(identical(
rtn[["users_details"]],
sanitize_rtn[["users_details"]]
))
test_that("sanitise() removes names, emails, usernames, GUIDs and user URLs", {
personal = c("email", "first_name", "last_name", "username")
out = list(
audit_details = list(
email = "ada@example.com",
first_name = "Ada",
last_name = "Lovelace",
username = "alovelace",
guid = "guid-ada",
user_role = "administrator"
),
users_details = list(
user_list = list(
users = tibble::tibble(
email = "bob@example.com",
first_name = "Bob",
last_name = "Jones",
username = "bjones",
guid = "guid-bob",
user_role = "viewer",
url = "https://connect.example.com/connect/#/people/users/guid-bob"
)
),
locked_apps = tibble::tibble(username = "bjones", n = 3L)
)
)

it("Check everything else has stayed the same", {
rtn[["users_details"]] = sanitize_rtn[["users_details"]] = NULL
expect_identical(rtn, sanitize_rtn)
})
sanitised = sanitise(out)
users = sanitised$users_details$user_list$users

expect_named(users, c(personal, "user_role"))
expect_true(all(is.na(users[personal])))
expect_true(all(is.na(sanitised$audit_details[c(personal, "guid")])))
expect_identical(sanitised$audit_details$user_role, "administrator")
expect_identical(sanitised$users_details$locked_apps$username, NA_character_)
})
Loading