aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-12-10 13:12:20 -0800
committerIvan Frade <ifrade@google.com>2024-12-12 23:23:34 +0000
commitcfb6b625d709c643e8e227b0cce15e650dacacff (patch)
tree65cfdb9799dbb74b2d5041c6e3f15d09922c6040
parente5bb59bc15f09651ffe0fff95dfe5ca5c8470619 (diff)
downloadjgit-cfb6b625d709c643e8e227b0cce15e650dacacff.tar.gz
jgit-cfb6b625d709c643e8e227b0cce15e650dacacff.zip
PushCertificateIdentTest: Add test for the timezone parsing
PushCertificateIdent translates the hhmm in the certificate ident to minutes and then back to hhmm when a timezone is needed. This accepts invalid timezones like +0061 (which becomes +0101 (!)). Add test covering these peculiar timezone translations. This will help when porting the PushCertificateIdent to the new java.time API Change-Id: I008648d4e0c977eb3b3135e548d577680cf5f39c
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateIdentTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateIdentTest.java
index cee023d5a9..6290b7978e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateIdentTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateIdentTest.java
@@ -138,6 +138,51 @@ public class PushCertificateIdentTest {
"Me <me@example.com>");
}
+ @Test
+ public void timezoneRange_hours() {
+ int HOUR_TO_MS = 60 * 60 * 1000;
+
+ // java.util.TimeZone: Hours must be between 0 to 23
+ PushCertificateIdent hourLimit = PushCertificateIdent
+ .parse("A U. Thor <a_u_thor@example.com> 1218123387 +2300");
+ assertEquals(1380, hourLimit.getTimeZoneOffset());
+ assertEquals(23 * HOUR_TO_MS,
+ hourLimit.getTimeZone().getOffset(1218123387));
+
+ PushCertificateIdent hourDubious = PushCertificateIdent
+ .parse("A U. Thor <a_u_thor@example.com> 1218123387 +2400");
+ assertEquals(1440, hourDubious.getTimeZoneOffset());
+ assertEquals(0, hourDubious.getTimeZone().getOffset(1218123387));
+ }
+
+ @Test
+ public void timezoneRange_minutes() {
+ PushCertificateIdent hourLimit = PushCertificateIdent
+ .parse("A U. Thor <a_u_thor@example.com> 1218123387 +0059");
+ assertEquals(59, hourLimit.getTimeZoneOffset());
+ assertEquals(59 * 60 * 1000,
+ hourLimit.getTimeZone().getOffset(1218123387));
+
+ // This becomes one hour and one minute (!)
+ PushCertificateIdent hourDubious = PushCertificateIdent
+ .parse("A U. Thor <a_u_thor@example.com> 1218123387 +0061");
+ assertEquals(61, hourDubious.getTimeZoneOffset());
+ assertEquals(61 * 60 * 1000,
+ hourDubious.getTimeZone().getOffset(1218123387));
+
+ PushCertificateIdent weirdCase = PushCertificateIdent
+ .parse("A U. Thor <a_u_thor@example.com> 1218123387 +0099");
+ assertEquals(99, weirdCase.getTimeZoneOffset());
+ assertEquals(99 * 60 * 1000,
+ weirdCase.getTimeZone().getOffset(1218123387));
+
+ PushCertificateIdent weirdCase2 = PushCertificateIdent
+ .parse("A U. Thor <a_u_thor@example.com> 1218123387 +0199");
+ assertEquals(60 + 99, weirdCase2.getTimeZoneOffset());
+ assertEquals((60 + 99) * 60 * 1000,
+ weirdCase2.getTimeZone().getOffset(1218123387));
+ }
+
private static void assertMatchesPersonIdent(String raw,
PersonIdent expectedPersonIdent, String expectedUserId) {
PushCertificateIdent certIdent = PushCertificateIdent.parse(raw);