Skip to content

Commit

Permalink
[ES-1347]
Browse files Browse the repository at this point in the history
Signed-off-by: Venkata Saidurga Polamraju <[email protected]>
  • Loading branch information
pvsaidurga committed Aug 9, 2024
1 parent b3b9512 commit e684e79
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void delegateAuthenticateRequest_withInvalidResult_thenFail() throws KycA
}

@Test
public void delegateAuthenticateRequest_withInValidDetails_thenFail() throws KycAuthException {
public void delegateAuthenticateRequest_ThrowsKycAuthException_thenFail() throws KycAuthException {
String transactionId = "transaction-id";
String individualId = "individual-id";
List<AuthChallenge> challengeList = new ArrayList<>();
Expand All @@ -298,7 +298,12 @@ public void delegateAuthenticateRequest_withInValidDetails_thenFail() throws Kyc
oidcTransaction.setAuthTransactionId("auth-transaction-id");
oidcTransaction.setRequestedClaims(new Claims());
Mockito.when(authenticationWrapper.doKycAuth(Mockito.anyString(), Mockito.anyString(), anyBoolean(), any(KycAuthDto.class))).thenThrow(KycAuthException.class);
Assert.assertThrows(EsignetException.class,()->authorizationHelperService.delegateAuthenticateRequest(transactionId, individualId, challengeList, oidcTransaction));
try{
authorizationHelperService.delegateAuthenticateRequest(transactionId, individualId, challengeList, oidcTransaction);
Assert.fail();
}catch (EsignetException e) {
Assert.assertEquals(null,e.getErrorCode());
}
}

@Test
Expand Down Expand Up @@ -489,7 +494,7 @@ public void delegateSendOtpRequest_withInvalidTransactionId_thenFail() throws Se
}

@Test
public void delegateSendOtpRequest_withInvalidDetail_thenFail() throws SendOtpException {
public void delegateSendOtpRequest_withThrowsSendOtpException_thenFail() throws SendOtpException {
OtpRequest otpRequest = new OtpRequest();
otpRequest.setIndividualId("individual-id");
otpRequest.setOtpChannels(Arrays.asList("email"));
Expand All @@ -499,7 +504,12 @@ public void delegateSendOtpRequest_withInvalidDetail_thenFail() throws SendOtpEx
oidcTransaction.setClientId("client-id");
SendOtpResult sendOtpResult = new SendOtpResult("temp-id", "masked-email", "masked-mobile");
Mockito.when(authenticationWrapper.sendOtp(Mockito.anyString(), Mockito.anyString(), any(SendOtpDto.class))).thenThrow(SendOtpException.class);
Assert.assertThrows(EsignetException.class,()->authorizationHelperService.delegateSendOtpRequest(otpRequest, oidcTransaction));
try {
authorizationHelperService.delegateSendOtpRequest(otpRequest, oidcTransaction);
Assert.fail();
}catch(EsignetException e){
Assert.assertEquals(null,e.getErrorCode());
}
}

@Test
Expand Down Expand Up @@ -644,17 +654,26 @@ public void testHandleInternalAuthenticateRequest_NoCookie_thenFail() {
authChallenge.setChallenge("base64encodedchallenge");
OIDCTransaction transaction = new OIDCTransaction();
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
Assert.assertThrows(EsignetException.class, () ->
authorizationHelperService.handleInternalAuthenticateRequest(authChallenge, transaction, httpServletRequest));
try{
authorizationHelperService.handleInternalAuthenticateRequest(authChallenge, transaction, httpServletRequest);
Assert.fail();
}catch(EsignetException e){
Assert.assertEquals("auth_failed",e.getErrorCode());
}
}

@Test
public void testHandleInternalAuthenticateRequest_NoHaltedTransaction_thenFail() {
AuthChallenge authChallenge = new AuthChallenge();
authChallenge.setChallenge("base64encodedchallenge");
OIDCTransaction transaction = new OIDCTransaction();
Assert.assertThrows(EsignetException.class, () ->
authorizationHelperService.handleInternalAuthenticateRequest(authChallenge, transaction, httpServletRequest));
try {
authorizationHelperService.handleInternalAuthenticateRequest(authChallenge, transaction, httpServletRequest);
Assert.fail();
}catch(EsignetException e)
{
Assert.assertEquals("auth_failed",e.getErrorCode());
}
}

private Cookie[] createMockCookies(String subject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,18 @@ public void getAuthCode_withValidInput_thenPass() {
}

@Test
public void getAuthCode_withInValidTransaction_thenFail() {
public void getAuthCode_withInValidTransactionId_thenFail() {
AuthCodeRequest authCodeRequest = new AuthCodeRequest();
authCodeRequest.setTransactionId("987654321");
authCodeRequest.setAcceptedClaims(Arrays.asList("fullName"));
authCodeRequest.setPermittedAuthorizeScopes(Arrays.asList("test-scope"));
Mockito.when(cacheUtilService.getAuthenticatedTransaction(Mockito.anyString())).thenReturn(null);
Assert.assertThrows(InvalidTransactionException.class,()->authorizationServiceImpl.getAuthCode(authCodeRequest));
try{
authorizationServiceImpl.getAuthCode(authCodeRequest);
Assert.fail();
}catch (EsignetException e){
Assert.assertEquals("invalid_transaction",e.getErrorCode());
}
}

@Test
Expand Down Expand Up @@ -1259,7 +1264,12 @@ public void sendOtp_invalidTransactionId_thenFail() throws Exception {
OtpRequest otpRequest = new OtpRequest();
otpRequest.setTransactionId("invalidTransactionId");
when(cacheUtilService.getPreAuthTransaction("invalidTransactionId")).thenReturn(null);
assertThrows(InvalidTransactionException.class, () -> authorizationServiceImpl.sendOtp(otpRequest));
try{
authorizationServiceImpl.sendOtp(otpRequest);
Assert.fail();
}catch(EsignetException e){
Assert.assertEquals("invalid_transaction",e.getErrorCode());
}
}

private OIDCTransaction createIdpTransaction(String[] acrs) {
Expand Down

0 comments on commit e684e79

Please sign in to comment.