Skip to content

Commit

Permalink
Done with writing test cases for the origin which is not exists in li…
Browse files Browse the repository at this point in the history
…st and handle success case for multiple origins
  • Loading branch information
imran-ishaq committed Jan 8, 2025
1 parent 4fa6699 commit 3364ee4
Showing 1 changed file with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.jans.fido2.service.processors.AttestationFormatProcessor;
import io.jans.service.net.NetworkService;
import jakarta.enterprise.inject.Instance;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import org.bouncycastle.util.encoders.Hex;
Expand All @@ -33,9 +34,7 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -116,6 +115,47 @@ void verifyRpDomain_originIsNull_valid() {
assertEquals(response, "test.domain");
}


@Test
void verifyRpDomain_originMatchesValidOrigin_valid() {
String origin = "https://test.bank.com";
String rpId = "bank.com";
List<RequestedParty> requestedParties = new ArrayList<>();
RequestedParty rp = new RequestedParty();
rp.setOrigins(Arrays.asList("test.bank.com", "emp.bank.com", "india.bank.com"));
requestedParties.add(rp);

when(networkService.getHost(origin)).thenReturn("test.bank.com");

String response = commonVerifiers.verifyRpDomain(origin, rpId, requestedParties);

assertNotNull(response);
assertEquals("test.bank.com", response);
}

@Test
void verifyRpDomain_originDoesNotMatchValidOrigins_invalid() {
String origin = "https://test.bank1.com";
String rpId = "bank.com";
List<RequestedParty> requestedParties = new ArrayList<>();
RequestedParty rp = new RequestedParty();
rp.setOrigins(Arrays.asList("test.bank.com", "emp.bank.com", "india.bank.com"));
requestedParties.add(rp);

when(networkService.getHost(origin)).thenReturn("test.bank1.com");

// Here we mock the errorResponseFactory to throw a BadRequestException
when(errorResponseFactory.badRequestException(any(), anyString()))
.thenThrow(new BadRequestException("The origin '\" + origin + \"' is not listed in the allowed origins."));

// Expecting an exception when the origin doesn't match any of the allowed origins
BadRequestException exception = assertThrows(BadRequestException.class, () -> {
commonVerifiers.verifyRpDomain(origin, rpId, requestedParties);
});

assertEquals("The origin '\" + origin + \"' is not listed in the allowed origins.", exception.getMessage());
}

@Test
void verifyCounter_oldAndNewCounterZero_valid() {
int oldCounter = 0;
Expand Down

0 comments on commit 3364ee4

Please sign in to comment.