core: type auth profile timestamps

This commit is contained in:
a.tolmachev
2026-04-12 22:20:19 +00:00
parent e03d4da925
commit edf318ba67
10 changed files with 90 additions and 42 deletions
+38 -2
View File
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use crate::{
ids::{AuthProfileId, SecretId, WorkspaceId},
@@ -56,6 +57,41 @@ pub struct AuthProfile {
pub name: String,
pub kind: AuthKind,
pub config: AuthConfig,
pub created_at: String,
pub updated_at: String,
#[serde(with = "time::serde::rfc3339")]
pub created_at: OffsetDateTime,
#[serde(with = "time::serde::rfc3339")]
pub updated_at: OffsetDateTime,
}
#[cfg(test)]
mod tests {
use serde_json::json;
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
use super::{ApiKeyHeaderAuthConfig, AuthConfig, AuthProfile};
use crate::{
ids::{AuthProfileId, SecretId, WorkspaceId},
protocol::AuthKind,
};
#[test]
fn auth_profile_serializes_timestamps_as_rfc3339() {
let profile = AuthProfile {
id: AuthProfileId::new("auth_01"),
workspace_id: WorkspaceId::new("ws_default"),
name: "header".to_owned(),
kind: AuthKind::ApiKeyHeader,
config: AuthConfig::ApiKeyHeader(ApiKeyHeaderAuthConfig {
header_name: "X-Api-Key".to_owned(),
secret_id: SecretId::new("secret_01"),
}),
created_at: OffsetDateTime::parse("2026-03-25T12:00:00Z", &Rfc3339).unwrap(),
updated_at: OffsetDateTime::parse("2026-03-25T12:05:00Z", &Rfc3339).unwrap(),
};
let value = serde_json::to_value(&profile).unwrap();
assert_eq!(value["created_at"], json!("2026-03-25T12:00:00Z"));
assert_eq!(value["updated_at"], json!("2026-03-25T12:05:00Z"));
}
}
+7 -2
View File
@@ -264,6 +264,7 @@ mod tests {
use std::collections::BTreeMap;
use serde_json::json;
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
use crate::{
auth::{AuthConfig, AuthProfile, BearerAuthConfig},
@@ -280,6 +281,10 @@ mod tests {
},
};
fn timestamp(value: &str) -> OffsetDateTime {
OffsetDateTime::parse(value, &Rfc3339).unwrap()
}
#[test]
fn rest_target_serializes_with_kind_tag() {
let target = Target::Rest(RestTarget {
@@ -440,8 +445,8 @@ mod tests {
header_name: "Authorization".to_owned(),
secret_id: crate::ids::SecretId::new("secret_crm_prod_token"),
}),
created_at: "2026-03-25T08:00:00Z".to_owned(),
updated_at: "2026-03-25T08:00:00Z".to_owned(),
created_at: timestamp("2026-03-25T08:00:00Z"),
updated_at: timestamp("2026-03-25T08:00:00Z"),
};
let value = serde_json::to_value(profile).unwrap();