forked from eclipse-vertx/vertx-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebAuthn: Add user id to PublicKeyCredentialsCreateOptions, Authentic…
…ator and WebAuthnCredentials (eclipse-vertx#580, eclipse-vertx#581)
- Loading branch information
Showing
9 changed files
with
244 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package io.vertx.ext.auth.webauthn; | ||
|
||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.auth.impl.Codec; | ||
import io.vertx.ext.unit.Async; | ||
import io.vertx.ext.unit.TestContext; | ||
import io.vertx.ext.unit.junit.RunTestOnContext; | ||
|
@@ -10,7 +12,13 @@ | |
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import javax.naming.AuthenticationException; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
@RunWith(VertxUnitRunner.class) | ||
public class NavigatorCredentialsCreate { | ||
|
@@ -36,10 +44,19 @@ public void testRequestRegister(TestContext should) { | |
.authenticatorFetcher(database::fetch) | ||
.authenticatorUpdater(database::store); | ||
|
||
final String userId = UUID.randomUUID().toString(); | ||
|
||
// Authenticator to test excludedCredentials | ||
database.add( | ||
new Authenticator() | ||
.setUserId(Codec.base64UrlEncode(userId.getBytes())) | ||
.setType("public-key") | ||
.setCredID("-r1iW_eHUyIpU93f77odIrdUlNVfYzN-JPCTWGtdn-1wxdLxhlS9NmzLNbYsQ7XVZlGSWbh_63E5oFHcNh4JNw") | ||
); | ||
|
||
// Dummy user | ||
JsonObject user = new JsonObject() | ||
// id is expected to be a base64url string | ||
.put("id", "000000000000000000000000") | ||
.put("id", userId) | ||
.put("name", "[email protected]") | ||
.put("displayName", "John Doe") | ||
.put("icon", "https://pics.example.com/00/p/aBjjjpqPb.png"); | ||
|
@@ -56,7 +73,75 @@ public void testRequestRegister(TestContext should) { | |
assertNotNull(challengeResponse.getJsonArray("pubKeyCredParams")); | ||
// ensure that challenge and user.id are base64url encoded | ||
assertNotNull(challengeResponse.getBinary("challenge")); | ||
assertNotNull(challengeResponse.getJsonObject("user").getBinary("id")); | ||
|
||
final JsonObject challengeResponseUser = challengeResponse.getJsonObject("user"); | ||
assertNotNull(challengeResponseUser); | ||
assertArrayEquals(user.getString("id").getBytes(), Codec.base64UrlDecode(challengeResponseUser.getString("id"))); | ||
assertEquals(user.getString("name"), challengeResponseUser.getString("name")); | ||
assertEquals(user.getString("displayName"), challengeResponseUser.getString("displayName")); | ||
assertEquals(user.getString("icon"), challengeResponseUser.getString("icon")); | ||
|
||
final JsonArray excludeCredentials = challengeResponse.getJsonArray("excludeCredentials"); | ||
assertEquals(1, excludeCredentials.size()); | ||
|
||
final JsonObject excludeCredential = excludeCredentials.getJsonObject(0); | ||
assertEquals("public-key", excludeCredential.getString("type")); | ||
assertEquals("-r1iW_eHUyIpU93f77odIrdUlNVfYzN-JPCTWGtdn-1wxdLxhlS9NmzLNbYsQ7XVZlGSWbh_63E5oFHcNh4JNw", excludeCredential.getString("id")); | ||
assertEquals(new JsonArray(Arrays.asList("usb", "nfc", "ble", "internal")), excludeCredential.getJsonArray("transports")); | ||
|
||
test.complete(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRequestRegisterWithRawId(TestContext should) { | ||
final Async test = should.async(); | ||
|
||
WebAuthn webAuthN = WebAuthn.create( | ||
rule.vertx(), | ||
new WebAuthnOptions().setRelyingParty(new RelyingParty().setName("ACME Corporation")) | ||
.setAttestation(Attestation.of("direct"))) | ||
.authenticatorFetcher(database::fetch) | ||
.authenticatorUpdater(database::store); | ||
|
||
// Dummy user | ||
JsonObject user = new JsonObject() | ||
.put("rawId", "000000000000000000000000") | ||
.put("displayName", "John Doe"); | ||
|
||
webAuthN | ||
.createCredentialsOptions(user) | ||
.onFailure(should::fail) | ||
.onSuccess(challengeResponse -> { | ||
final JsonObject challengeResponseUser = challengeResponse.getJsonObject("user"); | ||
assertNotNull(challengeResponseUser); | ||
assertEquals("rawId should have been used as-is", user.getString("rawId"), challengeResponseUser.getString("id")); | ||
test.complete(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRequestRegisterWithNoId(TestContext should) { | ||
final Async test = should.async(); | ||
|
||
WebAuthn webAuthN = WebAuthn.create( | ||
rule.vertx(), | ||
new WebAuthnOptions().setRelyingParty(new RelyingParty().setName("ACME Corporation")) | ||
.setAttestation(Attestation.of("direct"))) | ||
.authenticatorFetcher(database::fetch) | ||
.authenticatorUpdater(database::store); | ||
|
||
// Dummy user | ||
JsonObject user = new JsonObject() | ||
.put("displayName", "John Doe"); | ||
|
||
webAuthN | ||
.createCredentialsOptions(user) | ||
.onFailure(should::fail) | ||
.onSuccess(challengeResponse -> { | ||
final JsonObject challengeResponseUser = challengeResponse.getJsonObject("user"); | ||
assertNotNull(challengeResponseUser); | ||
assertNotNull("random id should have been generated", challengeResponseUser.getBinary("id")); | ||
test.complete(); | ||
}); | ||
} | ||
|
Oops, something went wrong.