Skip to content
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 @@ -17,8 +17,7 @@
*/
package org.owasp.dependencycheck.xml.suppression;

import org.apache.commons.lang3.Strings;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.h2.util.StringUtils;
import org.jspecify.annotations.NonNull;
import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.dependency.Vulnerability;
Expand All @@ -31,6 +30,7 @@
import us.springett.parsers.cpe.exceptions.CpeEncodingException;

import javax.annotation.concurrent.NotThreadSafe;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
Expand Down Expand Up @@ -727,8 +727,9 @@ protected boolean identifierMatches(PropertyType suppressionEntry, Identifier id

private static boolean cpe22UriPrefixMatches(PropertyType suppressionEntry, String cpe22Uri) {
String candidate = cpe22Uri + cpePartMatchingSuffixFor(suppressionEntry);
return (suppressionEntry.isCaseSensitive() ? Strings.CS : Strings.CI)
.startsWith(candidate, suppressionEntry.getValue());
return suppressionEntry.isCaseSensitive()
? candidate.startsWith(suppressionEntry.getValue())
: StringUtils.startsWithIgnoringCase(candidate, suppressionEntry.getValue());
}

/**
Expand All @@ -753,7 +754,7 @@ public String toString() {
final StringBuilder sb = new StringBuilder(64);
sb.append("SuppressionRule{");
if (until != null) {
final String dt = DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT.format(until);
final String dt = DateTimeFormatter.ISO_DATE_TIME.format(until.toInstant().atZone(until.getTimeZone().toZoneId()));
sb.append("until=").append(dt).append(',');
}
if (filePath != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
import us.springett.parsers.cpe.exceptions.CpeValidationException;

import java.io.File;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -417,6 +421,16 @@ void testThresholdHighestIsUseIfMultipleBelows() {
assertEquals(1, dependency.getSuppressedVulnerabilities().size());
}

@Test
void testToStringExpiryFormatting() {
ZonedDateTime time = ZonedDateTime.of(2024, 6, 1, 12, 0, 0, 0, ZoneId.of("Asia/Singapore"));
SuppressionRule rule = new SuppressionRule();
Calendar until = Calendar.getInstance(TimeZone.getTimeZone(time.getZone()));
until.setTimeInMillis(time.toInstant().toEpochMilli());
rule.setUntil(until);
assertTrue(rule.toString().contains("until=2024-06-01T12:00:00+08:00"));
}

@Test
void testThresholdHighestIsUseIfMultipleVersionedBelows() {
Dependency dependency = createDependencyWithDifferentScores();
Expand Down
Loading