all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/2] s3-client: add regression tests for http date header parsing
Date: Fri,  8 Aug 2025 13:41:17 +0200	[thread overview]
Message-ID: <20250808114117.393536-3-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250808114117.393536-1-c.ebner@proxmox.com>

Basic tests to check that the header is parsed as expected if present
and ignored if not.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 proxmox-s3-client/src/response_reader.rs | 24 ++++++++++++++++++++++++
 proxmox-s3-client/src/timestamps.rs      |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/proxmox-s3-client/src/response_reader.rs b/proxmox-s3-client/src/response_reader.rs
index f200e15a..c00c7bd4 100644
--- a/proxmox-s3-client/src/response_reader.rs
+++ b/proxmox-s3-client/src/response_reader.rs
@@ -632,3 +632,27 @@ fn parse_list_buckets_response_test() {
         ]
     );
 }
+
+#[test]
+fn test_optional_date_header_parsing() {
+    let mut header_map = HeaderMap::new();
+
+    let expected_date = "Wed, 12 Oct 2009 17:50:00 GMT";
+    header_map.insert(header::DATE, expected_date.parse().unwrap());
+    let parsed_date = ResponseReader::parse_optional_date_header(&header_map).unwrap();
+    assert!(parsed_date.is_some());
+    assert_eq!(
+        parsed_date.unwrap(),
+        HttpDate::from_str(expected_date).unwrap(),
+    );
+
+    header_map.clear();
+    let invalid_date_format = "2019-11-10";
+    header_map.insert(header::DATE, invalid_date_format.parse().unwrap());
+    assert!(ResponseReader::parse_optional_date_header(&header_map).is_err());
+
+    header_map.clear();
+    assert!(ResponseReader::parse_optional_date_header(&header_map)
+        .unwrap()
+        .is_none());
+}
diff --git a/proxmox-s3-client/src/timestamps.rs b/proxmox-s3-client/src/timestamps.rs
index 661e1fdf..74397593 100644
--- a/proxmox-s3-client/src/timestamps.rs
+++ b/proxmox-s3-client/src/timestamps.rs
@@ -28,7 +28,7 @@ serde_plain::derive_deserialize_from_fromstr!(LastModifiedTimestamp, "last modif
 /// https://datatracker.ietf.org/doc/html/rfc2616#section-3.3
 /// https://datatracker.ietf.org/doc/html/rfc1123#section-5.2.14
 /// https://datatracker.ietf.org/doc/html/rfc822#section-5
-#[derive(Debug)]
+#[derive(Debug, PartialEq)]
 pub struct HttpDate {
     _epoch: i64,
 }
-- 
2.47.2



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2025-08-08 11:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 11:41 [pbs-devel] [PATCH proxmox 0/2] fix non-optional date header for S3 api response parsing Christian Ebner
2025-08-08 11:41 ` [pbs-devel] [PATCH proxmox 1/2] s3-client: fix non-optional date header for " Christian Ebner
2025-08-08 11:41 ` Christian Ebner [this message]
2025-08-11 12:30 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] fix non-optional date header for S3 " Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250808114117.393536-3-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal