Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaifk468 committed Sep 7, 2023
1 parent 4ceb3da commit 40b06ff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public AuthCodeResponse getAuthCode(AuthCodeRequest authCodeRequest) throws Esig
transaction.setCodeHash(authorizationHelperService.getKeyHash(authCode));
transaction.setAcceptedClaims(acceptedClaims);
transaction.setPermittedScopes(acceptedScopes);
consentHelperService.updateUserConsent(transaction, false, null);
consentHelperService.updateUserConsent(transaction, null);
transaction = cacheUtilService.setAuthCodeGeneratedTransaction(authCodeRequest.getTransactionId(), transaction);
auditWrapper.logAudit(Action.GET_AUTH_CODE, ActionStatus.SUCCESS, AuditHelper.buildAuditDto(authCodeRequest.getTransactionId(), transaction), null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void processConsent(OIDCTransaction transaction, boolean linked) {
}


public void updateUserConsent(OIDCTransaction transaction, boolean linked, String signature) {
public void updateUserConsent(OIDCTransaction transaction, String signature) {
if(ConsentAction.NOCAPTURE.equals(transaction.getConsentAction())
&& transaction.getEssentialClaims().isEmpty()
&& transaction.getVoluntaryClaims().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import io.mosip.esignet.core.util.IdentityProviderUtil;
import io.mosip.esignet.core.util.KafkaHelperService;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.util.Pair;
Expand Down Expand Up @@ -241,7 +239,7 @@ public LinkedKycAuthResponseV2 authenticateUserV2(LinkedKycAuthRequest linkedKyc
if(ConsentAction.NOCAPTURE.equals(transaction.getConsentAction())){
validateConsent(transaction, transaction.getAcceptedClaims(), transaction.getPermittedScopes());
cacheUtilService.setLinkedConsentedTransaction(transaction.getLinkedTransactionId(), transaction);
consentHelperService.updateUserConsent(transaction,true, "");
consentHelperService.updateUserConsent(transaction, "");
kafkaHelperService.publish(linkedAuthCodeTopicName, transaction.getLinkedTransactionId());
} else {
cacheUtilService.setLinkedAuthenticatedTransaction(linkedKycAuthRequest.getLinkedTransactionId(), transaction);
Expand Down Expand Up @@ -286,7 +284,7 @@ public LinkedConsentResponse saveConsentV2(LinkedConsentRequestV2 linkedConsentR
// cache consent only, auth-code will be generated on link-auth-code-status API call
transaction.setAcceptedClaims(linkedConsentRequest.getAcceptedClaims());
transaction.setPermittedScopes(linkedConsentRequest.getPermittedAuthorizeScopes());
consentHelperService.updateUserConsent(transaction, true, linkedConsentRequest.getSignature());
consentHelperService.updateUserConsent(transaction, linkedConsentRequest.getSignature());
cacheUtilService.setLinkedConsentedTransaction(linkedConsentRequest.getLinkedTransactionId(), transaction);
//Publish message after successfully saving the consent
kafkaHelperService.publish(linkedAuthCodeTopicName, linkedConsentRequest.getLinkedTransactionId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.mosip.esignet.core.dto.PublicKeyRegistry;
import io.mosip.esignet.core.dto.UserConsent;
import io.mosip.esignet.core.dto.UserConsentRequest;
import io.mosip.esignet.core.exception.EsignetException;
import io.mosip.esignet.core.spi.ConsentService;
import io.mosip.esignet.core.spi.PublicKeyRegistryService;
import io.mosip.esignet.core.util.IdentityProviderUtil;
Expand Down Expand Up @@ -61,6 +60,9 @@ public class ConsentHelperServiceTest {
@Mock
AuthorizationHelperService authorizationHelperService;

@Mock
AuditPlugin auditPlugin;

@InjectMocks
ConsentHelperService consentHelperService;

Expand All @@ -69,7 +71,7 @@ public class ConsentHelperServiceTest {

private static final Certificate certificate;
private static final PrivateKey privateKey;
private static String jwksString;
private static final String jwksString;

static {
try {
Expand Down Expand Up @@ -104,9 +106,6 @@ public class ConsentHelperServiceTest {
throw new RuntimeException(e);
}
}
@Mock
AuditPlugin auditHelper;


@Test
public void addUserConsent_withValidLinkedTransaction_thenPass() throws Exception {
Expand Down Expand Up @@ -140,7 +139,7 @@ public void addUserConsent_withValidLinkedTransaction_thenPass() throws Exceptio
payLoadMap.put("accepted_claims",acceptedClaims);
payLoadMap.put("permitted_authorized_scopes",permittedScopes);
String signature = generateSignature(payLoadMap);
consentHelperService.updateUserConsent(oidcTransaction, true, signature);
consentHelperService.updateUserConsent(oidcTransaction, signature);
UserConsent userConsent = new UserConsent();
userConsent.setAuthorizationScopes(Map.of("openid",false,"profile",false,"email",false));
userConsent.setHash("UrgNGrbWUB5v_oSvupBCqp7V31MJdE3nNqfGv9eazBc");
Expand Down Expand Up @@ -181,7 +180,7 @@ public void addUserConsent_withValidWebTransaction_thenPass()

Mockito.when(consentService.saveUserConsent(Mockito.any())).thenReturn(new ConsentDetail());

consentHelperService.updateUserConsent(oidcTransaction, false, "");
consentHelperService.updateUserConsent(oidcTransaction, "");
UserConsent userConsent = new UserConsent();
userConsent.setHash("Cgh8oWpNM84WPYQVvluGj616_kd4z60elVXtc7R_lXw");
userConsent.setClaims(claims);
Expand All @@ -207,7 +206,7 @@ public void addUserConsent_withValidWebTransactionNoClaimsAndScopes_thenPass()
oidcTransaction.setPermittedScopes(List.of());
oidcTransaction.setClientId(clientId);
oidcTransaction.setPartnerSpecificUserToken(psuToken);
consentHelperService.updateUserConsent(oidcTransaction, false, "");
consentHelperService.updateUserConsent(oidcTransaction, "");
Mockito.verify(consentService).deleteUserConsent(clientId, psuToken);
}

Expand Down Expand Up @@ -256,14 +255,13 @@ public void processConsent_withWebFlowAndValidConsentAndGetConsentActionAsNoCapt

List<String> acceptedClaims = consentDetail.getAcceptedClaims();
List<String> permittedScopes = consentDetail.getPermittedScopes();
String jws = consentDetail.getSignature();
Collections.sort(acceptedClaims);
Collections.sort(permittedScopes);
Map<String,Object> payLoadMap = new TreeMap<>();
payLoadMap.put("accepted_claims",acceptedClaims);
payLoadMap.put("permitted_authorized_scopes",permittedScopes);

String signature = generateSignature(payLoadMap);;
String signature = generateSignature(payLoadMap);
consentDetail.setSignature(signature);
consentDetail.setPsuToken("psutoken");

Expand Down Expand Up @@ -334,7 +332,6 @@ public void processConsent_withLinkedFlowAndValidConsentAndGetConsentActionAsCap

List<String> acceptedClaims = consentDetail.getAcceptedClaims();
List<String> permittedScopes = consentDetail.getPermittedScopes();
String jws = consentDetail.getSignature();
Collections.sort(acceptedClaims);
Collections.sort(permittedScopes);
Map<String,Object> payLoadMap = new TreeMap<>();
Expand Down Expand Up @@ -421,14 +418,13 @@ public void processConsent_withInvalidIdHashOrThumbPrint_thenPass() throws Excep

List<String> acceptedClaims = consentDetail.getAcceptedClaims();
List<String> permittedScopes = consentDetail.getPermittedScopes();
String jws = consentDetail.getSignature();
Collections.sort(acceptedClaims);
Collections.sort(permittedScopes);
Map<String,Object> payLoadMap = new TreeMap<>();
payLoadMap.put("accepted_claims",acceptedClaims);
payLoadMap.put("permitted_authorized_scopes",permittedScopes);

String signature = generateSignature(payLoadMap);;
String signature = generateSignature(payLoadMap);
consentDetail.setSignature(signature);
consentDetail.setPsuToken("psutoken");

Expand Down

0 comments on commit 40b06ff

Please sign in to comment.