mirror of
https://github.com/mailscope/kumomta.git
synced 2026-09-21 01:05:31 +00:00
add integration test for logging heads to webhook
This commit is contained in:
@@ -26,6 +26,7 @@ kumo.on('init', function()
|
||||
if WEBHOOK_PORT then
|
||||
kumo.configure_log_hook {
|
||||
name = 'webhook',
|
||||
headers = { 'Subject', 'X-*' },
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -13,9 +13,11 @@ mod test {
|
||||
use anyhow::Context;
|
||||
use k9::assert_equal;
|
||||
use kumo_api_types::SuspendV1Response;
|
||||
use kumo_log_types::RecordType;
|
||||
use kumo_log_types::RecordType::{Bounce, Delivery, Reception, TransientFailure};
|
||||
use mailparsing::DecodedBody;
|
||||
use rfc5321::*;
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::Duration;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -823,6 +825,27 @@ Ok(
|
||||
"
|
||||
);
|
||||
|
||||
let mut logged_headers = vec![];
|
||||
for record in daemon.webhook.return_logs() {
|
||||
if record.kind == RecordType::Reception {
|
||||
let ordered_headers: BTreeMap<_, _> = record.headers.into_iter().collect();
|
||||
logged_headers.push(ordered_headers);
|
||||
}
|
||||
}
|
||||
k9::snapshot!(
|
||||
logged_headers,
|
||||
r#"
|
||||
[
|
||||
{
|
||||
"Subject": String("Hello! This is a test"),
|
||||
"x-another": String("Another"),
|
||||
"x-kumoref": String("eyJfQF8iOiJcXF8vIiwicmVjaXBpZW50IjoicmVjaXBAZXhhbXBsZS5jb20ifQ=="),
|
||||
"x-test1": String("Test1"),
|
||||
},
|
||||
]
|
||||
"#
|
||||
);
|
||||
|
||||
let mut messages = daemon.with_maildir.extract_maildir_messages()?;
|
||||
|
||||
assert_equal!(messages.len(), 1);
|
||||
|
||||
@@ -71,6 +71,10 @@ impl WebHookServer {
|
||||
}
|
||||
Ok(counts)
|
||||
}
|
||||
|
||||
pub fn return_logs(&self) -> Vec<JsonLogRecord> {
|
||||
(*self.records.lock().unwrap()).clone()
|
||||
}
|
||||
}
|
||||
|
||||
async fn log_record(
|
||||
|
||||
@@ -39,7 +39,7 @@ pub enum RecordType {
|
||||
Any,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct JsonLogRecord {
|
||||
/// What kind of record this is
|
||||
#[serde(rename = "type")]
|
||||
|
||||
Reference in New Issue
Block a user