diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml index efaf724..a3e74c7 100644 --- a/.github/workflows/build-and-publish.yaml +++ b/.github/workflows/build-and-publish.yaml @@ -40,6 +40,5 @@ jobs: java_version: ${{ inputs.java_version }} publish_vulnerabilities: ${{ inputs.publish_vulnerabilities }} vulnerability_failure_severity: ${{ inputs.vulnerability_failure_severity }} - skip_tests: true # No tests are present in this repository merge_environment: ${{ github.ref_protected && 'ci-auto-merge' || '' }} secrets: inherit diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index cf151cd..672f3a5 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -7,4 +7,3 @@ jobs: secrets: inherit with: java_version: 21 - skip_tests: true # No tests are present in this repository diff --git a/pom.xml b/pom.xml index 071a495..70a3e63 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,12 @@ - + + junit + junit + 4.13.2 + test + diff --git a/src/test/java/com/uid2/enclave/AttestationExceptionTest.java b/src/test/java/com/uid2/enclave/AttestationExceptionTest.java new file mode 100644 index 0000000..363e6e1 --- /dev/null +++ b/src/test/java/com/uid2/enclave/AttestationExceptionTest.java @@ -0,0 +1,21 @@ +package com.uid2.enclave; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class AttestationExceptionTest { + @Test + public void testConstructWithMessage() { + AttestationException e = new AttestationException("boom"); + assertEquals("boom", e.getMessage()); + assertNull(e.getCause()); + } + + @Test + public void testConstructWithCause() { + Throwable cause = new RuntimeException("root"); + AttestationException e = new AttestationException(cause); + assertSame(cause, e.getCause()); + assertNotNull(e.getMessage()); + } +} diff --git a/src/test/java/com/uid2/enclave/IAttestationProviderTest.java b/src/test/java/com/uid2/enclave/IAttestationProviderTest.java new file mode 100644 index 0000000..8fe4588 --- /dev/null +++ b/src/test/java/com/uid2/enclave/IAttestationProviderTest.java @@ -0,0 +1,25 @@ +package com.uid2.enclave; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class IAttestationProviderTest { + @Test + public void testIsReadyDefaultsTrue() { + IAttestationProvider p = (publicKey, userData) -> new byte[0]; + assertTrue(p.isReady()); + } + + @Test + public void testGetAttestationRequestReturnsBytes() throws AttestationException { + byte[] expected = new byte[]{0x01, 0x02}; + IAttestationProvider p = (publicKey, userData) -> expected; + assertArrayEquals(expected, p.getAttestationRequest(new byte[0], new byte[0])); + } + + @Test(expected = AttestationException.class) + public void testGetAttestationRequestCanThrowAttestationException() throws AttestationException { + IAttestationProvider p = (publicKey, userData) -> { throw new AttestationException("fail"); }; + p.getAttestationRequest(new byte[0], new byte[0]); + } +} diff --git a/src/test/java/com/uid2/enclave/IOperatorKeyRetrieverTest.java b/src/test/java/com/uid2/enclave/IOperatorKeyRetrieverTest.java new file mode 100644 index 0000000..23d030f --- /dev/null +++ b/src/test/java/com/uid2/enclave/IOperatorKeyRetrieverTest.java @@ -0,0 +1,12 @@ +package com.uid2.enclave; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class IOperatorKeyRetrieverTest { + @Test + public void testRetrieveReturnsKey() { + IOperatorKeyRetriever retriever = () -> "test-key"; + assertEquals("test-key", retriever.retrieve()); + } +}