Skip to content

Commit 2370f12

Browse files
committed
Test that the right exception is thrown when BouncyCastle is needed but fails to load
1 parent d72a2c0 commit 2370f12

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

test-dependent-projects/java-dep-webauthn-server-core-minimal/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ plugins {
22
`java-library`
33
}
44

5+
val coreTestsOutput = project(":webauthn-server-core-minimal").extensions.getByType(SourceSetContainer::class).test.get().output
6+
57
dependencies {
68
implementation(project(":webauthn-server-core-minimal"))
9+
10+
testImplementation(coreTestsOutput)
711
testImplementation("junit:junit:4.12")
812
testImplementation("org.mockito:mockito-core:[2.27.0,3)")
13+
14+
// Runtime-only internal dependency of webauthn-server-core-minimal
15+
testImplementation("com.augustcellars.cose:cose-java:[1.0.0,2)")
16+
17+
// Transitive dependencies from coreTestOutput
18+
testImplementation("org.scala-lang:scala-library:[2.13.1,3)")
919
}

test-dependent-projects/java-dep-webauthn-server-core-minimal/src/test/java/com/yubico/webauthn/BouncyCastleProviderPresenceTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package com.yubico.webauthn;
22

3+
import COSE.CoseException;
4+
import com.yubico.webauthn.data.AttestationObject;
35
import com.yubico.webauthn.data.RelyingPartyIdentity;
6+
import java.io.IOException;
7+
import java.security.NoSuchAlgorithmException;
8+
import java.security.PublicKey;
9+
import java.security.spec.InvalidKeySpecException;
410
import org.junit.Test;
511
import org.mockito.Mockito;
612

713
import java.security.Security;
814
import java.util.Arrays;
915

1016
import static org.junit.Assert.assertTrue;
17+
import static org.junit.Assert.fail;
1118

1219
/**
1320
* Test that the BouncyCastle provider is not loaded by default
@@ -46,4 +53,26 @@ public void bouncyCastleProviderIsNotLoadedAfterInstantiatingRelyingParty() {
4653
));
4754
}
4855

56+
@Test
57+
public void bouncyCastleProviderIsNotLoadedAfterAttemptingToLoadEddsaKey() throws IOException, CoseException, NoSuchAlgorithmException, InvalidKeySpecException {
58+
try {
59+
WebAuthnCodecs.importCosePublicKey(
60+
new AttestationObject(RegistrationTestData.Packed$.MODULE$.BasicAttestationEdDsa().attestationObject())
61+
.getAuthenticatorData()
62+
.getAttestedCredentialData()
63+
.get()
64+
.getCredentialPublicKey()
65+
);
66+
} catch (NoSuchAlgorithmException e) {
67+
// OK
68+
}
69+
70+
assertTrue(
71+
Arrays.stream(Security.getProviders())
72+
.noneMatch(prov ->
73+
prov.getName().equals("BC")
74+
|| prov.getClass().getCanonicalName().contains("bouncy")
75+
));
76+
}
77+
4978
}

0 commit comments

Comments
 (0)