mock_share_response <- function(status_code = 200) {
resp_body <- '
ok200OK10811113jdoe@example.comDoe, John (jdoe@example.com)1111636228602wjn6dK***jdoe@example.comDoe, John (jdoe@example.com)/exchange/afolder31httpd/unix-directoryhome::jdoe@example.com2404168304555316830455531620994286/a016766661701|***(Shared Link)***https://example.com/s/wjn6dK***0015020823jdoe@example.comDoe, John (jdoe@example.com)151117036408613GgX8p***jdoe@example.comDoe, John (jdoe@example.com)/exchange/booksfolder31httpd/unix-directoryhome::jdoe@example.com2404254333881825433388181620994286/books10672717593224953|***(Shared Link)***https://example.com/s/3GgX8p***0010385273jdoe@example.comDoe, John (jdoe@example.com)1111630149890dCopD9***jdoe@example.comDoe, John (jdoe@example.com)/exchange/hfolder31httpd/unix-directoryhome::jdoe@example.com2404162099436716209943671620994286/h017491276581|***(Shared Link)***https://example.com/s/dCopD9***0014985273jdoe@example.comDoe, John (jdoe@example.com)31111702864315OsKtXj***jdoe@example.comDoe, John (jdoe@example.com)/exchange/hpcfolder31httpd/unix-directoryhome::jdoe@example.com2404253763778925376377891620994286/hpc448354117455251461|***(Shared Link)***https://example.com/s/OsKtXj***0014985303jdoe@example.comDoe, John (jdoe@example.com)1111702866649XfPJvX***jdoe@example.comDoe, John (jdoe@example.com)/exchange/hpcfolder31httpd/unix-directoryhome::jdoe@example.com2404253763778925376377891620994286/hpc448354117455251463|***(Shared Link)***https://example.com/s/XfPJvX***0014267413jdoe@example.comDoe, John (jdoe@example.com)1111691849649mebez2***jdoe@example.comDoe, John (jdoe@example.com)/exchange/lfolder31httpd/unix-directoryhome::jdoe@example.com2404243198857524319885751620994286/l017055744001|***(Shared Link)***https://example.com/s/mebez2***0012519373jdoe@example.comDoe, John (jdoe@example.com)11116636957144HvsBa***jdoe@example.comDoe, John (jdoe@example.com)/exchange/mfolder31httpd/unix-directoryhome::jdoe@example.com2404196478446019647844601620994286/m017412207071|***(Shared Link)***https://example.com/s/4HvsBa***0016168133jdoe@example.comDoe, John (jdoe@example.com)15111722541757mNJy5g***jdoe@example.comDoe, John (jdoe@example.com)/exchange/mafolder31httpd/unix-directoryhome::jdoe@example.com2404291411801529141180151620994286/ma017434172571|***(Shared Link)***https://example.com/s/mNJy5g***0018192143jdoe@example.comDoe, John (jdoe@example.com)17111754253819LfiwRE***jdoe@example.comDoe, John (jdoe@example.com)/exchange/sfolder31httpd/unix-directoryhome::jdoe@example.com2404229621363022962136301620994286/s017551602583|***(Shared Link)***https://example.com/s/LfiwRE***0018768374jdoe@example.comDoe, John (jdoe@example.com)17111761697738iCDQsZ***jdoe@example.comDoe, John (jdoe@example.com)/exchange/testfolder31httpd/unix-directoryhome::jdoe@example.com240434344919813434491981162099428601761216416guntherkrauss@gmx.net***guntherkrauss@gmx.net0010385213jdoe@example.comDoe, John (jdoe@example.com)1111630149345FfOw2P***jdoe@example.comDoe, John (jdoe@example.com)/exchange/vfolder31httpd/unix-directoryhome::jdoe@example.com2404162099585216209958521620994286/v017079568141|***(Shared Link)***https://example.com/s/FfOw2P***00
'
httr2::response(status_code = status_code,
headers = list("Content-Type" = "application/xml"),
body = charToRaw(resp_body))
}
mock_share <- function(req) {
u <- req |>
httr2::req_get_url() |>
httr2::url_parse()
p <- u$query$path
ids <- strsplit(u$path, "/")[[1]]
id <- ids[length(ids)]
if (id == "send-email") {
id <- ids[length(ids) - 1]
}
if (req$method == "POST") {
p <- httr2::req_get_body(req)$path
if (!is.null(p)) {
p <- utils::URLdecode(p)
}
p
}
if (!is.null(p)) {
if (p == "/" || p == "/exchange") {
mock_share_response()
} else {
mock_share_response(404)
}
} else if (id == "10" || (id == "12" && req$method != "PUT")) {
mock_share_response()
} else if (id == "11") {
mock_share_response(404)
} else {
mock_share_response(500)
}
}
mock_users_response <- function(status_code = 200, empty = TRUE) {
resp_body_found <- '
ok100OKjd007@example.comDoe, Jack (jd007@example.com)0jd007@example.comjack.doe@example.com
jd5@example.comDoe, Jan (jd5@example.com)6jd5@example.com@other.example.comother.example.com'
resp_body_empty <- '
ok100OK'
resp_body <- ifelse(empty, resp_body_empty, resp_body_found)
httr2::response(status_code = status_code,
headers = list("Content-Type" = "application/xml"),
body = charToRaw(resp_body))
}
mock_users <- function(req) {
u <- req |>
httr2::req_get_url() |>
httr2::url_parse()
s <- u$query$search
if (s == "Doe") {
mock_users_response(200, FALSE)
} else {
mock_users_response(200, TRUE)
}
}