Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ jobs:
publish_vulnerabilities: ${{ inputs.publish_vulnerabilities }}
vulnerability_failure_severity: ${{ inputs.vulnerability_failure_severity }}
working_dir: attestation-aws
skip_tests: true # No tests are present in this repository
merge_environment: ${{ github.ref_protected && 'ci-auto-merge' || '' }}
secrets: inherit
1 change: 0 additions & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ jobs:
with:
working_dir: attestation-aws/
java_version: 21
skip_tests: true # No tests are present in this repository
12 changes: 12 additions & 0 deletions attestation-aws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
<artifactId>uid2-attestation-api</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public static NitroAttestationRequest generateAttestationRequest(NitroAttestatio
}

static {
System.loadLibrary("jnsm");
try {
System.loadLibrary("jnsm");
} catch (UnsatisfiedLinkError ignored) {
// Intentionally ignored in non-Nitro environments (e.g. test JVMs without jnsm).
// generateAttestationRequestInternal() will throw UnsatisfiedLinkError on first call.
}
}

private static native int generateAttestationRequestInternal(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.uid2.attestation.aws;

import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNull;

public class NitroAttestationParamsTest {
@Test
public void testConstructorAssignsFields() {
byte[] userData = {1, 2, 3};
byte[] publicKey = {4, 5};
byte[] nonce = {6};
NitroAttestationParams p = new NitroAttestationParams(userData, publicKey, nonce);
assertArrayEquals(userData, p.userData);
assertArrayEquals(publicKey, p.publicKey);
assertArrayEquals(nonce, p.nonce);
}

@Test
public void testNullNonceAllowed() {
NitroAttestationParams p = new NitroAttestationParams(new byte[]{1}, new byte[]{2}, null);
assertNull(p.nonce);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.uid2.attestation.aws;

import com.uid2.enclave.AttestationException;
import org.junit.Test;
import org.mockito.MockedStatic;

import org.mockito.ArgumentCaptor;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mockStatic;

public class NitroAttestationProviderTest {

@Test
public void testReturnsSlicedBuffer() throws AttestationException {
byte[] fullBuffer = new byte[20000];
fullBuffer[0] = 1; fullBuffer[1] = 2; fullBuffer[2] = 3;
NitroAttestationRequest stub = new NitroAttestationRequest(fullBuffer, 3);

try (MockedStatic<NitroAttestation> mocked = mockStatic(NitroAttestation.class)) {
ArgumentCaptor<NitroAttestationParams> captor = ArgumentCaptor.forClass(NitroAttestationParams.class);
mocked.when(() -> NitroAttestation.generateAttestationRequest(captor.capture())).thenReturn(stub);

byte[] result = new NitroAttestationProvider()
.getAttestationRequest(new byte[]{9}, new byte[]{8});

assertArrayEquals(new byte[]{1, 2, 3}, result);
assertArrayEquals(new byte[]{9}, captor.getValue().publicKey);
assertArrayEquals(new byte[]{8}, captor.getValue().userData);
assertNull(captor.getValue().nonce);
}
}

@Test
public void testWrapsNitroExceptionAsAttestationException() {
try (MockedStatic<NitroAttestation> mocked = mockStatic(NitroAttestation.class)) {
NitroException root = NitroException.fromErrorCode(-1);
mocked.when(() -> NitroAttestation.generateAttestationRequest(any())).thenThrow(root);

try {
new NitroAttestationProvider().getAttestationRequest(new byte[0], new byte[0]);
fail("expected AttestationException");
} catch (AttestationException e) {
assertSame(root, e.getCause());
}
}
}

@Test
public void testIsReadyDefaultTrue() {
// NitroAttestationProvider delegates to IAttestationProvider.isReady() default (always true)
assertTrue(new NitroAttestationProvider().isReady());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.uid2.attestation.aws;

import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class NitroAttestationRequestTest {
@Test
public void testGetters() {
byte[] data = {10, 20, 30, 0, 0};
NitroAttestationRequest r = new NitroAttestationRequest(data, 3);
assertArrayEquals(data, r.getData());
assertEquals(3, r.getLength());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.uid2.attestation.aws;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class NitroExceptionTest {
@Test public void testInvalidArgument() { assertEquals("Invalid Argument", NitroException.fromErrorCode(-1).getMessage()); }
@Test public void testInvalidIndex() { assertEquals("Invalid Index", NitroException.fromErrorCode(-2).getMessage()); }
@Test public void testInvalidResponse() { assertEquals("Invalid Response", NitroException.fromErrorCode(-3).getMessage()); }
@Test public void testReadonlyIndex() { assertEquals("Readonly Index", NitroException.fromErrorCode(-4).getMessage()); }
@Test public void testInvalidOperation() { assertEquals("Invalid Operation", NitroException.fromErrorCode(-5).getMessage()); }
@Test public void testBufferTooSmall() { assertEquals("Buffer too small", NitroException.fromErrorCode(-6).getMessage()); }
@Test public void testInputTooLarge() { assertEquals("Input too large", NitroException.fromErrorCode(-7).getMessage()); }
@Test public void testInternalError() { assertEquals("Internal Error", NitroException.fromErrorCode(-8).getMessage()); }
@Test public void testUnknownPositive() { assertEquals("Unknown Error", NitroException.fromErrorCode(42).getMessage()); }
@Test public void testUnknownNegative() { assertEquals("Unknown Error", NitroException.fromErrorCode(-9).getMessage()); }
}
Loading