"enhanced request body parsing handles all content types"
'{"name": "test", "value": 123, "nested": {"key": "value"}}'
"transformation hooks handle errors gracefully"
"data processing handles edge cases and large payloads"
'{"name": "test", "value": 123, "incomplete"'
'{"message": "Hello 世界 🌍", "emoji": "🚀", "accents": "café"}'
"content type detection handles various formats"
"error handling provides useful information"
'{"name": "test", "value": 123, "missing_quote: true}'

content type detection handles various formats

response$status (`actual`) not equal to 200L (`expected`).

  `actual`: 403
`expected`: 200

# Integration tests for shinypayload - Real-world scenarios
test_that("webhook endpoint simulation with full security", {
payload_debug_config(debug_mode = TRUE, log_level = "INFO")
payload_history_config(max_items = 1000, max_age_hours = 72)
payload_json <- jsonlite::toJSON(github_payload, auto_unbox = TRUE)
signature <- digest::hmac(webhook_secret, body_raw, algo = "sha256", serialize = FALSE, raw = FALSE)
# Verify payload was stored with correct metadata
test_that("full workflow integration test", {
ui <- payload_ui(base_ui, path = "/data", token = "test123")
# Test that UI function is created properly
test_that("POST request flow works end-to-end", {
# Reset security configuration to avoid interference from other tests
ui <- payload_ui(base_ui, path = "/api", token = "secret")
# Simulate POST request with proper body reading
test_that("authentication flow works correctly", {
ui <- payload_ui(base_ui, path = "/secure", token = "supersecret")
rook.input = list(read = function() NULL)
# Test authorized request with query parameter
rook.input = list(read = function() charToRaw('{"auth": "test"}'))
if (call_count == 1) charToRaw('{"auth": "test"}') else NULL
test_that("different content types are handled", {
ui <- payload_ui(base_ui, path = "/forms", token = NULL)
test_that("error handling in POST processing", {
ui <- payload_ui(base_ui, path = "/error-test", token = NULL)
charToRaw('{"malformed": json}') # Invalid JSON
# Should still return 200 but store the raw text
test_that("state isolation between paths", {
ui <- payload_ui(base_ui, path = "/path1", token = NULL)
test_that("IoT sensor data collection with transformations", {
# Configure data transformation for sensor readings
sensor_transform <- function(data, content_type, req) {
if (is.list(data) && !is.null(data$temperature) && !is.null(data$humidity)) {
# Convert Celsius to Fahrenheit and calculate heat index
if (temp_f >= 80 && data$humidity >= 40) {
heat_index <- temp_f + 0.5 * (data$humidity - 50)
payload_history_config(max_items = 500, max_age_hours = 168)  # 1 week retention
# Create UI for multiple sensor endpoints using payload_methods
list(path = "/sensors/temperature", methods = "POST", token = "iot-device-token"),
list(path = "/sensors/humidity", methods = "POST", token = "iot-device-token"),
list(path = "/sensors/air_quality", methods = "POST", token = "iot-device-token")
sensor_locations <- c("living_room", "bedroom", "kitchen")
temperature = round(runif(1, 18, 35), 1),  # 18-35°C
pressure = round(runif(1, 980, 1020), 2),  # hPa
battery_level = round(runif(1, 20, 100), 0)
sensor_json <- jsonlite::toJSON(sensor_data, auto_unbox = TRUE)
# Send sensor data to appropriate endpoint
endpoint <- if (sensor_data$temperature > 30) "/sensors/temperature" else
if (sensor_data$humidity > 70) "/sensors/humidity" else
HEADERS = list("content-type" = "application/json"),
Sys.sleep(0.01)  # Small delay to simulate real timing
# Verify data collection and transformations
# Check that transformations were applied
test_that("e-commerce order processing with multiple endpoints", {
# Configure rate limiting for customer protection
rate_limit_window_seconds = 300  # 5 minutes
# Setup multiple endpoints for different order stages using payload_methods
list(path = "/orders/cart", methods = "POST", token = "ecommerce-api-key"),
list(path = "/orders/checkout", methods = "POST", token = "ecommerce-api-key"),
list(path = "/orders/payment", methods = "POST", token = "ecommerce-api-key"),
list(path = "/orders/fulfillment", methods = "POST", token = "ecommerce-api-key")
customer_id <- paste0("customer_", sprintf("%03d", session))
session_id <- paste0("session_", session, "_", as.integer(Sys.time()))
cart_json <- jsonlite::toJSON(cart_data, auto_unbox = TRUE)
Sys.sleep(0.1)  # Simulate user thinking time
checkout_json <- jsonlite::toJSON(checkout_data, auto_unbox = TRUE)
session_ids <- unique(sapply(cart_history, function(p) p$payload$session_id))
test_that("log monitoring and alerting system simulation", {
payload_debug_config(debug_mode = TRUE, log_level = "DEBUG", max_log_entries = 2000)
# Create UI for log ingestion using payload_methods
list(path = "/logs/application", methods = "POST", token = "monitoring-token"),
list(path = "/logs/system", methods = "POST", token = "monitoring-token"),
list(path = "/logs/security", methods = "POST", token = "monitoring-token")
# Simulate application generating various log levels
list(endpoint = "/logs/application", level = "INFO", message = "User logged in successfully"),
list(endpoint = "/logs/application", level = "WARN", message = "Slow database query detected"),
list(endpoint = "/logs/application", level = "ERROR", message = "Database connection failed"),
list(endpoint = "/logs/system", level = "INFO", message = "System health check passed"),
list(endpoint = "/logs/security", level = "WARN", message = "Multiple failed login attempts detected")
message = paste(scenario$message, "- iteration", iteration),
log_json <- jsonlite::toJSON(log_entry, auto_unbox = TRUE)
all_logs <- c(app_logs, system_logs, security_logs)
error_logs <- Filter(function(log) log$payload$level == "ERROR", all_logs)
warning_logs <- Filter(function(log) log$payload$level == "WARN", all_logs)
(p$level == "WARN" && grepl("security|login", p$message, ignore.case = TRUE))
alerts <- Filter(function(log) alert_condition(log), all_logs)
payload_debug_config(debug_mode = FALSE, log_level = "INFO", max_log_entries = 1000)
test_that("stress testing combined features under load", {
payload_history_config(max_items = 500, max_age_hours = 1)
payload_debug_config(debug_mode = TRUE, log_level = "WARN")  # Reduce log noise
# Create UI with multiple endpoints using payload_methods
list(path = "/api/metrics", methods = "POST", token = "stress-test-token"),
list(path = "/api/events", methods = "POST", token = "stress-test-token")
total_requests <- 50  # Reduced for test performance
payload_json <- jsonlite::toJSON(payload_data, auto_unbox = TRUE)
duration <- as.numeric(difftime(end_time, start_time, units = "secs"))
expect_true(success_count > total_requests * 0.8)  # 80%+ success rate
expect_true(duration < 10)  # Should complete reasonably fast
# Verify data integrity after stress test
timestamps <- sapply(history, function(h) h$timestamp)
payload_debug_config(debug_mode = FALSE, log_level = "INFO")
payload_history_config(max_items = 100, max_age_hours = 24)