Skip to content

fix(xtest): correct PQC version threshold and algorithm error detection#462

Open
dmihalcik-virtru wants to merge 1 commit into
fix/DSPX-3356-xwing-kao-size-assertionsfrom
fix/DSPX-3356-ci-prereqs
Open

fix(xtest): correct PQC version threshold and algorithm error detection#462
dmihalcik-virtru wants to merge 1 commit into
fix/DSPX-3356-xwing-kao-size-assertionsfrom
fix/DSPX-3356-ci-prereqs

Conversation

@dmihalcik-virtru
Copy link
Copy Markdown
Member

Context

This is a prerequisite fix for PR #461 (fix/DSPX-3356-xwing-kao-size-assertions), which is failing on two CI jobs:

  • xct (main, go@main) — all PQC tests fail at decrypt (platform bug, unrelated to this PR)
  • xct (v0.15.0, go@v0.32.0) — PQC tests ERROR instead of SKIP ← fixed here

What this fixes

1. tdfs.py — wrong version threshold for mechanism-xwing / mechanism-secpmlkem

mechanism-xwing was gated at >= (0, 14, 0), but platform v0.15.0 rejects hpqt:xwing key creation with:

{"message": "Failed to create kas key: invalid_argument: validation error:\n - key_algorithm: The key_algorithm must be one of the defined values. [key_algorithm_defined]"}

This means v0.15.0 passes the version check, reaches key creation, fails, and — because the error string doesn't match the existing guard — crashes the fixture with AssertionError instead of calling pytest.skip.

Raised threshold to (0, 16, 0), the expected next minor release after the commit that added hpqt:* key management support (one commit past service/v0.15.0).

2. otdfctl.py — missing error string in InvalidAlgorithm detection

kas_registry_create_key only recognised "Invalid key parameters: invalid algorithm" as an unsupported-algorithm signal. Platform v0.15.0 returns a protobuf field-validation error containing "key_algorithm_defined" instead. Without the match, the error fell through to assert process.returncode == 0, turning what should be a pytest.skip into a test ERROR.

Added "key_algorithm_defined" as a second trigger for InvalidAlgorithm.

What this does NOT fix

The xct (main, go@main) failures: all PQC tests encrypt successfully but fail at decrypt — every SDK (go, java) returns exit 1. That is the underlying platform bug (DSPX-3356): the KAS at main encodes the wrappedKey using ec:secp384r1 wrapping rather than raw X-Wing KEM encapsulation, producing a ciphertext no SDK can unwrap. That fix belongs in opentdf/platform, not the test suite.

Note for PR #461: the assertion changes in that PR (accepting > 1120 bytes and ephemeralPublicKey is None) would mask the broken ciphertext and allow the encrypt assertions to pass while decrypt still fails. Recommend reverting those assertion changes and instead landing this PR first so CI goes green on v0.15.0, then tracking the platform decrypt fix separately.

Test plan

  • xct (v0.15.0, go@v0.32.0): all test_pqc.py cases SKIP cleanly (no ERROR)
  • xct (main, go@main): no change expected (decrypt failures are a platform bug)
  • All other xtest jobs: unaffected

🤖 Generated with Claude Code

… error detection

Two bugs causing spurious CI failures in test_pqc.py when testing against
older platform versions:

1. **`tdfs.py` version threshold** — `mechanism-xwing` and
   `mechanism-secpmlkem` were gated at `>= (0, 14, 0)`, but the
   key management API for hpqt:* algorithms didn't land until after
   `service/v0.15.0`. Platform v0.15.0 rejects them with a protobuf
   validation error (`key_algorithm_defined`), causing tests to ERROR
   (fixture crash) rather than SKIP. Raise threshold to `(0, 16, 0)`.

2. **`otdfctl.py` error string** — `kas_registry_create_key` only matched
   `"Invalid key parameters: invalid algorithm"` to raise `InvalidAlgorithm`.
   Platform v0.15.0 returns `"key_algorithm_defined"` (a protobuf validation
   error), which fell through to a bare `AssertionError`, turning what should
   be a pytest.skip into a test ERROR. Extend the match condition.

These fixes target PR #461 (fix/DSPX-3356-xwing-kao-size-assertions) which
was failing on `xct (v0.15.0, go@v0.32.0)` for exactly these reasons.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@dmihalcik-virtru dmihalcik-virtru requested review from a team as code owners May 22, 2026 19:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • main

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e91d28da-03a4-4c27-9901-89eb8f7c8354

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/DSPX-3356-ci-prereqs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the error handling in otdfctl.py to include a new validation error string and adjusts the version requirement for hybrid PQ/T KEM support in tdfs.py to version 0.16.0. Feedback was provided to add a descriptive comment for the new error string to improve code maintainability.

Comment thread xtest/otdfctl.py
Comment on lines +315 to +318
if (
"Invalid key parameters: invalid algorithm" in err_str
or "key_algorithm_defined" in err_str
):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this string matching correctly identifies the specific protobuf validation error returned by platform v0.15.0, it is a bit of a "magic string" that lacks context in the code. Adding a brief comment explaining that this string corresponds to a specific platform version's error response would improve maintainability.

            if (
                "Invalid key parameters: invalid algorithm" in err_str
                # Platform v0.15.0 returns this protobuf validation error for unsupported algorithms
                or "key_algorithm_defined" in err_str
            ):

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.

1 participant