|
| 1 | +import os |
| 2 | + |
| 3 | +from expects import * |
| 4 | +from expects import equal |
| 5 | +from mamba import * |
| 6 | + |
| 7 | +from sdcclient import SdScanningClient |
| 8 | +from specs import be_successful_api_call |
| 9 | + |
| 10 | +with description("Scanning vulnerability details") as self: |
| 11 | + with before.each: |
| 12 | + self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"), |
| 13 | + token=os.getenv("SDC_SECURE_TOKEN")) |
| 14 | + |
| 15 | + with context("when retrieving a simple vulnerability"): |
| 16 | + with it("retrieves the vulnerability details correctly if exists"): |
| 17 | + vuln_id = "VULNDB-140292" |
| 18 | + ok, res = self.client.get_vulnerability_details(id=vuln_id) |
| 19 | + |
| 20 | + expect((ok, res)).to(be_successful_api_call) |
| 21 | + expect(res).to( |
| 22 | + have_keys("description", "severity", "vendor_data", "nvd_data", "references", |
| 23 | + "affected_packages", id=equal(vuln_id)) |
| 24 | + ) |
| 25 | + |
| 26 | + with it("fails if it does not exist"): |
| 27 | + non_existing_vuln_id = "VULNDB-NOEXISTS" |
| 28 | + ok, res = self.client.get_vulnerability_details(id=non_existing_vuln_id) |
| 29 | + |
| 30 | + expect((ok, res)).to_not(be_successful_api_call) |
| 31 | + expect(res).to(equal(f"Vulnerability {non_existing_vuln_id} was not found")) |
| 32 | + |
| 33 | + with it("fails if no id was provided"): |
| 34 | + non_existing_vuln_id = None |
| 35 | + ok, res = self.client.get_vulnerability_details(id=non_existing_vuln_id) |
| 36 | + |
| 37 | + expect((ok, res)).to_not(be_successful_api_call) |
| 38 | + expect(res).to(equal(f"No vulnerability ID provided")) |
0 commit comments