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: Fix failing JSON BOM validation when specVersion is not one of the first fields #3698

Merged
merged 1 commit into from
May 13, 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 @@ -126,7 +126,7 @@ private CycloneDxSchema.Version detectSchemaVersionFromJson(final byte[] bomByte
}

CycloneDxSchema.Version schemaVersion = null;
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
while (jsonParser.nextToken() != null) {
final String fieldName = jsonParser.getCurrentName();
if ("specVersion".equals(fieldName)) {
if (jsonParser.nextToken() == JsonToken.VALUE_STRING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNoException;

public class CycloneDxValidatorTest {

Expand Down Expand Up @@ -162,4 +163,17 @@ public void testValidateXmlWithInvalidComponentType() {
valid with respect to its type, 'classification'.""");
}

@Test // https://github.com/DependencyTrack/dependency-track/issues/3696
public void testValidateJsonWithSpecVersionAtTheBottom() {
assertThatNoException()
.isThrownBy(() -> validator.validate("""
{
"metadata": {},
"components": [],
"bomFormat": "CycloneDX",
"specVersion": "1.5"
}
""".getBytes()));
}

}