Skip to content

fix: send a tei:// TEI to TEA 0.4.0 endpoints in its urn:tei: form - #48

Merged
vpetersson merged 2 commits into
sbomify:masterfrom
aurangzaib048:fix/tei-urn-for-legacy-endpoints
Nov 23, 2026
Merged

vpetersson merged 2 commits into
sbomify:masterfrom
aurangzaib048:fix/tei-urn-for-legacy-endpoints

Conversation

@aurangzaib048

Copy link
Copy Markdown
Collaborator

Problem. TeaClient.from_tei (and tea-cli discover / inspect / TEI download without --base-url) negotiates TEA 1.0.0 first, then fails over to 0.4.0 endpoints. It sent a tei:// TEI to a 0.4.0 endpoint verbatim, but TEA 0.4.0 defines only the urn:tei:<type>:<domain>:<identifier> form. The README's own example therefore fails against trust.sbomify.com, which serves 0.4.0 only:

$ tea-cli discover "tei://trust.sbomify.com/uuid/6b031f75-5388-4d2b-907d-eab7fa9533dd"
Error: Client error: HTTP 400 — {"error": "Invalid TEI format"}

Fix. When the endpoint being tried is 0.4.0 (client.is_legacy), _connect sends the TEI's legacy form (new helper discovery._legacy_tei):

  • a purl identifier is decoded from Base64URL to the PURL itself, as 0.4.0 carries it;
  • other identifiers are kept byte for byte (the spec's TEI rules: percent-escapes are neither added nor removed);
  • a TEI with no 0.4.0 form (a type 0.4.0 doesn't define, or a purl TEI that doesn't carry a PURL) skips that endpoint and fails over to the next one.

TEA 1.x endpoints still receive the TEI verbatim, and TeaClient.discover() is unchanged (it still sends exactly what it is given).

Live check against trust.sbomify.com (from this branch):

  • tei://…/uuid/… now reaches the server as urn:tei:uuid:… and gets a TEA answer (OBJECT_UNKNOWN: the server doesn't index uuid TEIs) instead of the 400.
  • tei://trust.sbomify.com/purl/<Base64URL of pkg:github/sbomify/sbomify> now resolves and lists sbomify's product releases.

Tests. New TestFromTei cases: uuid, purl (Base64URL decoded) and percent-escaped hash TEIs reach a 0.4.0 endpoint in URN form; on a mixed .well-known the 1.0.0 endpoint gets tei:// and the 0.4.0 fallback gets the URN; TEIs with no 0.4.0 form skip the endpoint without a request. Two CLI tests expected the old verbatim behaviour (and mocked a HEAD probe from_tei no longer sends); they now expect the URN form. 1203 passed, 95% coverage (client.py 100%); ruff and mypy clean.

Docs. README (Discovery, Upgrading), docs/cli.md (discover TEI argument), CLAUDE.md (failover note) and the from_tei docstring. Touches only lines #46 leaves alone; a trial merge with #46 is clean.

from_tei negotiates TEA 1.0.0 first and fails over to 0.4.0 endpoints, but
sent the tei:// TEI to them verbatim. TEA 0.4.0 defines only the
urn:tei:<type>:<domain>:<identifier> form, so a 0.4.0 server answered 400
("Invalid TEI format") and discovery stopped: tea-cli discover with the
README's tei:// example failed against trust.sbomify.com, which serves
0.4.0 only.

When the endpoint being tried is 0.4.0 (client.is_legacy), _connect now
sends the TEI's legacy form: a purl identifier is decoded from Base64URL to
the PURL, other identifiers are kept byte for byte (percent-escapes are
neither added nor removed). A TEI whose type 0.4.0 does not define, or a
purl TEI that does not carry a PURL, has no legacy form, so that endpoint
is skipped and the next one tried. TEA 1.x endpoints still receive the TEI
verbatim, and TeaClient.discover() is unchanged.

Two CLI tests expected the old behaviour (and mocked a HEAD probe from_tei
no longer sends); they now expect the URN form.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 10:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Comment thread tests/client/test_client_v1.py Fixed
Comment thread tests/client/test_client_v1.py Fixed
CodeQL flags "host" in url as incomplete URL sanitization. Compare urlsplit(url).hostname instead, which is also the stricter assertion.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@vpetersson
vpetersson merged commit d22dd6b into sbomify:master Nov 23, 2026
6 checks passed
@aurangzaib048 aurangzaib048 mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants