From be1c1c519edd37acbcf33977e3d167d1995997bb Mon Sep 17 00:00:00 2001 From: Neil Naveen <42328488+neilnaveen@users.noreply.github.com> Date: Fri, 3 Mar 2023 14:30:11 -0600 Subject: 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> --- spdx/model.go | 2 +- spdxlib/documents_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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") + } } -- cgit v1.2.3