Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Add date format to support offset in NuGet timestamps #3788

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class NugetMetaAnalyzer extends AbstractMetaAnalyzer {

public static final DateFormat[] SUPPORTED_DATE_FORMATS = new DateFormat[]{
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
};
private static final Logger LOGGER = Logger.getLogger(NugetMetaAnalyzer.class);
private static final String DEFAULT_BASE_URL = "https://api.nuget.org";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@

import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static org.dependencytrack.tasks.repositories.NugetMetaAnalyzer.SUPPORTED_DATE_FORMATS;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

Expand Down Expand Up @@ -121,6 +126,19 @@ public void testAnalyzerWithPrivatePackageRepository() throws Exception {
Assert.assertEquals("5.0.2", metaModel.getLatestVersion());
Assert.assertNotNull(metaModel.getPublishedTimestamp());
}

@Test
public void testPublishedDateTimeFormat() throws ParseException {
Date dateParsed = null;
for (DateFormat dateFormat : SUPPORTED_DATE_FORMATS) {
try {
dateParsed = dateFormat.parse("1900-01-01T00:00:00+00:00");
} catch (ParseException e) {}
}
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Assert.assertEquals(dateFormat.parse("1900-01-01T00:00:00+00:00"), dateParsed);
}

private String readResourceFileToString(String fileName) throws Exception {
return Files.readString(Paths.get(getClass().getResource(fileName).toURI()));
}
Expand Down