summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-05-28 11:03:35 +0200
committerJulian Andres Klode <jak@debian.org>2016-11-14 15:10:03 +0100
commit76277d6f6c6cbcec83a52d3b1399061326c7574e (patch)
treef0a9b0bef3cca836a9083fc2dd75aa27c1443e2d /test
parent4ed2a17ab4334f019c00512aa54a162f0bf083c4 (diff)
accept only the expected UTC timezones in date parsing
HTTP/1.1 hardcodes GMT (RFC 7231 §7.1.1.1) and what is good enough for the internet must be good enough for us™ as we reuse the implementation internally to parse (most) dates we encounter in various places like the Release files with their Date and Valid-Until header fields. Implementing a fully timezone aware parser just feels too hard for no effective benefit as it would take 5+ years (= until LTS's are out of fashion) until a repository could use non-UTC dates and expect it to work. Not counting non-apt implementations which might or might not only want to encounter UTC here as well. As a bonus, this eliminates the use of an instance of setlocale in libapt. Closes: 819697 (cherry picked from commit 9febc2b238e1e322dce1f94ecbed46d595893b52)
Diffstat (limited to 'test')
-rwxr-xr-xtest/integration/test-apt-update-ims4
-rw-r--r--test/libapt/strutil_test.cc38
2 files changed, 40 insertions, 2 deletions
diff --git a/test/integration/test-apt-update-ims b/test/integration/test-apt-update-ims
index 5a44911a6..88f479465 100755
--- a/test/integration/test-apt-update-ims
+++ b/test/integration/test-apt-update-ims
@@ -97,9 +97,9 @@ runtest 'warning'
# make the release file old
find aptarchive -name '*Release' -exec sed -i \
- -e "s#^Date: .*\$#Date: $(date -d '-2 weeks' '+%a, %d %b %Y %H:%M:%S %Z')#" \
+ -e "s#^Date: .*\$#Date: $(date -ud '-2 weeks' '+%a, %d %b %Y %H:%M:%S %Z')#" \
-e '/^Valid-Until: / d' -e "/^Date: / a\
-Valid-Until: $(date -d '-1 weeks' '+%a, %d %b %Y %H:%M:%S %Z')" '{}' \;
+Valid-Until: $(date -ud '-1 weeks' '+%a, %d %b %Y %H:%M:%S %Z')" '{}' \;
signreleasefiles
logcurrentarchivedirectory
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc
index 8947aea59..b7ba816ee 100644
--- a/test/libapt/strutil_test.cc
+++ b/test/libapt/strutil_test.cc
@@ -246,3 +246,41 @@ TEST(StrUtilTest,QuoteString)
EXPECT_EQ("%45ltvill%65%2d%45rbach", QuoteString("Eltville-Erbach", "E-Ae"));
EXPECT_EQ("Eltville-Erbach", DeQuoteString(QuoteString("Eltville-Erbach", "")));
}
+
+TEST(StrUtilTest,RFC1123StrToTime)
+{
+ {
+ time_t t;
+ EXPECT_TRUE(RFC1123StrToTime("Sun, 06 Nov 1994 08:49:37 GMT", t));
+ EXPECT_EQ(784111777, t);
+ } {
+ time_t t;
+ EXPECT_TRUE(RFC1123StrToTime("Sun, 06 Nov 1994 08:49:37 UTC", t));
+ EXPECT_EQ(784111777, t);
+ } {
+ time_t t;
+ EXPECT_TRUE(RFC1123StrToTime("Sun, 06 Nov 1994 08:49:37 -0000", t));
+ EXPECT_EQ(784111777, t);
+ } {
+ time_t t;
+ EXPECT_TRUE(RFC1123StrToTime("Sun, 06 Nov 1994 08:49:37 +0000", t));
+ EXPECT_EQ(784111777, t);
+ } {
+ time_t t;
+ EXPECT_TRUE(RFC1123StrToTime("Sunday, 06-Nov-94 08:49:37 GMT", t));
+ EXPECT_EQ(784111777, t);
+ } {
+ time_t t;
+ EXPECT_TRUE(RFC1123StrToTime("Sun Nov 6 08:49:37 1994", t));
+ EXPECT_EQ(784111777, t);
+ }
+ time_t t;
+ EXPECT_FALSE(RFC1123StrToTime("Sun, 06 Nov 1994 08:49:37", t));
+ EXPECT_FALSE(RFC1123StrToTime("Sun, 06 Nov 1994 GMT", t));
+ EXPECT_FALSE(RFC1123StrToTime("Sonntag, 06 Nov 1994 08:49:37 GMT", t));
+ EXPECT_FALSE(RFC1123StrToTime("domingo Nov 6 08:49:37 1994", t));
+ EXPECT_FALSE(RFC1123StrToTime("Sunday, 06-Nov-94 08:49:37 GMT+1", t));
+ EXPECT_FALSE(RFC1123StrToTime("Sunday, 06-Nov-94 08:49:37 EDT", t));
+ EXPECT_FALSE(RFC1123StrToTime("Sunday, 06-Nov-94 08:49:37 -0100", t));
+ EXPECT_FALSE(RFC1123StrToTime("Sunday, 06-Nov-94 08:49:37 -0.1", t));
+}