aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Naveen <42328488+neilnaveen@users.noreply.github.com>2023-03-03 14:30:11 -0600
committerGitHub <noreply@github.com>2023-03-03 15:30:11 -0500
commitbe1c1c519edd37acbcf33977e3d167d1995997bb (patch)
tree73ccf48ef392a06db9653960530d5566da22fca1
parent105e17fd98ed1fab33b68c57158920a23aad2fda (diff)
downloadspdx-tools-be1c1c519edd37acbcf33977e3d167d1995997bb.tar.gz
Improve SPDX document validation (#200)
- Update the `CatagorySecurity` to `CategorySecurity` in `model.go` - Add `file1` to the list of files in `documents_test.go` to increase coverage - Add a validation test for an invalid document with an invalid relationship in `documents_test.go` [spdx/model.go] - Change `CatagorySecurity` to `CategorySecurity` [spdxlib/documents_test.go] - Add `file1` to the list of files - Change the relationship between `p1` and `p99` to `DEPENDS_ON` - Add a validation test for an invalid document with an invalid relationship Signed-off-by: Neil Naveen <42328488+neilnaveen@users.noreply.github.com>
-rw-r--r--spdx/model.go2
-rw-r--r--spdxlib/documents_test.go23
2 files changed, 24 insertions, 1 deletions
diff --git a/spdx/model.go b/spdx/model.go
index cc31d2a..e91856b 100644
--- a/spdx/model.go
+++ b/spdx/model.go
@@ -64,7 +64,7 @@ const (
const (
// F.2 Security types
- CatagorySecurity = common.CategorySecurity
+ CategorySecurity = common.CategorySecurity
SecurityCPE23Type = common.TypeSecurityCPE23Type
SecurityCPE22Type = common.TypeSecurityCPE22Type
SecurityAdvisory = common.TypeSecurityAdvisory
diff --git a/spdxlib/documents_test.go b/spdxlib/documents_test.go
index 3219b20..7a39cce 100644
--- a/spdxlib/documents_test.go
+++ b/spdxlib/documents_test.go
@@ -23,6 +23,9 @@ func TestValidDocumentPassesValidation(t *testing.T) {
{PackageName: "pkg4", PackageSPDXIdentifier: "p4"},
{PackageName: "pkg5", PackageSPDXIdentifier: "p5"},
},
+ Files: []*spdx.File{
+ {FileName: "file1", FileSPDXIdentifier: "f1"},
+ },
Relationships: []*spdx.Relationship{
{
RefA: common.MakeDocElementID("", "DOCUMENT"),
@@ -91,4 +94,24 @@ func TestInvalidDocumentFailsValidation(t *testing.T) {
if err == nil {
t.Fatalf("expected non-nil error, got nil")
}
+
+ doc = &spdx.Document{
+ SPDXVersion: spdx.Version,
+ DataLicense: spdx.DataLicense,
+ SPDXIdentifier: common.ElementID("DOCUMENT"),
+ CreationInfo: &spdx.CreationInfo{},
+
+ Relationships: []*spdx.Relationship{
+ {
+ RefA: common.MakeDocElementID("", "p1"),
+ RefB: common.MakeDocElementID("", "p99"),
+ Relationship: "DEPENDS_ON",
+ },
+ },
+ }
+
+ err = ValidateDocument(doc)
+ if err == nil {
+ t.Fatalf("expected non-nil error, got nil")
+ }
}