Skip to content

Commit

Permalink
skip nonce check in local environment (#1148)
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Rana <[email protected]>
  • Loading branch information
sacrana0 authored Jan 30, 2025
1 parent 87372bd commit 2b23c05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -103,6 +104,9 @@ public class AuthorizationServiceImpl implements AuthorizationService {
@Value("${mosip.esignet.signup-id-token-audience}")
private String signupIDTokenAudience;

@Autowired
private Environment environment;


@Override
public OAuthDetailResponseV1 getOauthDetails(OAuthDetailRequest oauthDetailReqDto) throws EsignetException {
Expand Down Expand Up @@ -507,11 +511,15 @@ private String getAuthTransactionId(String oidcTransactionId) {
}

private void validateNonce(String nonce) {
if(nonce == null || nonce.isBlank())
if(isLocalEnvironment() || nonce == null || nonce.isBlank())
return;

if(cacheUtilService.checkNonce(nonce.trim()) == 0L)
throw new EsignetException(ErrorConstants.INVALID_REQUEST);
}

private boolean isLocalEnvironment() {
return Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> env.equalsIgnoreCase("local"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.env.Environment;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.util.ReflectionTestUtils;

Expand Down Expand Up @@ -72,6 +73,9 @@ public class AuthorizationServiceTest {
@Mock
Authenticator authenticationWrapper;

@Mock
Environment environment;

@InjectMocks
AuthorizationServiceImpl authorizationServiceImpl;

Expand Down Expand Up @@ -124,6 +128,8 @@ public void setUp() {
ReflectionTestUtils.setField(authorizationServiceImpl, "objectMapper", new ObjectMapper());
ReflectionTestUtils.setField(authorizationServiceImpl, "authorizationHelperService", authorizationHelperService);
ReflectionTestUtils.setField(authorizationServiceImpl,"captchaRequired",Arrays.asList("bio","pwd"));

when(environment.getActiveProfiles()).thenReturn(new String[]{"test"});
}


Expand Down

0 comments on commit 2b23c05

Please sign in to comment.