Skip to content

Commit

Permalink
Add an origins(Optional) setter
Browse files Browse the repository at this point in the history
  • Loading branch information
fdennis committed Jan 24, 2025
1 parent 0cbba57 commit ecfae42
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,16 @@ public static class RelyingPartyBuilder {
Optional.empty();
private @NonNull Optional<AttestationTrustSource> attestationTrustSource = Optional.empty();

public RelyingPartyBuilder origins(@NonNull Set<String> origins) {
this.origins = origins;
return this;
}

public RelyingPartyBuilder origins(Optional<Set<String>> origins) {
this.origins = origins.orElse(null);
return this;
}

public static class MandatoryStages {
private final RelyingPartyBuilder builder = new RelyingPartyBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,64 @@ public void originsIsImmutable() {
}
}

@Test
public void testOriginsWithEmptySet() {
Set<String> origins = new HashSet<>();

RelyingParty rp =
RelyingParty.builder()
.identity(RelyingPartyIdentity.builder().id("localhost").name("Test").build())
.credentialRepository(unimplementedCredentialRepository())
.origins(origins)
.build();

assertEquals(0, rp.getOrigins().size());
}

@Test
public void testOriginsWithSet() {
Set<String> origins = new HashSet<>();
origins.add("test1");
origins.add("test2");

RelyingParty rp =
RelyingParty.builder()
.identity(RelyingPartyIdentity.builder().id("localhost").name("Test").build())
.credentialRepository(unimplementedCredentialRepository())
.origins(origins)
.build();

assertEquals(2, rp.getOrigins().size());
}

@Test
public void testOriginsWithEmptyOptionalSet() {
RelyingParty rp =
RelyingParty.builder()
.identity(RelyingPartyIdentity.builder().id("localhost").name("Test").build())
.credentialRepository(unimplementedCredentialRepository())
.origins(Optional.empty())
.build();

assertEquals(1, rp.getOrigins().size());
}

@Test
public void testOriginsWithOptionalSet() {
Set<String> origins = new HashSet<>();
origins.add("test1");
origins.add("test2");

RelyingParty rp =
RelyingParty.builder()
.identity(RelyingPartyIdentity.builder().id("localhost").name("Test").build())
.credentialRepository(unimplementedCredentialRepository())
.origins(Optional.of(origins))
.build();

assertEquals(2, rp.getOrigins().size());
}

@Test
public void filtersAlgorithmsToThoseAvailable() throws HexException {
for (Provider prov : Security.getProviders()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class RelyingPartyStartOperationSpec
.identity(rpId)
.credentialRepository(credRepo(credentials, userId))
.preferredPubkeyParams(List(PublicKeyCredentialParameters.ES256).asJava)
.origins(Set.empty.asJava)
.origins(Set.empty[String].asJava)
appId.foreach { appid => builder = builder.appId(appid) }
attestationConveyancePreference.foreach { acp =>
builder = builder.attestationConveyancePreference(acp)
Expand Down

0 comments on commit ecfae42

Please sign in to comment.