aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-12-12 23:23:56 +0000
committerGerrit Code Review <support@gerrithub.io>2024-12-12 23:23:56 +0000
commitcef96317d7ff16d42806780f58f5f2fa835e1688 (patch)
tree3bda574cfb321ce0f150f3a25728b61f9101c867
parentdf7810957c00f3d857c006ff62ea7dd0e5b6fb76 (diff)
parentcfb6b625d709c643e8e227b0cce15e650dacacff (diff)
downloadjgit-cef96317d7ff16d42806780f58f5f2fa835e1688.tar.gz
jgit-cef96317d7ff16d42806780f58f5f2fa835e1688.zip
Merge "PushCertificateIdentTest: Add test for the timezone parsing"
-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);