99from unittest import TestCase
1010
1111from archivist .archivist import Archivist
12+ from archivist .errors import ArchivistBadRequestError
1213from archivist .logger import set_logger
1314from archivist .timestamp import now_timestamp
1415
2526}
2627
2728TEST_SBOM_PATH = "functests/test_resources/bom.xml"
29+ TEST_SBOM_SPDX_PATH = "functests/test_resources/bom.spdx"
2830TEST_SBOM_DOWNLOAD_PATH = "functests/test_resources/downloaded_bom.xml"
2931
3032if "TEST_DEBUG" in environ and environ ["TEST_DEBUG" ]:
@@ -57,15 +59,15 @@ def tearDown(cls) -> None:
5759 with suppress (FileNotFoundError ):
5860 remove (TEST_SBOM_DOWNLOAD_PATH )
5961
60- def test_sbom_upload_with_public_privacy (self ):
62+ def test_sbom_upload_with_private_privacy (self ):
6163 """
6264 Test sbom upload with privacy
6365 """
6466 now = now_timestamp ()
65- print ("Title:" , self .title , now )
67+ print ("Public Upload Title:" , self .title , now )
6668 with open (TEST_SBOM_PATH , "rb" ) as fd :
6769 metadata = self .arch .sboms .upload (
68- fd , confirm = True , params = {"privacy" : "PUBLIC " }
70+ fd , confirm = True , params = {"privacy" : "PRIVATE " }
6971 )
7072 print ("first upload" , json_dumps (metadata .dict (), indent = 4 ))
7173 identity = metadata .identity
@@ -78,12 +80,57 @@ def test_sbom_upload_with_public_privacy(self):
7880 msg = "Metadata not correct" ,
7981 )
8082
83+ def test_sbom_upload_with_illegal_privacy (self ):
84+ """
85+ Test sbom upload with privacy
86+ """
87+ now = now_timestamp ()
88+ print ("Illegal Upload Title:" , self .title , now )
89+ with open (TEST_SBOM_PATH , "rb" ) as fd :
90+ with self .assertRaises (ArchivistBadRequestError ):
91+ metadata = self .arch .sboms .upload (
92+ fd , confirm = True , params = {"privacy" : "XXXXXX" }
93+ )
94+
95+ def test_sbom_upload_with_spdx (self ):
96+ """
97+ Test sbom upload with spdx
98+ """
99+ now = now_timestamp ()
100+ print ("SPDX Upload Title:" , self .title , now )
101+ with open (TEST_SBOM_SPDX_PATH , "rb" ) as fd :
102+ metadata = self .arch .sboms .upload (
103+ fd , confirm = True , params = {"sbomType" : "spdx-tag" }
104+ )
105+ print ("first upload" , json_dumps (metadata .dict (), indent = 4 ))
106+ identity = metadata .identity
107+
108+ metadata1 = self .arch .sboms .read (identity )
109+ print ("read" , json_dumps (metadata1 .dict (), indent = 4 ))
110+ self .assertEqual (
111+ metadata ,
112+ metadata1 ,
113+ msg = "Metadata not correct" ,
114+ )
115+
116+ def test_sbom_upload_with_illegal_format (self ):
117+ """
118+ Test sbom upload with illegal format
119+ """
120+ now = now_timestamp ()
121+ print ("SPDX Upload Title:" , self .title , now )
122+ with open (TEST_SBOM_SPDX_PATH , "rb" ) as fd :
123+ with self .assertRaises (ArchivistBadRequestError ):
124+ metadata = self .arch .sboms .upload (
125+ fd , confirm = True , params = {"sbomType" : "xxxxxxxx" }
126+ )
127+
81128 def test_sbom_upload_with_confirmation (self ):
82129 """
83130 Test sbom upload with confirmation
84131 """
85132 now = now_timestamp ()
86- print ("Title:" , self .title , now )
133+ print ("Confirmed Upload Title:" , self .title , now )
87134 with open (TEST_SBOM_PATH , "rb" ) as fd :
88135 metadata = self .arch .sboms .upload (fd , confirm = True )
89136 print ("first upload" , json_dumps (metadata .dict (), indent = 4 ))
@@ -105,6 +152,35 @@ def test_sbom_upload_with_confirmation(self):
105152 msg = "No. of SBOMS should be 1" ,
106153 )
107154
155+ def test_sbom_upload_with_cyclonedx_xml (self ):
156+ """
157+ Test sbom upload with cyclonedx-xml
158+ """
159+ now = now_timestamp ()
160+ print ("CycloneDX-XML Upload Title:" , self .title , now )
161+ with open (TEST_SBOM_PATH , "rb" ) as fd :
162+ metadata = self .arch .sboms .upload (
163+ fd , params = {"sbomType" : "cyclonedx-xml" }, confirm = True
164+ )
165+ print ("first upload" , json_dumps (metadata .dict (), indent = 4 ))
166+ identity = metadata .identity
167+
168+ metadata1 = self .arch .sboms .read (identity )
169+ print ("read" , json_dumps (metadata1 .dict (), indent = 4 ))
170+ self .assertEqual (
171+ metadata ,
172+ metadata1 ,
173+ msg = "Metadata not correct" ,
174+ )
175+
176+ sleep (1 ) # the data may have not reached cogsearch
177+ metadatas = list (self .arch .sboms .list (metadata = {"uploaded_since" : now }))
178+ self .assertEqual (
179+ len (metadatas ),
180+ 1 ,
181+ msg = "No. of SBOMS should be 1" ,
182+ )
183+
108184 def test_sbom_upload_and_download (self ):
109185 """
110186 Test sbom upload and download through the SDK
0 commit comments