Skip to content

Commit

Permalink
fix TSA SuspendTenant rules always set duration to 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
wez committed Sep 18, 2024
1 parent b6a73f0 commit 12b3ae5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
anyhow = "1.0"
axum = {workspace=true}
axum-server = {workspace=true}
chrono = {version="0.4", default-features=false, features=["std", "clock"]}
futures-lite = "2.3"
k9 = "0.12"
kumo-api-types = {path="../kumo-api-types"}
Expand Down
10 changes: 10 additions & 0 deletions crates/integration-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn main() {
mod test {
use super::kumod::*;
use anyhow::Context;
use chrono::Utc;
use k9::assert_equal;
use kumo_api_types::{SuspendReadyQueueV1ListEntry, SuspendV1ListEntry, SuspendV1Response};
use kumo_log_types::RecordType;
Expand Down Expand Up @@ -1278,6 +1279,11 @@ DeliverySummary {
assert_eq!(status[0].name, "unspecified->localhost@smtp_client");
let reason = &status[0].reason;
assert!(reason.contains("you said"), "{reason}");
let remaining = status[0].expires - Utc::now();
assert!(
remaining.num_minutes() > 50,
"expiration should be about an hour remaining, {remaining:?}"
);

daemon.stop().await?;
Ok(())
Expand Down Expand Up @@ -1352,6 +1358,10 @@ DeliverySummary {
assert!(reason.contains("you said"), "{reason}");
assert_eq!(item.campaign.as_deref(), Some("mycamp"));
assert_eq!(item.tenant.as_deref(), Some("mytenant"));
assert!(
item.duration.as_secs() > 50 * 60,
"expiration should be about an hour remaining, {item:?}"
);

daemon.stop().await?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/kcli/src/suspend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl SuspendCommand {
tenant: self.tenant.clone(),
reason: self.reason.clone(),
duration: self.duration.clone(),
expires: None,
},
)
.await?;
Expand Down
10 changes: 9 additions & 1 deletion crates/kumo-api-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,19 @@ pub struct SuspendV1Request {
skip_serializing_if = "Option::is_none"
)]
pub duration: Option<Duration>,

/// instead of specifying the duration, you can set an explicit
/// expiration timestamp
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires: Option<DateTime<Utc>>,
}

impl SuspendV1Request {
pub fn duration(&self) -> Duration {
self.duration.unwrap_or_else(default_duration)
match &self.expires {
Some(exp) => (*exp - Utc::now()).to_std().unwrap_or(Duration::ZERO),
None => self.duration.unwrap_or_else(default_duration),
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions docs/changelog/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@
the domain name internally, and in the case of domains with no explicit MX
records, the fallback record that was synthesized from the domain name would
also be encoded in the unicode representation.

* TSA SuspendTenant rules didn't respect the duration specified in the rule,
instead defaulting to 5 minutes.
10 changes: 9 additions & 1 deletion docs/reference/kumod.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": {
"name": "Apache-2.0"
},
"version": "2024.09.12-e7ec3be8"
"version": "2024.09.17-b6a73f08"
},
"paths": {
"/api/admin/bounce/v1": {
Expand Down Expand Up @@ -1060,6 +1060,14 @@
"description": "Specifies how long this suspension remains active.",
"nullable": true
},
"expires": {
"allOf": [
{
"$ref": "#/components/schemas/DateTime"
}
],
"nullable": true
},
"reason": {
"type": "string",
"description": "The reason for the suspension",
Expand Down

0 comments on commit 12b3ae5

Please sign in to comment.