| 162 | |
| 163 | |
| 164 | def _registry(path, image): |
| 165 | raw = _read(path, REGISTRY_CAP) |
| 166 | try: |
| 167 | value = json.loads(raw.decode("utf-8", "strict"), object_pairs_hook=_pairs, |
| 168 | parse_constant=lambda _: _error("input", "nonfinite JSON number")) |
| 169 | except (UnicodeError, json.JSONDecodeError, RecursionError): |
| 170 | _error("input", "invalid registry JSON") |
| 171 | if type(value) is not dict or set(value) != {"format", "image_sha256", "suites"}: |
| 172 | _error("input", "registry keys do not match v0 schema") |
| 173 | if value["format"] != "cbm.coverage.registry.v0": |
| 174 | _error("input", "unsupported registry format") |
| 175 | declared = value["image_sha256"] |
| 176 | if type(declared) is not str or not re.fullmatch(r"[0-9a-f]{64}", declared): |
| 177 | _error("input", "registry image digest must be lowercase SHA256") |
| 178 | if declared != image["sha256"]: |
| 179 | _error("identity", "registry does not match runner image") |
| 180 | suites = value["suites"] |
| 181 | if type(suites) is not list or not suites: |
| 182 | _error("input", "registry suites must be nonempty") |
| 183 | result = {} |
| 184 | rows = 0 |
| 185 | for item in suites: |
| 186 | if type(item) is not dict or set(item) != {"name", "tests"}: |
| 187 | _error("input", "registry suite keys do not match schema") |
| 188 | name = item["name"] |
| 189 | _identifier(name, suite=True) |
| 190 | if name in result: |
| 191 | _error("input", "duplicate registry suite") |
| 192 | tests = item["tests"] |
| 193 | if type(tests) is not list or not tests: |
| 194 | _error("input", "registry tests must be nonempty") |
| 195 | seen = set() |
| 196 | for test in tests: |
| 197 | _identifier(test) |
| 198 | if test in seen: |
| 199 | _error("input", "duplicate registry test") |
| 200 | seen.add(test) |
| 201 | rows += 1 + len(tests) |
| 202 | if rows > ROW_CAP: |
| 203 | _error("resource_limit", "registry row limit exceeded") |
| 204 | result[name] = tuple(tests) |
| 205 | return result, hashlib.sha256(raw).hexdigest(), raw |
| 206 | |
| 207 | |
| 208 | class Evidence: |