-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project CreateBom): write control file with attachment details
This can be used to check meta data of attachments before feeding the list into "bom downloadAttachments".
- Loading branch information
Showing
4 changed files
with
190 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ def test_project_not_found(self) -> None: | |
args.verbose = True | ||
args.id = "34ef5c5452014c52aa9ce4bc180624d8" | ||
args.outputfile = self.OUTPUTFILE | ||
args.controlfile = None | ||
|
||
self.add_login_response() | ||
|
||
|
@@ -155,19 +156,12 @@ def test_create_bom_multiple_purls(self, capsys): | |
assert "Multiple purls added" in captured.out | ||
assert cdx_components[0].purl == "pkg:deb/debian/[email protected] pkg:pypi/[email protected]" | ||
|
||
@responses.activate | ||
def test_project_by_id(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBasePytest.MYTOKEN, url=TestBasePytest.MYURL) | ||
|
||
def add_project_releases_responses(self): | ||
# the project | ||
project = self.get_project_for_test() | ||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/projects/p001", | ||
json=project, | ||
json=self.get_project_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
|
@@ -194,7 +188,7 @@ def test_project_by_id(self): | |
"attachmentType": "SOURCE_SELF", | ||
"_links": { | ||
"self": { | ||
"href": "https://my.server.com/resource/api/attachments/r002a002" | ||
"href": "https://my.server.com/resource/api/attachments/r002a003" | ||
} | ||
} | ||
}) | ||
|
@@ -204,7 +198,7 @@ def test_project_by_id(self): | |
"attachmentType": "CLEARING_REPORT", | ||
"_links": { | ||
"self": { | ||
"href": "https://my.server.com/resource/api/attachments/r002a003" | ||
"href": "https://my.server.com/resource/api/attachments/r002a004" | ||
} | ||
} | ||
}) | ||
|
@@ -217,8 +211,19 @@ def test_project_by_id(self): | |
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
return release | ||
|
||
cdx_bom = sut.create_project_cdx_bom("p001") | ||
@responses.activate | ||
def test_project_by_id(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBasePytest.MYTOKEN, url=TestBasePytest.MYURL) | ||
|
||
release = self.add_project_releases_responses() | ||
project = self.get_project_for_test() | ||
|
||
cdx_bom, _ = sut.create_project_cdx_bom("p001", create_controlfile=False) | ||
cx_comp = cdx_bom.components[0] | ||
assert cx_comp.purl == release["externalIds"]["package-url"] | ||
|
||
|
@@ -239,15 +244,15 @@ def test_project_by_id(self): | |
assert len(ext_refs) == 1 | ||
assert ext_refs[0].url == release["_embedded"]["sw360:attachments"][1]["filename"] | ||
assert ext_refs[0].type == ExternalReferenceType.OTHER | ||
assert ext_refs[0].comment, CaPyCliBom.CLI_FILE_COMMENT + " == sw360Id: r002a002" | ||
assert ext_refs[0].comment == CaPyCliBom.CLI_FILE_COMMENT | ||
assert ext_refs[0].hashes[0].alg == "SHA-1" | ||
assert ext_refs[0].hashes[0].content == release["_embedded"]["sw360:attachments"][1]["sha1"] | ||
|
||
ext_refs = [e for e in cx_comp.external_references | ||
if e.comment and e.comment.startswith(CaPyCliBom.CRT_FILE_COMMENT)] | ||
assert len(ext_refs) == 1 | ||
assert ext_refs[0].url == release["_embedded"]["sw360:attachments"][3]["filename"] | ||
assert ext_refs[0].comment, CaPyCliBom.CRT_FILE_COMMENT + " == sw360Id: r002a003" | ||
assert ext_refs[0].comment == CaPyCliBom.CRT_FILE_COMMENT | ||
assert ext_refs[0].type == ExternalReferenceType.OTHER | ||
assert ext_refs[0].hashes[0].alg == "SHA-1" | ||
assert ext_refs[0].hashes[0].content == release["_embedded"]["sw360:attachments"][3]["sha1"] | ||
|
@@ -260,6 +265,71 @@ def test_project_by_id(self): | |
assert cdx_bom.metadata.component.version == project["version"] | ||
assert cdx_bom.metadata.component.description == project["description"] | ||
|
||
@responses.activate | ||
def test_project_by_id_controlfile(self): | ||
sut = CreateBom() | ||
self.add_login_response() | ||
sut.login(token=TestBasePytest.MYTOKEN, url=TestBasePytest.MYURL) | ||
|
||
self.add_project_releases() | ||
|
||
# attachment info | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r001a001", | ||
body=""" | ||
{ | ||
"filename": "CLIXML_wheel-0.38.4.xml", | ||
"sha1": "ccd9f1ed2f59c46ff3f0139c05bfd76f83fd9851", | ||
"attachmentType": "COMPONENT_LICENSE_INFO_XML" | ||
}""", | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r002a002", | ||
body=""" | ||
{ | ||
"filename": "CLIXML_clipython-1.3.0.xml", | ||
"sha1": "dd4c38387c6811dba67d837af7742d84e61e20de", | ||
"attachmentType": "COMPONENT_LICENSE_INFO_XML", | ||
"checkedBy": "[email protected]", | ||
"checkStatus": "ACCEPTED", | ||
"createdBy": "[email protected]" | ||
}""", | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r002a004", | ||
body=""" | ||
{ | ||
"filename": "clipython-1.3.0.docx", | ||
"sha1": "f0d8f2ddd017bdeaecbaec72ff76a6c0a045ec66", | ||
"attachmentType": "CLEARING_REPORT" | ||
}""", | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
|
||
_, controlfile = sut.create_project_cdx_bom("p001", create_controlfile=True) | ||
assert controlfile['ProjectName'] == 'CaPyCLI, 1.9.0' | ||
assert controlfile['Components'][0]['ComponentName'] == 'cli-support 1.3' | ||
assert controlfile['Components'][0]['Sw360Id'] == 'r002' | ||
assert controlfile['Components'][0]['Sw360AttachmentId'] == 'r002a002' | ||
assert controlfile['Components'][0]['CliFile'] == 'CLIXML_clipython-1.3.0.xml' | ||
assert controlfile['Components'][0]['CheckedBy'] == '[email protected]' | ||
assert controlfile['Components'][0]['CheckStatus'] == 'ACCEPTED' | ||
assert controlfile['Components'][0]['CreatedBy'] == '[email protected]' | ||
|
||
assert controlfile['Components'][1]['ReportFile'] == 'clipython-1.3.0.docx' | ||
|
||
@responses.activate | ||
def test_project_show_by_name(self): | ||
sut = CreateBom() | ||
|
@@ -275,6 +345,7 @@ def test_project_show_by_name(self): | |
args.name = "CaPyCLI" | ||
args.version = "1.9.0" | ||
args.outputfile = self.OUTPUTFILE | ||
args.controlfile = None | ||
|
||
self.add_login_response() | ||
|
||
|
@@ -358,6 +429,65 @@ def test_project_show_by_name(self): | |
|
||
self.delete_file(self.OUTPUTFILE) | ||
|
||
@responses.activate | ||
def test_create_project_bom_release_error(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBasePytest.MYTOKEN, url=TestBasePytest.MYURL) | ||
|
||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r001", | ||
status=404, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r002", | ||
json=self.get_release_cli_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
with pytest.raises(SystemExit): | ||
bom, _ = sut.create_project_bom(self.get_project_for_test(), create_controlfile=False) | ||
|
||
@responses.activate | ||
def test_create_project_bom_controlfile_attachment_error(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBasePytest.MYTOKEN, url=TestBasePytest.MYURL) | ||
|
||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r001", | ||
json=self.get_release_wheel_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r002", | ||
json=self.get_release_cli_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r002a002", | ||
status=404, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
|
||
with pytest.raises(SystemExit): | ||
bom, _ = sut.create_project_bom(self.get_project_for_test(), create_controlfile=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
APP = TestCreateBom() | ||
|