From b126372448958d7b6dee1ca0ad70ec4fbb52899f Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sun, 27 Dec 2020 02:11:47 +0100 Subject: [PATCH 1/4] Fix errorprone configuration for maven-compiler-plugin with javac See https://errorprone.info/docs/installation. Add new profile jdk8 to enable running errorprone with javac on java 8 and java 11. Remove errorprone configuration from benchmark module, didn't find a way to make it work and this module does not contain any productive code. Change-Id: I6a84195af05e6cea9e7c04ad5cd4c79742e80cb3 Signed-off-by: Matthias Sohn --- org.eclipse.jgit.benchmarks/pom.xml | 40 ++------------ pom.xml | 81 ++++++++++++----------------- 2 files changed, 37 insertions(+), 84 deletions(-) diff --git a/org.eclipse.jgit.benchmarks/pom.xml b/org.eclipse.jgit.benchmarks/pom.xml index 9b5712063..86dd389de 100644 --- a/org.eclipse.jgit.benchmarks/pom.xml +++ b/org.eclipse.jgit.benchmarks/pom.xml @@ -70,47 +70,13 @@ - org.apache.maven.plugins maven-compiler-plugin - 3.8.1 - ${javac.target} - ${javac.target} - ${javac.target} + UTF-8 + 1.8 + 1.8 .apt_generated - - - compile-with-errorprone - compile - - compile - - - javac-with-errorprone - true - - - - - - org.codehaus.plexus - plexus-compiler-javac - 2.8.5 - - - org.codehaus.plexus - plexus-compiler-javac-errorprone - 2.8.5 - - - - com.google.errorprone - error_prone_core - 2.3.4 - - org.apache.maven.plugins diff --git a/pom.xml b/pom.xml index e7d35ff8c..4846aff54 100644 --- a/pom.xml +++ b/pom.xml @@ -814,54 +814,41 @@ UTF-8 1.8 1.8 + + -XDcompilePolicy=simple + -Xplugin:ErrorProne + + + + com.google.errorprone + error_prone_core + 2.4.0 + + + + + + + + + jdk8 + + 1.8 + + + 9+181-r4173-1 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + + -J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar + - - - default-compile - compile - - compile - - - - org/eclipse/jgit/transport/InsecureCipherFactory.java - - - - - compile-with-errorprone - compile - - compile - - - javac-with-errorprone - true - - org/eclipse/jgit/transport/InsecureCipherFactory.java - - - - - - - org.codehaus.plexus - plexus-compiler-javac - ${plexus-compiler-version} - - - org.codehaus.plexus - plexus-compiler-javac-errorprone - ${plexus-compiler-version} - - - - com.google.errorprone - error_prone_core - 2.3.4 - - From 616a88895dfc36fd3c9fea7d010b03e6d2cf8c1d Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Fri, 29 Jan 2021 23:03:44 +0100 Subject: [PATCH 2/4] LFS: handle invalid pointers better Make sure that SmudgeFilter calls LfsPointer.parseLfsPointer() with a stream that supports mark/reset, and make sure that parseLfsPointer() resets the stream properly if it decides that the stream content is not a LFS pointer. Add a test. Bug: 570758 Change-Id: I2593d67cff31b2dfdfaaa48e437331f0ed877915 Signed-off-by: Thomas Wolf --- .../META-INF/MANIFEST.MF | 4 +- .../tst/org/eclipse/jgit/lfs/LfsGitTest.java | 141 +++++++++++++++ .../org/eclipse/jgit/lfs/LfsBlobFilter.java | 4 +- .../src/org/eclipse/jgit/lfs/LfsPointer.java | 166 +++++++++++++----- .../org/eclipse/jgit/lfs/SmudgeFilter.java | 20 ++- .../jgit/lfs/lib/LfsPointerFilter.java | 4 +- 6 files changed, 289 insertions(+), 50 deletions(-) create mode 100644 org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java diff --git a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF index b4c892ed9..419c4ca50 100644 --- a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF @@ -7,7 +7,9 @@ Bundle-Version: 5.11.0.qualifier Bundle-Vendor: %Bundle-Vendor Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: org.eclipse.jgit.internal.storage.dfs;version="[5.11.0,5.12.0)", +Import-Package: org.eclipse.jgit.api;version="[5.11.0,5.12.0)", + org.eclipse.jgit.attributes;version="[5.11.0,5.12.0)", + org.eclipse.jgit.internal.storage.dfs;version="[5.11.0,5.12.0)", org.eclipse.jgit.junit;version="[5.11.0,5.12.0)", org.eclipse.jgit.lfs;version="[5.11.0,5.12.0)", org.eclipse.jgit.lfs.errors;version="[5.11.0,5.12.0)", diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java new file mode 100644 index 000000000..8964310e4 --- /dev/null +++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/LfsGitTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2021, Thomas Wolf and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.lfs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.ResetCommand.ResetType; +import org.eclipse.jgit.attributes.FilterCommandRegistry; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lfs.lib.Constants; +import org.eclipse.jgit.lib.StoredConfig; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LfsGitTest extends RepositoryTestCase { + + private static final String SMUDGE_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX + + Constants.ATTR_FILTER_DRIVER_PREFIX + + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_SMUDGE; + + private static final String CLEAN_NAME = org.eclipse.jgit.lib.Constants.BUILTIN_FILTER_PREFIX + + Constants.ATTR_FILTER_DRIVER_PREFIX + + org.eclipse.jgit.lib.Constants.ATTR_FILTER_TYPE_CLEAN; + + @BeforeClass + public static void installLfs() { + FilterCommandRegistry.register(SMUDGE_NAME, SmudgeFilter.FACTORY); + FilterCommandRegistry.register(CLEAN_NAME, CleanFilter.FACTORY); + } + + @AfterClass + public static void removeLfs() { + FilterCommandRegistry.unregister(SMUDGE_NAME); + FilterCommandRegistry.unregister(CLEAN_NAME); + } + + private Git git; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + git = new Git(db); + // commit something + writeTrashFile("Test.txt", "Hello world"); + git.add().addFilepattern("Test.txt").call(); + git.commit().setMessage("Initial commit").call(); + // prepare the config for LFS + StoredConfig config = git.getRepository().getConfig(); + config.setString("filter", "lfs", "clean", CLEAN_NAME); + config.setString("filter", "lfs", "smudge", SMUDGE_NAME); + config.save(); + } + + @Test + public void checkoutNonLfsPointer() throws Exception { + String content = "size_t\nsome_function(void* ptr);\n"; + File smallFile = writeTrashFile("Test.txt", content); + StringBuilder largeContent = new StringBuilder( + LfsPointer.SIZE_THRESHOLD * 4); + while (largeContent.length() < LfsPointer.SIZE_THRESHOLD * 4) { + largeContent.append(content); + } + File largeFile = writeTrashFile("large.txt", largeContent.toString()); + fsTick(largeFile); + git.add().addFilepattern("Test.txt").addFilepattern("large.txt").call(); + git.commit().setMessage("Text files").call(); + writeTrashFile(".gitattributes", "*.txt filter=lfs"); + git.add().addFilepattern(".gitattributes").call(); + git.commit().setMessage("attributes").call(); + assertTrue(smallFile.delete()); + assertTrue(largeFile.delete()); + // This reset will run the two text files through the smudge filter + git.reset().setMode(ResetType.HARD).call(); + assertTrue(smallFile.exists()); + assertTrue(largeFile.exists()); + checkFile(smallFile, content); + checkFile(largeFile, largeContent.toString()); + // Modify the large file + largeContent.append(content); + writeTrashFile("large.txt", largeContent.toString()); + // This should convert largeFile to an LFS pointer + git.add().addFilepattern("large.txt").call(); + git.commit().setMessage("Large modified").call(); + String lfsPtr = "version https://git-lfs.github.com/spec/v1\n" + + "oid sha256:d041ab19bd7edd899b3c0450d0f61819f96672f0b22d26c9753abc62e1261614\n" + + "size 858\n"; + assertEquals("[.gitattributes, mode:100644, content:*.txt filter=lfs]" + + "[Test.txt, mode:100644, content:" + content + ']' + + "[large.txt, mode:100644, content:" + lfsPtr + ']', + indexState(CONTENT)); + // Verify the file has been saved + File savedFile = new File(db.getDirectory(), "lfs"); + savedFile = new File(savedFile, "objects"); + savedFile = new File(savedFile, "d0"); + savedFile = new File(savedFile, "41"); + savedFile = new File(savedFile, + "d041ab19bd7edd899b3c0450d0f61819f96672f0b22d26c9753abc62e1261614"); + String saved = new String(Files.readAllBytes(savedFile.toPath()), + StandardCharsets.UTF_8); + assertEquals(saved, largeContent.toString()); + + assertTrue(smallFile.delete()); + assertTrue(largeFile.delete()); + git.reset().setMode(ResetType.HARD).call(); + assertTrue(smallFile.exists()); + assertTrue(largeFile.exists()); + checkFile(smallFile, content); + checkFile(largeFile, largeContent.toString()); + assertEquals("[.gitattributes, mode:100644, content:*.txt filter=lfs]" + + "[Test.txt, mode:100644, content:" + content + ']' + + "[large.txt, mode:100644, content:" + lfsPtr + ']', + indexState(CONTENT)); + git.add().addFilepattern("Test.txt").call(); + git.commit().setMessage("Small committed again").call(); + String lfsPtrSmall = "version https://git-lfs.github.com/spec/v1\n" + + "oid sha256:9110463275fb0e2f0e9fdeaf84e598e62915666161145cf08927079119cc7814\n" + + "size 33\n"; + assertEquals("[.gitattributes, mode:100644, content:*.txt filter=lfs]" + + "[Test.txt, mode:100644, content:" + lfsPtrSmall + ']' + + "[large.txt, mode:100644, content:" + lfsPtr + ']', + indexState(CONTENT)); + + assertTrue(git.status().call().isClean()); + } +} diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsBlobFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsBlobFilter.java index 52c3001b8..032a19b5d 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsBlobFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsBlobFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017, Markus Duft and others + * Copyright (C) 2017, 2021 Markus Duft and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -45,7 +45,7 @@ public class LfsBlobFilter { */ public static ObjectLoader smudgeLfsBlob(Repository db, ObjectLoader loader) throws IOException { - if (loader.getSize() > LfsPointer.SIZE_THRESHOLD) { + if (loader.getSize() > LfsPointer.FULL_SIZE_THRESHOLD) { return loader; } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java index aef441638..0a8a3faec 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java @@ -11,7 +11,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; +import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -25,6 +27,7 @@ import org.eclipse.jgit.lfs.lib.AnyLongObjectId; import org.eclipse.jgit.lfs.lib.Constants; import org.eclipse.jgit.lfs.lib.LongObjectId; +import org.eclipse.jgit.util.IO; /** * Represents an LFS pointer file @@ -57,6 +60,12 @@ public class LfsPointer implements Comparable { public static final String HASH_FUNCTION_NAME = Constants.LONG_HASH_FUNCTION .toLowerCase(Locale.ROOT).replace("-", ""); //$NON-NLS-1$ //$NON-NLS-2$ + /** + * {@link #SIZE_THRESHOLD} is too low; with lfs extensions a LFS pointer can + * be larger. But 8kB should be more than enough. + */ + static final int FULL_SIZE_THRESHOLD = 8 * 1024; + private final AnyLongObjectId oid; private final long size; @@ -115,64 +124,113 @@ public void encode(OutputStream out) { /** * Try to parse the data provided by an InputStream to the format defined by - * {@link #VERSION} + * {@link #VERSION}. If the given stream supports mark and reset as + * indicated by {@link InputStream#markSupported()}, its input position will + * be reset if the stream content is not actually a LFS pointer (i.e., when + * {@code null} is returned). If the stream content is an invalid LFS + * pointer or the given stream does not support mark/reset, the input + * position may not be reset. * * @param in * the {@link java.io.InputStream} from where to read the data - * @return an {@link org.eclipse.jgit.lfs.LfsPointer} or null - * if the stream was not parseable as LfsPointer + * @return an {@link org.eclipse.jgit.lfs.LfsPointer} or {@code null} if the + * stream was not parseable as LfsPointer * @throws java.io.IOException */ @Nullable public static LfsPointer parseLfsPointer(InputStream in) throws IOException { + if (in.markSupported()) { + return parse(in); + } + // Fallback; note that while parse() resets its input stream, that won't + // reset "in". + return parse(new BufferedInputStream(in)); + } + + @Nullable + private static LfsPointer parse(InputStream in) + throws IOException { + if (!in.markSupported()) { + // No translation; internal error + throw new IllegalArgumentException( + "LFS pointer parsing needs InputStream.markSupported() == true"); //$NON-NLS-1$ + } + // Try reading only a short block first. + in.mark(SIZE_THRESHOLD); + byte[] preamble = new byte[SIZE_THRESHOLD]; + int length = IO.readFully(in, preamble, 0); + if (length < preamble.length || in.read() < 0) { + // We have the whole file. Try to parse a pointer from it. + try (BufferedReader r = new BufferedReader(new InputStreamReader( + new ByteArrayInputStream(preamble, 0, length), UTF_8))) { + LfsPointer ptr = parse(r); + if (ptr == null) { + in.reset(); + } + return ptr; + } + } + // Longer than SIZE_THRESHOLD: expect "version" to be the first line. + boolean hasVersion = checkVersion(preamble); + in.reset(); + if (!hasVersion) { + return null; + } + in.mark(FULL_SIZE_THRESHOLD); + byte[] fullPointer = new byte[FULL_SIZE_THRESHOLD]; + length = IO.readFully(in, fullPointer, 0); + if (length == fullPointer.length && in.read() >= 0) { + in.reset(); + return null; // Too long. + } + try (BufferedReader r = new BufferedReader(new InputStreamReader( + new ByteArrayInputStream(fullPointer, 0, length), UTF_8))) { + LfsPointer ptr = parse(r); + if (ptr == null) { + in.reset(); + } + return ptr; + } + } + + private static LfsPointer parse(BufferedReader r) throws IOException { boolean versionLine = false; LongObjectId id = null; long sz = -1; - // This parsing is a bit too general if we go by the spec at // https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md - // Comment lines are not mentioned in the spec, and the "version" line - // MUST be the first. - try (BufferedReader br = new BufferedReader( - new InputStreamReader(in, UTF_8))) { - for (String s = br.readLine(); s != null; s = br.readLine()) { - if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$ - continue; - } else if (s.startsWith("version")) { //$NON-NLS-1$ - if (versionLine || s.length() < 8 || s.charAt(7) != ' ') { - return null; // Not a LFS pointer - } - String rest = s.substring(8).trim(); - versionLine = VERSION.equals(rest) - || VERSION_LEGACY.equals(rest); - if (!versionLine) { - return null; // Not a LFS pointer - } - } else { - try { - if (s.startsWith("oid sha256:")) { //$NON-NLS-1$ - if (id != null) { - return null; // Not a LFS pointer - } - id = LongObjectId - .fromString(s.substring(11).trim()); - } else if (s.startsWith("size")) { //$NON-NLS-1$ - if (sz > 0 || s.length() < 5 - || s.charAt(4) != ' ') { - return null; // Not a LFS pointer - } - sz = Long.parseLong(s.substring(5).trim()); + // Comment lines are not mentioned in the spec, the "version" line + // MUST be the first, and keys are ordered alphabetically. + for (String s = r.readLine(); s != null; s = r.readLine()) { + if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$ + continue; + } else if (s.startsWith("version")) { //$NON-NLS-1$ + if (versionLine || !checkVersionLine(s)) { + return null; // Not a LFS pointer + } + versionLine = true; + } else { + try { + if (s.startsWith("oid sha256:")) { //$NON-NLS-1$ + if (id != null) { + return null; // Not a LFS pointer } - } catch (RuntimeException e) { - // We could not parse the line. If we have a version - // already, this is a corrupt LFS pointer. Otherwise it - // is just not an LFS pointer. - if (versionLine) { - throw e; + id = LongObjectId.fromString(s.substring(11).trim()); + } else if (s.startsWith("size")) { //$NON-NLS-1$ + if (sz > 0 || s.length() < 5 || s.charAt(4) != ' ') { + return null; // Not a LFS pointer } - return null; + sz = Long.parseLong(s.substring(5).trim()); } + } catch (RuntimeException e) { + // We could not parse the line. If we have a version + // already, this is a corrupt LFS pointer. Otherwise it + // is just not an LFS pointer. + if (versionLine) { + throw e; + } + return null; } } if (versionLine && id != null && sz > -1) { @@ -182,6 +240,30 @@ public static LfsPointer parseLfsPointer(InputStream in) return null; } + private static boolean checkVersion(byte[] data) { + // According to the spec at + // https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md + // it MUST always be the first line. + try (BufferedReader r = new BufferedReader( + new InputStreamReader(new ByteArrayInputStream(data), UTF_8))) { + String s = r.readLine(); + if (s != null && s.startsWith("version")) { //$NON-NLS-1$ + return checkVersionLine(s); + } + } catch (IOException e) { + // Doesn't occur, we're reading from a byte array! + } + return false; + } + + private static boolean checkVersionLine(String s) { + if (s.length() < 8 || s.charAt(7) != ' ') { + return false; // Not a valid LFS pointer version line + } + String rest = s.substring(8).trim(); + return VERSION.equals(rest) || VERSION_LEGACY.equals(rest); + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java index 2f80d5b9a..341188756 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, Christian Halstrick and others + * Copyright (C) 2016, 2021 Christian Halstrick and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -11,6 +11,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; +import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -87,20 +88,31 @@ static void register() { */ public SmudgeFilter(Repository db, InputStream in, OutputStream out) throws IOException { + this(in.markSupported() ? in : new BufferedInputStream(in), out, db); + } + + private SmudgeFilter(InputStream in, OutputStream out, Repository db) + throws IOException { super(in, out); + InputStream from = in; try { - Lfs lfs = new Lfs(db); - LfsPointer res = LfsPointer.parseLfsPointer(in); + LfsPointer res = LfsPointer.parseLfsPointer(from); if (res != null) { AnyLongObjectId oid = res.getOid(); + Lfs lfs = new Lfs(db); Path mediaFile = lfs.getMediaFile(oid); if (!Files.exists(mediaFile)) { downloadLfsResource(lfs, db, res); } this.in = Files.newInputStream(mediaFile); + } else { + // Not swapped; stream was reset, don't close! + from = null; } } finally { - in.close(); // make sure the swapped stream is closed properly. + if (from != null) { + from.close(); // Close the swapped-out stream + } } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LfsPointerFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LfsPointerFilter.java index d84eebd22..99bae49ab 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LfsPointerFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LfsPointerFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, 2017, Dariusz Luksza and others + * Copyright (C) 2015, 2021 Dariusz Luksza and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -58,6 +58,8 @@ public boolean include(TreeWalk walk) throws MissingObjectException, try (ObjectStream stream = object.openStream()) { pointer = LfsPointer.parseLfsPointer(stream); return pointer != null; + } catch (RuntimeException e) { + return false; } } From a534d3d90a470896db5dd7c3d9a9dc0d0ec1331a Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 1 Mar 2021 22:10:22 +0100 Subject: [PATCH 3/4] Update Orbit to S20210223232630 Change-Id: Ida7a54cfe0bd15c1c28b892dea3452958924f0c0 Signed-off-by: Matthias Sohn --- .../org.eclipse.jgit.target/jgit-4.10.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.10.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.11.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.11.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.12.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.12.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.13.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.13.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.14.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.14.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.15.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.15.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.16.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.16.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.17.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.17.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.18.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.18.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.19-staging.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.19-staging.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.6.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.6.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.7.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.7.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.8.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.8.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.9.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.9.tpd | 2 +- .../orbit/{S20210216215844.tpd => S20210223232630.tpd} | 4 ++-- 29 files changed, 44 insertions(+), 44 deletions(-) rename org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/{S20210216215844.tpd => S20210223232630.tpd} (98%) diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target index 68378a2b0..a9ad22b42 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd index fb1ac6b25..db08bcbb7 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd @@ -1,7 +1,7 @@ target "jgit-4.10" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2018-12/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target index 18d525d8e..3177ed772 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd index 0d5628063..b4b24f4e4 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd @@ -1,7 +1,7 @@ target "jgit-4.11" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2019-03/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target index d72f08d29..ea37cc50e 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd index 5a024152d..342606ec6 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd @@ -1,7 +1,7 @@ target "jgit-4.12" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2019-06/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target index d0e559271..a809f2ba8 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd index 84e5c25ef..3244a169f 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd @@ -1,7 +1,7 @@ target "jgit-4.13" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2019-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.target index 42278f6ef..dde971e91 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.tpd index 6d793a607..26f0a9cde 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14.tpd @@ -1,7 +1,7 @@ target "jgit-4.14" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2019-12/201912181000/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.target index 0d5166e16..348cc5856 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.tpd index 4ce832bf9..5a47a9e9f 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.15.tpd @@ -1,7 +1,7 @@ target "jgit-4.15" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2020-03/202003181000/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.target index b4d53069b..4eae86780 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.tpd index 1b56447ce..646e1a033 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.16.tpd @@ -1,7 +1,7 @@ target "jgit-4.16" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2020-06/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target index 47fc74be6..cfb4dcc15 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd index 367020ce0..99e7b5913 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.17.tpd @@ -1,7 +1,7 @@ target "jgit-4.17" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2020-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target index b393e6075..67a07e306 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd index 507ddd1dc..4ec08d73d 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.18.tpd @@ -1,7 +1,7 @@ target "jgit-4.18" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2020-12/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.target index f37692616..8b27678d8 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.tpd index 3b1b19c84..46f96ad6b 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.19-staging.tpd @@ -1,7 +1,7 @@ target "jgit-4.19-staging" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/staging/2021-03/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target index 26715ee18..bd2a6309e 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd index 23bf87c07..e8d5c4aea 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd @@ -1,7 +1,7 @@ target "jgit-4.6" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/neon/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target index 64fe05495..a01c7f3f7 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd index c33e4a39b..db20e40f7 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd @@ -1,7 +1,7 @@ target "jgit-4.7" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/oxygen/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target index f7a3a3b26..e3f61fb16 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd index c40bacdb8..30e6a0136 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd @@ -1,7 +1,7 @@ target "jgit-4.8" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/photon/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target index 4afbe9973..2cfcf5c7e 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target @@ -1,7 +1,7 @@ - + @@ -86,7 +86,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd index 5aa63be64..f9fab982c 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd @@ -1,7 +1,7 @@ target "jgit-4.9" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/S20210216215844.tpd" +include "orbit/S20210223232630.tpd" location "https://download.eclipse.org/releases/2018-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20210216215844.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20210223232630.tpd similarity index 98% rename from org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20210216215844.tpd rename to org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20210223232630.tpd index 29e5bc800..7f5d20b1c 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20210216215844.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20210223232630.tpd @@ -1,7 +1,7 @@ -target "S20210216215844" with source configurePhase +target "S20210223232630" with source configurePhase // see https://download.eclipse.org/tools/orbit/downloads/ -location "https://download.eclipse.org/tools/orbit/downloads/drops/S20210216215844/repository" { +location "https://download.eclipse.org/tools/orbit/downloads/drops/S20210223232630/repository" { com.google.gson [2.8.6.v20201231-1626,2.8.6.v20201231-1626] com.google.gson.source [2.8.6.v20201231-1626,2.8.6.v20201231-1626] com.jcraft.jsch [0.1.55.v20190404-1902,0.1.55.v20190404-1902] From 40d6eda3f16f24db20776d33e586737efeddc725 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Mon, 1 Mar 2021 08:30:09 +0100 Subject: [PATCH 4/4] HTTP: cookie file stores expiration in seconds A cookie file stores the expiration in seconds since the Linux Epoch, not in milliseconds. Correct reading and writing cookie files; with a backwards-compatibility hack to read files that contain a millisecond timestamp. Add a test, and fix tests not to rely on the actual current time so that they will also run successfully after 2030-01-01 noon. Bug: 571574 Change-Id: If3ba68391e574520701cdee119544eedc42a1ff2 Signed-off-by: Thomas Wolf --- .../transport/http/cookies-simple1.txt | 4 +- .../transport/http/cookies-simple2.txt | 4 +- .../cookies-with-empty-and-comment-lines.txt | 4 +- .../http/cookies-with-milliseconds.txt | 2 + .../http/NetscapeCookieFileTest.java | 109 +++++++++--------- .../transport/http/NetscapeCookieFile.java | 54 +++++---- 6 files changed, 90 insertions(+), 87 deletions(-) create mode 100644 org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-milliseconds.txt diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt index e06b38c71..527893acf 100644 --- a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt @@ -1,2 +1,2 @@ -some-domain1 TRUE /some/path1 FALSE 1893499200000 key1 valueFromSimple1 -some-domain1 TRUE /some/path1 FALSE 1893499200000 key2 valueFromSimple1 \ No newline at end of file +some-domain1 TRUE /some/path1 FALSE 1893499200 key1 valueFromSimple1 +some-domain1 TRUE /some/path1 FALSE 1893499200 key2 valueFromSimple1 \ No newline at end of file diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt index 4bf6723fd..5ec060627 100644 --- a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt @@ -1,2 +1,2 @@ -some-domain1 TRUE /some/path1 FALSE 1893499200000 key1 valueFromSimple2 -some-domain1 TRUE /some/path1 FALSE 1893499200000 key3 valueFromSimple2 \ No newline at end of file +some-domain1 TRUE /some/path1 FALSE 1893499200 key1 valueFromSimple2 +some-domain1 TRUE /some/path1 FALSE 1893499200 key3 valueFromSimple2 \ No newline at end of file diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt index a9b8a2815..573ee9ee1 100644 --- a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt @@ -3,6 +3,6 @@ some-domain1 TRUE /some/path1 FALSE 0 key1 value1 # expires date is 01/01/2030 @ 12:00am (UTC) -#HttpOnly_.some-domain2 TRUE /some/path2 TRUE 1893499200000 key2 value2 +#HttpOnly_.some-domain2 TRUE /some/path2 TRUE 1893499200 key2 value2 -some-domain3 TRUE /some/path3 FALSE 1893499200000 key3 value3 \ No newline at end of file +some-domain3 TRUE /some/path3 FALSE 1893499200 key3 value3 \ No newline at end of file diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-milliseconds.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-milliseconds.txt new file mode 100644 index 000000000..940e3b1a5 --- /dev/null +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-milliseconds.txt @@ -0,0 +1,2 @@ +some-domain1 TRUE /some/path1 FALSE 1893499200000 key1 valueFromSimple1 +some-domain1 TRUE /some/path1 FALSE 1893499200 key2 valueFromSimple1 \ No newline at end of file diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java index 6c8c3ba61..b11dd637f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java @@ -22,13 +22,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.time.Duration; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Arrays; -import java.util.Date; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.regex.Pattern; import org.eclipse.jgit.internal.storage.file.LockFile; import org.eclipse.jgit.util.http.HttpCookiesMatcher; @@ -48,10 +48,14 @@ public class NetscapeCookieFileTest { private URL baseUrl; /** - * This is the expiration date that is used in the test cookie files + * This is the expiration date that is used in the test cookie files. */ - private static long JAN_01_2030_NOON = Instant - .parse("2030-01-01T12:00:00.000Z").toEpochMilli(); + private static final Instant TEST_EXPIRY_DATE = Instant + .parse("2030-01-01T12:00:00.000Z"); + + /** Earlier than TEST_EXPIRY_DATE. */ + private static final Instant TEST_DATE = TEST_EXPIRY_DATE.minus(180, + ChronoUnit.DAYS); @Before public void setUp() throws IOException { @@ -102,14 +106,13 @@ public void testWriteToNewFile() throws IOException { cookie.setPath("/"); cookie.setMaxAge(1000); cookies.add(cookie); - Date creationDate = new Date(); try (Writer writer = Files.newBufferedWriter(tmpFile, StandardCharsets.US_ASCII)) { - NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate); + NetscapeCookieFile.write(writer, cookies, baseUrl, TEST_DATE); } String expectedExpiration = String - .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000)); + .valueOf(TEST_DATE.getEpochSecond() + cookie.getMaxAge()); assertThat(Files.readAllLines(tmpFile, StandardCharsets.US_ASCII), CoreMatchers @@ -128,13 +131,12 @@ public void testWriteToExistingFile() throws IOException { HttpCookie cookie = new HttpCookie("key2", "value2"); cookie.setMaxAge(1000); cookies.add(cookie); - Date creationDate = new Date(); try (Writer writer = Files.newBufferedWriter(tmpFile, StandardCharsets.US_ASCII)) { - NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate); + NetscapeCookieFile.write(writer, cookies, baseUrl, TEST_DATE); } String expectedExpiration = String - .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000)); + .valueOf(TEST_DATE.getEpochSecond() + cookie.getMaxAge()); assertThat(Files.readAllLines(tmpFile, StandardCharsets.US_ASCII), CoreMatchers.equalTo( @@ -160,6 +162,21 @@ public void testWriteWhileSomeoneIsHoldingTheLock() } } + @Test + public void testReadCookieFileWithMilliseconds() throws IOException { + try (InputStream input = this.getClass() + .getResourceAsStream("cookies-with-milliseconds.txt")) { + Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING); + } + NetscapeCookieFile cookieFile = new NetscapeCookieFile(tmpFile, + TEST_DATE); + long expectedMaxAge = Duration.between(TEST_DATE, TEST_EXPIRY_DATE) + .getSeconds(); + for (HttpCookie cookie : cookieFile.getCookies(true)) { + assertEquals(expectedMaxAge, cookie.getMaxAge()); + } + } + @Test public void testWriteAfterAnotherJgitProcessModifiedTheFile() throws IOException, InterruptedException { @@ -167,7 +184,8 @@ public void testWriteAfterAnotherJgitProcessModifiedTheFile() .getResourceAsStream("cookies-simple1.txt")) { Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING); } - NetscapeCookieFile cookieFile = new NetscapeCookieFile(tmpFile); + NetscapeCookieFile cookieFile = new NetscapeCookieFile(tmpFile, + TEST_DATE); cookieFile.getCookies(true); // now modify file externally try (InputStream input = this.getClass() @@ -177,39 +195,19 @@ public void testWriteAfterAnotherJgitProcessModifiedTheFile() // now try to write cookieFile.write(baseUrl); - // validate that the external changes are there as well - // due to rounding errors (conversion from ms to sec to ms) - // the expiration date might not be exact List lines = Files.readAllLines(tmpFile, StandardCharsets.US_ASCII); assertEquals("Expected 3 lines", 3, lines.size()); - assertStringMatchesPatternWithInexactNumber(lines.get(0), - "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey1\tvalueFromSimple2", - JAN_01_2030_NOON, 1000); - assertStringMatchesPatternWithInexactNumber(lines.get(1), - "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey3\tvalueFromSimple2", - JAN_01_2030_NOON, 1000); - assertStringMatchesPatternWithInexactNumber(lines.get(2), - "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey2\tvalueFromSimple1", - JAN_01_2030_NOON, 1000); - } - - @SuppressWarnings("boxing") - private static final void assertStringMatchesPatternWithInexactNumber( - String string, String pattern, long expectedNumericValue, - long delta) { - java.util.regex.Matcher matcher = Pattern.compile(pattern) - .matcher(string); - assertTrue("Given string '" + string + "' does not match '" + pattern - + "'", matcher.matches()); - // extract numeric value - Long actualNumericValue = Long.decode(matcher.group(1)); - - assertTrue( - "Value is supposed to be close to " + expectedNumericValue - + " but is " + actualNumericValue + ".", - Math.abs(expectedNumericValue - actualNumericValue) <= delta); + assertEquals( + "some-domain1\tTRUE\t/some/path1\tFALSE\t1893499200\tkey1\tvalueFromSimple2", + lines.get(0)); + assertEquals( + "some-domain1\tTRUE\t/some/path1\tFALSE\t1893499200\tkey3\tvalueFromSimple2", + lines.get(1)); + assertEquals( + "some-domain1\tTRUE\t/some/path1\tFALSE\t1893499200\tkey2\tvalueFromSimple1", + lines.get(2)); } @Test @@ -229,14 +227,13 @@ public void testWriteAndReadCycle() throws IOException { cookie.setHttpOnly(true); cookies.add(cookie); - Date creationDate = new Date(); - try (Writer writer = Files.newBufferedWriter(tmpFile, StandardCharsets.US_ASCII)) { - NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate); + NetscapeCookieFile.write(writer, cookies, baseUrl, TEST_DATE); } Set actualCookies = new NetscapeCookieFile(tmpFile, - creationDate).getCookies(true); + TEST_DATE) + .getCookies(true); assertThat(actualCookies, HttpCookiesMatcher.containsInOrder(cookies)); } @@ -246,15 +243,12 @@ public void testReadAndWriteCycle() throws IOException { .getResourceAsStream("cookies-simple1.txt")) { Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING); } - // round up to the next second (to prevent rounding errors) - Date creationDate = new Date( - (System.currentTimeMillis() / 1000) * 1000); - Set cookies = new NetscapeCookieFile(tmpFile, creationDate) + Set cookies = new NetscapeCookieFile(tmpFile, TEST_DATE) .getCookies(true); Path tmpFile2 = folder.newFile().toPath(); try (Writer writer = Files.newBufferedWriter(tmpFile2, StandardCharsets.US_ASCII)) { - NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate); + NetscapeCookieFile.write(writer, cookies, baseUrl, TEST_DATE); } // compare original file with newly written one, they should not differ assertEquals(Files.readAllLines(tmpFile), Files.readAllLines(tmpFile2)); @@ -267,13 +261,13 @@ public void testReadWithEmptyAndCommentLines() throws IOException { Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING); } - Date creationDate = new Date(); Set cookies = new LinkedHashSet<>(); HttpCookie cookie = new HttpCookie("key2", "value2"); cookie.setDomain("some-domain2"); cookie.setPath("/some/path2"); - cookie.setMaxAge((JAN_01_2030_NOON - creationDate.getTime()) / 1000); + cookie.setMaxAge( + Duration.between(TEST_DATE, TEST_EXPIRY_DATE).getSeconds()); cookie.setSecure(true); cookie.setHttpOnly(true); cookies.add(cookie); @@ -281,11 +275,12 @@ public void testReadWithEmptyAndCommentLines() throws IOException { cookie = new HttpCookie("key3", "value3"); cookie.setDomain("some-domain3"); cookie.setPath("/some/path3"); - cookie.setMaxAge((JAN_01_2030_NOON - creationDate.getTime()) / 1000); + cookie.setMaxAge( + Duration.between(TEST_DATE, TEST_EXPIRY_DATE).getSeconds()); cookies.add(cookie); - Set actualCookies = new NetscapeCookieFile(tmpFile, creationDate) - .getCookies(true); + Set actualCookies = new NetscapeCookieFile(tmpFile, + TEST_DATE).getCookies(true); assertThat(actualCookies, HttpCookiesMatcher.containsInOrder(cookies)); } @@ -296,7 +291,7 @@ public void testReadInvalidFile() throws IOException { Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING); } - new NetscapeCookieFile(tmpFile) - .getCookies(true); + assertTrue(new NetscapeCookieFile(tmpFile, TEST_DATE).getCookies(true) + .isEmpty()); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/http/NetscapeCookieFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/http/NetscapeCookieFile.java index 49f26c788..dae717305 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/http/NetscapeCookieFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/http/NetscapeCookieFile.java @@ -22,11 +22,12 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.text.MessageFormat; +import java.time.Instant; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.LinkedHashSet; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.annotations.Nullable; @@ -53,6 +54,7 @@ * In general this class is not thread-safe. So any consumer needs to take care * of synchronization! * + * @see Cookie file format * @see Netscape Cookie File * Format * @see cookies = null; @@ -104,13 +106,13 @@ public final class NetscapeCookieFile { * where to find the cookie file */ public NetscapeCookieFile(Path path) { - this(path, new Date()); + this(path, Instant.now()); } - NetscapeCookieFile(Path path, Date creationDate) { + NetscapeCookieFile(Path path, Instant createdAt) { this.path = path; this.snapshot = FileSnapshot.DIRTY; - this.creationDate = creationDate; + this.createdAt = createdAt; } /** @@ -142,7 +144,7 @@ public Set getCookies(boolean refresh) { if (cookies == null || refresh) { try { byte[] in = getFileContentIfModified(); - Set newCookies = parseCookieFile(in, creationDate); + Set newCookies = parseCookieFile(in, createdAt); if (cookies != null) { cookies = mergeCookies(newCookies, cookies); } else { @@ -168,9 +170,9 @@ public Set getCookies(boolean refresh) { * * @param input * the file content to parse - * @param creationDate - * the date for the creation of the cookies (used to calculate - * the maxAge based on the expiration date given within the file) + * @param createdAt + * cookie creation time; used to calculate the maxAge based on + * the expiration date given within the file * @return the set of parsed cookies from the given file (even expired * ones). If there is more than one cookie with the same name in * this file the last one overwrites the first one! @@ -180,7 +182,7 @@ public Set getCookies(boolean refresh) { * if the given file does not have a proper format */ private static Set parseCookieFile(@NonNull byte[] input, - @NonNull Date creationDate) + @NonNull Instant createdAt) throws IOException, IllegalArgumentException { String decoded = RawParseUtils.decode(StandardCharsets.US_ASCII, input); @@ -190,7 +192,7 @@ private static Set parseCookieFile(@NonNull byte[] input, new StringReader(decoded))) { String line; while ((line = reader.readLine()) != null) { - HttpCookie cookie = parseLine(line, creationDate); + HttpCookie cookie = parseLine(line, createdAt); if (cookie != null) { cookies.add(cookie); } @@ -200,7 +202,7 @@ private static Set parseCookieFile(@NonNull byte[] input, } private static HttpCookie parseLine(@NonNull String line, - @NonNull Date creationDate) { + @NonNull Instant createdAt) { if (line.isEmpty() || (line.startsWith("#") //$NON-NLS-1$ && !line.startsWith(HTTP_ONLY_PREAMBLE))) { return null; @@ -236,7 +238,12 @@ private static HttpCookie parseLine(@NonNull String line, cookie.setSecure(Boolean.parseBoolean(cookieLineParts[3])); long expires = Long.parseLong(cookieLineParts[4]); - long maxAge = (expires - creationDate.getTime()) / 1000; + // Older versions stored milliseconds. This heuristic to detect that + // will cause trouble in the year 33658. :-) + if (cookieLineParts[4].length() == 13) { + expires = TimeUnit.MILLISECONDS.toSeconds(expires); + } + long maxAge = expires - createdAt.getEpochSecond(); if (maxAge <= 0) { return null; // skip expired cookies } @@ -245,7 +252,7 @@ private static HttpCookie parseLine(@NonNull String line, } /** - * Read the underying file and return its content but only in case it has + * Read the underlying file and return its content but only in case it has * been modified since the last access. *

* Internally calculates the hash and maintains {@link FileSnapshot}s to @@ -333,7 +340,7 @@ public void write(URL url) throws IOException, InterruptedException { path); // reread new changes if necessary Set cookiesFromFile = NetscapeCookieFile - .parseCookieFile(cookieFileContent, creationDate); + .parseCookieFile(cookieFileContent, createdAt); this.cookies = mergeCookies(cookiesFromFile, cookies); } } catch (FileNotFoundException e) { @@ -343,7 +350,7 @@ public void write(URL url) throws IOException, InterruptedException { ByteArrayOutputStream output = new ByteArrayOutputStream(); try (Writer writer = new OutputStreamWriter(output, StandardCharsets.US_ASCII)) { - write(writer, cookies, url, creationDate); + write(writer, cookies, url, createdAt); } LockFile lockFile = new LockFile(path.toFile()); for (int retryCount = 0; retryCount < LOCK_ACQUIRE_MAX_RETRY_COUNT; retryCount++) { @@ -377,24 +384,23 @@ public void write(URL url) throws IOException, InterruptedException { * @param url * the url for which to write the cookie (to derive the default * values for certain cookie attributes) - * @param creationDate - * the date when the cookie has been created. Important for - * calculation the cookie expiration time (calculated from - * cookie's maxAge and this creation time) + * @param createdAt + * cookie creation time; used to calculate a cookie's expiration + * time * @throws IOException * if an I/O error occurs */ static void write(@NonNull Writer writer, @NonNull Collection cookies, @NonNull URL url, - @NonNull Date creationDate) throws IOException { + @NonNull Instant createdAt) throws IOException { for (HttpCookie cookie : cookies) { - writeCookie(writer, cookie, url, creationDate); + writeCookie(writer, cookie, url, createdAt); } } private static void writeCookie(@NonNull Writer writer, @NonNull HttpCookie cookie, @NonNull URL url, - @NonNull Date creationDate) throws IOException { + @NonNull Instant createdAt) throws IOException { if (cookie.getMaxAge() <= 0) { return; // skip expired cookies } @@ -422,7 +428,7 @@ private static void writeCookie(@NonNull Writer writer, final String expirationDate; // whenCreated field is not accessible in HttpCookie expirationDate = String - .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000)); + .valueOf(createdAt.getEpochSecond() + cookie.getMaxAge()); writer.write(expirationDate); writer.write(COLUMN_SEPARATOR); writer.write(cookie.getName());