Skip to content

Commit 67178d8

Browse files
committed
Fixed failing tests and added new unit test
1 parent 6a1ff35 commit 67178d8

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/sources/splunk_hec/mod.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl SplunkSource {
543543
.as_ref()
544544
.and_then(|v| v.to_str().ok())
545545
.map(|h| h.to_ascii_lowercase().contains("application/json"))
546-
.unwrap_or(false);
546+
.unwrap_or(true);
547547

548548
if !ok {
549549
return Err(warp::reject::custom(ApiError::UnsupportedContentType));
@@ -2524,6 +2524,51 @@ mod tests {
25242524
assert!(ack_res.acks.get(&event_res.ack_id).unwrap());
25252525
}
25262526

2527+
#[tokio::test]
2528+
async fn ack_service_accepts_parameterized_content_type() {
2529+
let ack_config = HecAcknowledgementsConfig {
2530+
enabled: Some(true),
2531+
..Default::default()
2532+
};
2533+
let (source, address) = source(Some(ack_config)).await;
2534+
let opts = SendWithOpts {
2535+
channel: Some(Channel::Header("guid")),
2536+
forwarded_for: None,
2537+
};
2538+
2539+
let event_res = send_with_response(
2540+
address,
2541+
"services/collector/event",
2542+
r#"{"event":"param-test"}"#,
2543+
TOKEN,
2544+
&opts,
2545+
)
2546+
.await
2547+
.json::<HecAckEventResponse>()
2548+
.await
2549+
.unwrap();
2550+
let _ = collect_n(source, 1).await;
2551+
2552+
let body = serde_json::to_string(&HecAckStatusRequest {
2553+
acks: vec![event_res.ack_id],
2554+
})
2555+
.unwrap();
2556+
2557+
let res = reqwest::Client::new()
2558+
.post(format!("http://{}/services/collector/ack", address))
2559+
.header("Authorization", format!("Splunk {}", TOKEN))
2560+
.header("x-splunk-request-channel", "guid")
2561+
.header("Content-Type", "application/json; some-random-text; hello")
2562+
.body(body)
2563+
.send()
2564+
.await
2565+
.unwrap();
2566+
2567+
assert_eq!(200, res.status().as_u16());
2568+
2569+
let _parsed: HecAckStatusResponse = res.json().await.unwrap();
2570+
}
2571+
25272572
#[tokio::test]
25282573
async fn event_service_acknowledgements_enabled_channel_required() {
25292574
let message = r#"{"event":"first", "color": "blue"}"#;

0 commit comments

Comments
 (0)