Skip to content
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
8 changes: 7 additions & 1 deletion functests/execsboms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ def test_sbom_upload_with_spdx(self):
print("SPDX Upload Title:", self.title, now)
with open(TEST_SBOM_SPDX_PATH, "rb") as fd:
metadata = self.arch.sboms.upload(
fd, confirm=True, params={"sbomType": "spdx-tag"}
fd,
confirm=True,
params={
"sbomType": "spdx-tag",
"component": "spdx-test-component",
"version": "v0.0.1",
},
)
print("first upload", json_dumps(metadata.dict(), indent=4))
identity = metadata.identity
Expand Down
89 changes: 89 additions & 0 deletions unittests/testsboms.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,95 @@ def test_sboms_str(self):
msg="Incorrect str",
)

def test_sboms_upload_spdx(self):
"""
Test attachment upload
"""
with mock.patch.object(self.arch._session, "post") as mock_post:
mock_post.return_value = MockResponse(200, **RESPONSE)

sbom = self.arch.sboms.upload(
self.mockstream,
params={
"sbomType": "spdx-tag",
"component": "spdx-test-component",
"version": "v0.0.1",
},
)
args, kwargs = mock_post.call_args
self.assertEqual(
args,
(f"url/{ROOT}/{SUBPATH}",),
msg="UPLOAD method called incorrectly",
)
self.assertEqual(
"headers" in kwargs,
True,
msg="UPLOAD no headers found",
)
headers = kwargs["headers"]
self.assertEqual(
"authorization" in headers,
True,
msg="UPLOAD no authorization found",
)
params = kwargs["params"]
self.assertEqual(
params,
{
"sbomType": "spdx-tag",
"component": "spdx-test-component",
"version": "v0.0.1",
},
msg="Params did not contain expected values",
)
self.assertEqual(
headers["authorization"],
"Bearer authauthauth",
msg="UPLOAD incorrect authorization",
)
self.assertEqual(
headers["content-type"].startswith("multipart/form-data;"),
True,
msg="UPLOAD incorrect content-type",
)
self.assertEqual(
kwargs["verify"],
True,
msg="UPLOAD method called incorrectly",
)
self.assertEqual(
"data" in kwargs,
True,
msg="UPLOAD no data found",
)
fields = kwargs["data"].fields
self.assertEqual(
"sbom" in fields,
True,
msg="UPLOAD no field 'sbom' found",
)
self.assertEqual(
fields["sbom"][0],
"filename",
msg="UPLOAD incorrect filename",
)
self.assertEqual(
fields["sbom"][2],
"text/xml",
msg="UPLOAD incorrect filetype",
)
self.assertEqual(
sbom,
SBOM(**RESPONSE),
msg="UPLOAD method called incorrectly",
)
self.assertEqual(
sbom.dict(),
RESPONSE,
msg="UPLOAD method called incorrectly",
)

def test_sboms_upload(self):
"""
Test attachment upload
Expand Down