Skip to content

Commit 75641f7

Browse files
committed
Validate document URI
Fixes #22
1 parent 8b28c82 commit 75641f7

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/main/java/org/spdx/library/model/v2/SpdxDocument.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ protected List<String> _verify(Set<String> verifiedIds, String verifySpecVersion
330330
} catch (InvalidSPDXAnalysisException e) {
331331
retval.add("Error getting document describes: "+e.getMessage());
332332
}
333+
// document namespace
334+
try {
335+
java.net.URI uri = new java.net.URI(getDocumentUri());
336+
} catch (java.net.URISyntaxException e) {
337+
retval.add(String.format("Document namespace %s is not a valid URI", getDocumentUri()));
338+
}
333339
//TODO: Figure out what to do with checking any "dangling items" not linked to the describes by
334340
return retval;
335341
}

src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,39 @@ public void testVerify() throws InvalidSPDXAnalysisException {
387387
assertEquals(2, result.size());
388388
}
389389

390-
/**
391-
* Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#getDocumentDescribes()}.
392-
*/
390+
public void testVerifyBadDocNamespace() throws InvalidSPDXAnalysisException {
391+
SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), "://bad/uri", gmo.getCopyManager(), true);
392+
doc.setStrict(false);
393+
List<Annotation> annotations = Arrays.asList(new Annotation[] {
394+
ANNOTATION1, ANNOTATION2
395+
});
396+
List<ExtractedLicenseInfo> extractedLicenseInfos = Arrays.asList(new ExtractedLicenseInfo[] {
397+
LICENSE1, LICENSE2
398+
});
399+
List<SpdxItem> items = Arrays.asList(new SpdxItem[] {
400+
FILE1, FILE2, PACKAGE1, PACKAGE2
401+
});
402+
List<Relationship> relationships = Arrays.asList(new Relationship[] {
403+
RELATIONSHIP1, RELATIONSHIP2
404+
});
405+
doc.setAnnotations(annotations);
406+
doc.setComment(DOC_COMMENT1);
407+
doc.setCreationInfo(CREATIONINFO1);
408+
doc.setDataLicense(CCO_DATALICENSE);
409+
doc.setExtractedLicenseInfos(extractedLicenseInfos);
410+
doc.setName(DOC_NAME1);
411+
doc.setRelationships(relationships);
412+
doc.setDocumentDescribes(items);
413+
doc.setSpecVersion(Version.TWO_POINT_THREE_VERSION);
414+
List<String> result = doc.verify();
415+
assertEquals(1, result.size());
416+
assertTrue(result.get(0).contains("namespace"));
417+
}
418+
419+
420+
/**
421+
* Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#getDocumentDescribes()}.
422+
*/
393423
public void testGetDocumentDescribes() throws InvalidSPDXAnalysisException {
394424
SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true);
395425
doc.setStrict(false);

0 commit comments

Comments
 (0)