UID2-7015: add unit tests for attestation-aws#34
Merged
Conversation
- Add explanatory comment to UnsatisfiedLinkError catch in NitroAttestation static initializer - Add ArgumentCaptor to testReturnsSlicedBuffer to verify publicKey/userData argument wiring - Add comment to testIsReadyDefaultTrue clarifying it tests the interface default Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sophia-chen-ttd
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
Design decisions
Why the
result > 0branch ingenerateAttestationRequestis not directly unit-testedThat method's only collaborator is
private static native generateAttestationRequestInternal, which has no implementation in a test JVM. Mockito cannot stub private methods, so the branch can't be driven without either (a) relaxing the native method to package-private purely for tests, or (b) pulling in PowerMock to mock a private/native call. Both were rejected:uid2-attestation-gcp/uid2-attestation-azure(which the ticket asks us to mirror).The branch itself is trivial glue, and its parts are already covered:
NitroException.fromErrorCodeis exhaustively unit-tested (all error codes + unknown paths), andNitroAttestationProviderTestcovers both the success-slice path and the error →AttestationExceptionwrapping path. Verified empirically that there is no zero-production-change way to test it: amockStaticcustom-Answerattempt to intercept only the inner native call still hitsUnsatisfiedLinkError, because Mockito does not route the internally-called private static through the mock.Why
System.loadLibrary("jnsm")is wrapped in try-catchNitroAttestationProviderTestusesmockStatic(NitroAttestation.class), which forces the JVM to load and initialize the class. The static initializer'sSystem.loadLibrary("jnsm")throwsUnsatisfiedLinkErrorin any JVM without the native library (i.e. CI / local test). Without the catch, Mockito's static-mock setup fails (Internal class redefinition failed: invalid class) and the provider tests cannot run.Catching
UnsatisfiedLinkErroris behaviorally inert in production: on a real Nitro enclavelibjnsm.sois always present, so the class initializes identically to before. The only difference is in a library-absent environment, where the failure shifts from class-load time to first native-call time —generateAttestationRequestInternalstill throwsUnsatisfiedLinkErroron first use. Verified empirically: reverting to the bareloadLibrarycall fails exactly the twomockStatic-based provider tests (14/16 pass); with the catch all 16 pass.Jira: UID2-7015