From e684e79eb22c7382cfad0ad925d8a47c52b53f14 Mon Sep 17 00:00:00 2001 From: Venkata Saidurga Polamraju Date: Fri, 9 Aug 2024 12:38:06 +0530 Subject: [PATCH] [ES-1347] Signed-off-by: Venkata Saidurga Polamraju --- .../AuthorizationHelperServiceTest.java | 35 ++++++++++++++----- .../services/AuthorizationServiceTest.java | 16 +++++++-- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationHelperServiceTest.java b/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationHelperServiceTest.java index 1ab3db325..3fb89f888 100644 --- a/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationHelperServiceTest.java +++ b/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationHelperServiceTest.java @@ -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 challengeList = new ArrayList<>(); @@ -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 @@ -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")); @@ -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 @@ -644,8 +654,12 @@ 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 @@ -653,8 +667,13 @@ 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) { diff --git a/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java b/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java index e251c0918..b5c55d880 100644 --- a/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java +++ b/oidc-service-impl/src/test/java/io/mosip/esignet/services/AuthorizationServiceTest.java @@ -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 @@ -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) {