|
| 1 | +import os |
| 2 | + |
| 3 | +from expects import expect, contain, have_keys, equal |
| 4 | +from mamba import before, it, context, description |
| 5 | + |
| 6 | +from sdcclient import SdScanningClient |
| 7 | +from specs import be_successful_api_call |
| 8 | + |
| 9 | +with description("Query Image Content", "integration") as self: |
| 10 | + with before.each: |
| 11 | + self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"), |
| 12 | + token=os.getenv("SDC_SECURE_TOKEN")) |
| 13 | + |
| 14 | + with it("is able to retrieve the OS contents"): |
| 15 | + ok, res = self.client.query_image_content("alpine:latest", "os") |
| 16 | + |
| 17 | + expect((ok, res)).to(be_successful_api_call) |
| 18 | + expect(res["content"]).to(contain(have_keys("license", "origin", "package", "size", "type", "version"))) |
| 19 | + expect(res["content_type"]).to(equal("os")) |
| 20 | + |
| 21 | + with it("is able to retrieve the npm contents"): |
| 22 | + ok, res = self.client.query_image_content("alpine:latest", "npm") |
| 23 | + |
| 24 | + expect((ok, res)).to(be_successful_api_call) |
| 25 | + expect(res["content_type"]).to(equal("npm")) |
| 26 | + |
| 27 | + with it("is able to retrieve the gem contents"): |
| 28 | + ok, res = self.client.query_image_content("alpine:latest", "gem") |
| 29 | + |
| 30 | + expect((ok, res)).to(be_successful_api_call) |
| 31 | + expect(res["content_type"]).to(equal("gem")) |
| 32 | + |
| 33 | + with it("is able to retrieve the python contents"): |
| 34 | + ok, res = self.client.query_image_content("alpine:latest", "python") |
| 35 | + |
| 36 | + expect((ok, res)).to(be_successful_api_call) |
| 37 | + expect(res["content_type"]).to(equal("python")) |
| 38 | + |
| 39 | + with it("is able to retrieve the java contents"): |
| 40 | + ok, res = self.client.query_image_content("alpine:latest", "java") |
| 41 | + |
| 42 | + expect((ok, res)).to(be_successful_api_call) |
| 43 | + expect(res["content_type"]).to(equal("java")) |
| 44 | + |
| 45 | + with it("is able to retrieve the files contents"): |
| 46 | + ok, res = self.client.query_image_content("alpine:latest", "files") |
| 47 | + |
| 48 | + expect((ok, res)).to(be_successful_api_call) |
| 49 | + expect(res["content"]).to( |
| 50 | + contain(have_keys("filename", "gid", "linkdest", "mode", "sha256", "size", "type", "uid"))) |
| 51 | + expect(res["content_type"]).to(equal("files")) |
| 52 | + |
| 53 | + with context("when the type is not in the supported list"): |
| 54 | + with it("returns an error indicating the type is incorrect"): |
| 55 | + ok, res = self.client.query_image_content("alpine:latest", "Unknown") |
| 56 | + |
| 57 | + expect((ok, res)).not_to(be_successful_api_call) |
| 58 | + expect(res).to(equal( |
| 59 | + "unsupported type provided: unknown, must be one of ['os', 'files', 'npm', 'gem', 'python', 'java']")) |
0 commit comments