mock_share_response <- function(status_code = 200) {
resp_body <- '
ok
200
OK
1081111
3
jdoe@example.com
Doe, John (jdoe@example.com)
1
1
1
1636228602
wjn6dK***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/a
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
1683045553
1683045553
1620994286
/a
0
1676666170
1|***
(Shared Link)
***
https://example.com/s/wjn6dK***
0
0
1502082
3
jdoe@example.com
Doe, John (jdoe@example.com)
15
1
1
1703640861
3GgX8p***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/books
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
2543338818
2543338818
1620994286
/books
106727
1759322495
3|***
(Shared Link)
***
https://example.com/s/3GgX8p***
0
0
1038527
3
jdoe@example.com
Doe, John (jdoe@example.com)
1
1
1
1630149890
dCopD9***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/h
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
1620994367
1620994367
1620994286
/h
0
1749127658
1|***
(Shared Link)
***
https://example.com/s/dCopD9***
0
0
1498527
3
jdoe@example.com
Doe, John (jdoe@example.com)
31
1
1
1702864315
OsKtXj***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/hpc
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
2537637789
2537637789
1620994286
/hpc
4483541
1745525146
1|***
(Shared Link)
***
https://example.com/s/OsKtXj***
0
0
1498530
3
jdoe@example.com
Doe, John (jdoe@example.com)
1
1
1
1702866649
XfPJvX***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/hpc
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
2537637789
2537637789
1620994286
/hpc
4483541
1745525146
3|***
(Shared Link)
***
https://example.com/s/XfPJvX***
0
0
1426741
3
jdoe@example.com
Doe, John (jdoe@example.com)
1
1
1
1691849649
mebez2***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/l
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
2431988575
2431988575
1620994286
/l
0
1705574400
1|***
(Shared Link)
***
https://example.com/s/mebez2***
0
0
1251937
3
jdoe@example.com
Doe, John (jdoe@example.com)
1
1
1
1663695714
4HvsBa***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/m
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
1964784460
1964784460
1620994286
/m
0
1741220707
1|***
(Shared Link)
***
https://example.com/s/4HvsBa***
0
0
1616813
3
jdoe@example.com
Doe, John (jdoe@example.com)
15
1
1
1722541757
mNJy5g***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/ma
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
2914118015
2914118015
1620994286
/ma
0
1743417257
1|***
(Shared Link)
***
https://example.com/s/mNJy5g***
0
0
1819214
3
jdoe@example.com
Doe, John (jdoe@example.com)
17
1
1
1754253819
LfiwRE***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/s
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
2296213630
2296213630
1620994286
/s
0
1755160258
3|***
(Shared Link)
***
https://example.com/s/LfiwRE***
0
0
1876837
4
jdoe@example.com
Doe, John (jdoe@example.com)
17
1
1
1761697738
iCDQsZ***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/test
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
3434491981
3434491981
1620994286
0
1761216416
guntherkrauss@gmx.net
***
guntherkrauss@gmx.net
0
0
1038521
3
jdoe@example.com
Doe, John (jdoe@example.com)
1
1
1
1630149345
FfOw2P***
jdoe@example.com
Doe, John (jdoe@example.com)
/exchange/v
folder
31
httpd/unix-directory
home::jdoe@example.com
2404
1620995852
1620995852
1620994286
/v
0
1707956814
1|***
(Shared Link)
***
https://example.com/s/FfOw2P***
0
0
'
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)) {
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 <- '
ok
100
OK
jd007@example.com
Doe, Jack (jd007@example.com)
0
jd007@example.com
jack.doe@example.com
jd5@example.com
Doe, Jan (jd5@example.com)
6
jd5@example.com@other.example.com
other.example.com
'
resp_body_empty <- '
ok
100
OK
'
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)
}
}