Skip to content

Commit

Permalink
[ES-1043] ConsentDetails service implementation (#700)
Browse files Browse the repository at this point in the history
* added consentDetail endpoint and implementation

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>

* added testcase for consentDetetails

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>

* removed getConsentAction method

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>

* removed unwanted code from AuthorizationServiceTest class

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>

* added test case for getConsentDetails api

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>

* review changes

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>

---------

Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>
Co-authored-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>
  • Loading branch information
kaifk468 and Mohd Kaif Siddique authored May 23, 2024
1 parent c91a723 commit 5a5557c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ public class OIDCTransaction implements Serializable {
//PKCE support
ProofKeyCodeExchange proofKeyCodeExchange;
List<String> requestedCredentialScopes;
List<ClaimStatus> claimStatuses;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,11 @@ public interface AuthorizationService {
* @return
*/
SignupRedirectResponse prepareSignupRedirect(SignupRedirectRequest signupRedirectRequest, HttpServletResponse response);

/**
* Get the ClaimStatus and check the consent Action
* @param transactionId
* @return
*/
ConsentDetailResponse getConsentDetails(String transactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static io.mosip.esignet.core.constants.Constants.UTC_DATETIME_PATTERN;
import static io.mosip.esignet.core.constants.ErrorConstants.*;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -1140,4 +1141,11 @@ public void getAuthorizationCode_withInValidPermittedAuthorizeScopes_thenErrorRe
.andExpect(jsonPath("$.errors[0].errorCode").value(ErrorConstants.INVALID_PERMITTED_SCOPE));
}

@Test
public void getConsentDetails_withValidDetails_thenSuccessResposne() throws Exception {
mockMvc.perform(get("/authorization/consent-details").header("oauth-details-key", "1234567890"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.response.consentAction").value("CAPTURE"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ public AuthCodeResponse getAuthCode(AuthCodeRequest authCodeRequest) throws Esig
return authCodeResponse;
}

@Override
public ConsentDetailResponse getConsentDetails(String transactionId) {
OIDCTransaction transaction = cacheUtilService.getAuthenticatedTransaction(transactionId);
if(transaction == null) {
throw new InvalidTransactionException();
}
ConsentDetailResponse consentDetailResponse=new ConsentDetailResponse();
consentDetailResponse.setConsentAction(transaction.getConsentAction());
consentDetailResponse.setTransactionId(transactionId);
consentDetailResponse.setClaimStatus(transaction.getClaimStatuses());
return consentDetailResponse;
}


private OIDCTransaction authenticate(AuthRequest authRequest, boolean checkConsentAction) {
OIDCTransaction transaction = cacheUtilService.getPreAuthTransaction(authRequest.getTransactionId());
if(transaction == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void processConsent(OIDCTransaction transaction, boolean linked) {
}
}


public void updateUserConsent(OIDCTransaction transaction, String signature) {
if(ConsentAction.NOCAPTURE.equals(transaction.getConsentAction())
&& transaction.getEssentialClaims().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import io.mosip.esignet.api.exception.KycAuthException;
import io.mosip.esignet.api.spi.AuditPlugin;
import io.mosip.esignet.api.spi.Authenticator;
import io.mosip.esignet.api.util.ConsentAction;
import io.mosip.esignet.core.constants.Constants;
import io.mosip.esignet.core.dto.*;
import io.mosip.esignet.core.exception.EsignetException;
import io.mosip.esignet.core.exception.InvalidClientException;
import io.mosip.esignet.core.exception.InvalidTransactionException;
import io.mosip.esignet.core.spi.ClientManagementService;
import io.mosip.esignet.core.util.AuthenticationContextClassRefUtil;
import io.mosip.esignet.core.constants.ErrorConstants;
Expand Down Expand Up @@ -1004,6 +1006,32 @@ public void getAuthCode_withValidInput_thenPass() {
Assert.assertEquals(authorizationServiceImpl.getAuthCode(authCodeRequest).getState(), "test-state");
}

@Test
public void getConsentDetails_withValidTransaction_thenPass(){
OIDCTransaction transaction=new OIDCTransaction();
ClaimStatus claimStatus=new ClaimStatus();
claimStatus.setClaim("email");
claimStatus.setVerified(true);
claimStatus.setAvailable(true);
transaction.setClaimStatuses(List.of(claimStatus));
transaction.setConsentAction(ConsentAction.NOCAPTURE);
Mockito.when(cacheUtilService.getAuthenticatedTransaction(Mockito.anyString())).thenReturn(transaction);

ConsentDetailResponse consentDetailResponse = authorizationServiceImpl.getConsentDetails("transactionId");
Assert.assertEquals(consentDetailResponse.getConsentAction(),ConsentAction.NOCAPTURE);
Assert.assertEquals(consentDetailResponse.getTransactionId(),"transactionId");
}

@Test
public void getConsentDetails_withInvalidTransaction_thenFail(){
Mockito.when(cacheUtilService.getAuthenticatedTransaction(Mockito.anyString())).thenReturn(null);
try{
authorizationServiceImpl.getConsentDetails("transactionId");
}catch (InvalidTransactionException ex){
Assert.assertEquals(ex.getErrorCode(),ErrorConstants.INVALID_TRANSACTION);
}
}

private OIDCTransaction createIdpTransaction(String[] acrs) {
OIDCTransaction oidcTransaction = new OIDCTransaction();
Map<String, ClaimDetail> idClaims = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ public void processConsent_withInvalidSignature_thenFail(){
consentDetail.setSignature("haa.naa");

Mockito.when(consentService.getUserConsent(userConsentRequest)).thenReturn(Optional.of(consentDetail));

try{
consentHelperService.processConsent(oidcTransaction,true);
Assert.fail();
Expand All @@ -482,6 +481,7 @@ public void processConsent_withEmptyRequestedClaims_thenPass(){
Assert.assertEquals(oidcTransaction.getConsentAction(),ConsentAction.NOCAPTURE);
}


private String generateSignature(Map<String,Object> payloadMap) throws Exception {

// Define the header and payload
Expand Down

0 comments on commit 5a5557c

Please sign in to comment.