def test_get_manifest_from_commit_fails(self, mocker, integration, requests_mock, mock_results, mocked_status, expected): """ Given: - A project without manifest file in master in Iron Bank. When: Validating docker image of Iron Bank pack. Then: Validates we show the correct error. """ manifest_url = 'https://repo1.dso.mil/api/v4/projects/dsop%2Fopensource%2Fpalo-alto-networks%2Ftest%2F' \ 'test_project/repository/files/hardening_manifest.yaml/raw' requests_mock.get(manifest_url, status_code=mocked_status, text=mock_results) DockerImageValidator.is_iron_bank = True docker_image_name = 'test/test_project:1.0.2' DockerImageValidator.yml_docker_image = docker_image_name DockerImageValidator.file_path = integration.yml.path with pytest.raises(Exception) as e: DockerImageValidator._get_manifest_from_commit( manifest_url, 'sha1') assert str(e.value) == expected
def test_get_manifest_from_commit(self, integration, requests_mock): """ Given: An example existing commit with successful commits in master with Manifest file in Iron Bank. When: Validating docker image of Iron Bank pack. Then: Validates we send the correct request to Iron Bank. """ manifest_url = 'https://repo1.dso.mil/api/v4/projects/dsop%2Fopensource%2Fpalo-alto-networks%2Ftest%2F'\ 'test_project/repository/files/hardening_manifest.yaml/raw' request_mock = requests_mock.get( manifest_url, text= """apiVersion: v1\nname: opensource/palo-alto-networks/test/test_project\ntags:\n- 1.0.1.23955\n""" ) DockerImageValidator.file_path = integration.yml.path DockerImageValidator.is_iron_bank = True docker_image_name = 'test/test_project:1.0.2' DockerImageValidator.yml_docker_image = docker_image_name DockerImageValidator._get_manifest_from_commit( manifest_url, 'sha1') assert request_mock.last_request.query == 'ref=sha1' assert request_mock.last_request.path == '/api/v4/projects/dsop%2fopensource%2fpalo-alto-networks%2f' \ 'test%2ftest_project/repository/files/hardening_manifest.yaml/raw'