From 72b17b43acab913410f65f4e8f091e76e8400545 Mon Sep 17 00:00:00 2001 From: tarique-azeez Date: Wed, 24 Dec 2025 17:23:38 +0530 Subject: [PATCH 1/3] code coverage of IDA Signed-off-by: tarique-azeez --- .../ChildAuthFilterImplTest.java | 59 ++++++- .../service/config/CacheConfigTest.java | 27 ++++ .../service/config/DemoAuthConfigTest.java | 68 ++++++++ .../service/config/IdAuthConfigTest.java | 80 +++++++++ .../config/KafkaProducerConfigTest.java | 47 ++++++ .../config/LangComparatorConfigTest.java | 75 +++++++++ .../service/config/SwaggerConfigTest.java | 93 +++++++++++ .../TrailingSlashRedirectFilterTest.java | 79 +++++++++ .../exception/IDAuthExceptionHandlerTest.java | 80 +++++++++ .../filter/DefaultInternalFilterTest.java | 89 ++++++++++ .../filter/ExternalAuthFilterTest.java | 50 ++++++ ...ntityAttributesForMatchTypeHelperTest.java | 153 ++++++++++++++++++ .../validator/AuthFiltersValidatorTest.java | 71 ++++++++ .../otp/service/filter/OTPFilterTest.java | 21 +++ ...ityKeyBindingRequestValidatorUnitTest.java | 54 +++++++ 15 files changed, 1044 insertions(+), 2 deletions(-) create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/CacheConfigTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/DemoAuthConfigTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/KafkaProducerConfigTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/LangComparatorConfigTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/SwaggerConfigTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/TrailingSlashRedirectFilterTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/DefaultInternalFilterTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/ExternalAuthFilterTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/IdentityAttributesForMatchTypeHelperTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java create mode 100644 authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/IdentityKeyBindingRequestValidatorUnitTest.java diff --git a/authentication/authentication-common/src/test/java/childauthFilter/ChildAuthFilterImplTest.java b/authentication/authentication-common/src/test/java/childauthFilter/ChildAuthFilterImplTest.java index b5280c4f945..d5f5ad6a7c4 100644 --- a/authentication/authentication-common/src/test/java/childauthFilter/ChildAuthFilterImplTest.java +++ b/authentication/authentication-common/src/test/java/childauthFilter/ChildAuthFilterImplTest.java @@ -2,8 +2,7 @@ import io.mosip.authentication.authfilter.exception.IdAuthenticationFilterException; import io.mosip.authentication.childauthfilter.impl.ChildAuthFilterImpl; -import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; -import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; +import io.mosip.authentication.core.indauth.dto.*; import org.junit.Before; import org.junit.Test; @@ -89,7 +88,63 @@ public void testAdultNoError() throws Exception { filter.validate(new AuthRequestDTO(), data, new HashMap<>()); } + private AuthRequestDTO buildOtpRequest() { + AuthRequestDTO authRequest = new AuthRequestDTO(); + RequestDTO request = new RequestDTO(); + request.setOtp("123456"); + authRequest.setRequest(request); + return authRequest; + } + + private AuthRequestDTO buildDemoRequest() { + AuthRequestDTO authRequest = new AuthRequestDTO(); + RequestDTO request = new RequestDTO(); + + IdentityDTO identity = new IdentityDTO(); + identity.setDob("2019-01-01"); // any demo attribute + + request.setDemographics(identity); + authRequest.setRequest(request); + return authRequest; + } + + private AuthRequestDTO buildEmptyAuthRequest() { + AuthRequestDTO authRequest = new AuthRequestDTO(); + authRequest.setRequest(new RequestDTO()); + return authRequest; + } + + @Test(expected = IdAuthenticationFilterException.class) + public void testChildOtpDenied() throws Exception { + String dob = LocalDate.now().minusYears(3).toString(); // child + + Map> data = new HashMap<>(); + data.put("dob", List.of(createDob(dob))); + + filter.validate(buildOtpRequest(), data, new HashMap<>()); + } + @Test(expected = IdAuthenticationFilterException.class) + public void testChildDemoDeniedWhenConfigured() throws Exception { + TestUtils.setField(filter, "factorsDeniedForChild", new String[]{"otp", "bio", "demo"}); + + String dob = LocalDate.now().minusYears(4).toString(); + + Map> data = new HashMap<>(); + data.put("dob", List.of(createDob(dob))); + + filter.validate(buildDemoRequest(), data, new HashMap<>()); + } + + @Test + public void testChildWithNoAuthFactorsAllowed() throws Exception { + String dob = LocalDate.now().minusYears(3).toString(); + + Map> data = new HashMap<>(); + data.put("dob", List.of(createDob(dob))); + + filter.validate(buildEmptyAuthRequest(), data, new HashMap<>()); + } } diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/CacheConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/CacheConfigTest.java new file mode 100644 index 00000000000..df2de7f939b --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/CacheConfigTest.java @@ -0,0 +1,27 @@ +package io.mosip.authentication.common.service.config; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.*; + +@RunWith(SpringRunner.class) +public class CacheConfigTest { + + @Test + public void testCacheManagerBeanCreation() { + // Load only this configuration + AnnotationConfigApplicationContext context = + new AnnotationConfigApplicationContext(CacheConfig.class); + + ConcurrentMapCacheManager cacheManager = + context.getBean(ConcurrentMapCacheManager.class); + + assertNotNull(cacheManager); + + context.close(); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/DemoAuthConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/DemoAuthConfigTest.java new file mode 100644 index 00000000000..b3ebf81a483 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/DemoAuthConfigTest.java @@ -0,0 +1,68 @@ +package io.mosip.authentication.common.service.config; + +import static org.junit.Assert.*; + +import java.lang.reflect.Field; + +import org.junit.Before; +import org.junit.Test; + +public class DemoAuthConfigTest { + + private DemoAuthConfig config; + + @Before + public void setup() { + config = new DemoAuthConfig(); + } + + private void setField(String name, String value) throws Exception { + Field f = DemoAuthConfig.class.getDeclaredField(name); + f.setAccessible(true); + f.set(config, value); + } + + /* ---------------- DemoApi ---------------- */ + + @Test + public void testGetDemoApiSDKInstanceClassNotFound() throws Exception { + setField("demosdkClassName", "invalid.demo.Api.Class"); + + try { + config.getDemoApiSDKInstance(); + fail("Expected ClassNotFoundException"); + } catch (ClassNotFoundException e) { + assertTrue(e.getMessage().contains("invalid.demo.Api.Class")); + } + } + + @Test + public void testGetDemoApiSDKInstanceNoDefaultConstructor() throws Exception { + // java.lang.Integer exists but has NO no-arg constructor + setField("demosdkClassName", Integer.class.getName()); + + // ReflectionUtils.findConstructor() returns empty + assertNull(config.getDemoApiSDKInstance()); + } + + /* ---------------- Normalizer ---------------- */ + + @Test + public void testGetNormalizerSDKInstanceClassNotFound() throws Exception { + setField("normalizerClassName", "invalid.normalizer.Class"); + + try { + config.getNormalizerSDKInstance(); + fail("Expected ClassNotFoundException"); + } catch (ClassNotFoundException e) { + assertTrue(e.getMessage().contains("invalid.normalizer.Class")); + } + } + + @Test(expected = ClassCastException.class) + public void testGetNormalizerSDKInstanceInvalidType() throws Exception { + setField("normalizerClassName", String.class.getName()); + config.getNormalizerSDKInstance(); + } + +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java new file mode 100644 index 00000000000..3ed694c4f51 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java @@ -0,0 +1,80 @@ +package io.mosip.authentication.common.service.config; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.web.servlet.LocaleResolver; + +import io.mosip.authentication.common.service.util.EnvUtil; +@RunWith(MockitoJUnitRunner.class) +public class IdAuthConfigTest { + + private IdAuthConfig config; + + @Mock + private EnvUtil environment; + + @Before + public void setup() throws Exception { + // anonymous subclass (allowed) + config = new IdAuthConfig() { + @Override protected boolean isFingerAuthEnabled() { return true; } + @Override protected boolean isFaceAuthEnabled() { return true; } + @Override protected boolean isIrisAuthEnabled() { return true; } + }; + + // 🔑 inject @Autowired field manually + java.lang.reflect.Field field = + IdAuthConfig.class.getDeclaredField("environment"); + field.setAccessible(true); + field.set(config, environment); + } + + @Test + public void testInitialize() { + when(environment.getEnvironment()).thenReturn(null); + + // should not throw + config.initialize(); + } + + @Test + public void testLocaleResolver() { + try (MockedStatic env = mockStatic(EnvUtil.class)) { + env.when(EnvUtil::getErrorMsgDefaultLang).thenReturn("en"); + + LocaleResolver resolver = config.localeResolver(); + + assertNotNull(resolver); + // ✅ correct assertion + assertEquals("en", LocaleContextHolder.getLocale().getLanguage()); + } + } + + @Test + public void testMessageSource() { + assertNotNull(config.messageSource()); + } + + @Test + public void testThreadPoolTaskScheduler() { + assertNotNull(config.threadPoolTaskScheduler()); + } + + @Test + public void testAfterburnerModule() { + assertNotNull(config.afterburnerModule()); + } + + @Test + public void testRestRequestBuilder() { + assertNotNull(config.getRestRequestBuilder()); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/KafkaProducerConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/KafkaProducerConfigTest.java new file mode 100644 index 00000000000..4c11d662d10 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/KafkaProducerConfigTest.java @@ -0,0 +1,47 @@ +package io.mosip.authentication.common.service.config; + +import static org.junit.Assert.*; + +import java.lang.reflect.Field; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.ProducerFactory; + +@RunWith(MockitoJUnitRunner.class) +public class KafkaProducerConfigTest { + + private KafkaProducerConfig config; + + @Before + public void setup() throws Exception { + config = new KafkaProducerConfig(); + + // 🔑 Inject @Value field using reflection + Field field = KafkaProducerConfig.class + .getDeclaredField("bootstrapAddress"); + field.setAccessible(true); + field.set(config, "localhost:9092"); + } + + /* ---------------- producerFactory ---------------- */ + + @Test + public void testProducerFactory() { + ProducerFactory factory = config.producerFactory(); + + assertNotNull(factory); + } + + /* ---------------- kafkaTemplate ---------------- */ + + @Test + public void testKafkaTemplate() { + KafkaTemplate template = config.kafkaTemplate(); + + assertNotNull(template); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/LangComparatorConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/LangComparatorConfigTest.java new file mode 100644 index 00000000000..ae3c6f06701 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/LangComparatorConfigTest.java @@ -0,0 +1,75 @@ +package io.mosip.authentication.common.service.config; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.util.ReflectionUtils; + +import io.mosip.authentication.core.util.LanguageComparator; + +@RunWith(MockitoJUnitRunner.class) +public class LangComparatorConfigTest { + + private LangComparatorConfig config; + + @Before + public void setup() { + config = new LangComparatorConfig() { + @Override + public List getSystemSupportedLanguageCodes() { + // provide fixed list for testing + return List.of("en", "fr", "hi"); + } + }; + } + + /* ---------------- getSystemSupportedLanguageCodes ---------------- */ + @Test + public void testGetSystemSupportedLanguageCodes() { + Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getSystemSupportedLanguageCodes"); + ReflectionUtils.makeAccessible(method); + + @SuppressWarnings("unchecked") + List result = (List) ReflectionUtils.invokeMethod(method, config); + + assertNotNull(result); + assertEquals(3, result.size()); + assertTrue(result.contains("en")); + assertTrue(result.contains("fr")); + assertTrue(result.contains("hi")); + } + + /* ---------------- getLanguageComparator ---------------- */ + @Test + public void testGetLanguageComparator() { + Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getLanguageComparator"); + ReflectionUtils.makeAccessible(method); + + LanguageComparator comparator = (LanguageComparator) ReflectionUtils.invokeMethod(method, config); + + // just check object creation (we don't need getLanguageCodes) + assertNotNull(comparator); + } + + @Test + public void testGetSystemSupportedLanguageCodesActualLogic() throws Exception { + // use ReflectionUtils to invoke the method + Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getSystemSupportedLanguageCodes"); + ReflectionUtils.makeAccessible(method); + + @SuppressWarnings("unchecked") + List result = (List) ReflectionUtils.invokeMethod(method, config); + + assertNotNull(result); + assertEquals(3, result.size()); + assertTrue(result.contains("en")); + assertTrue(result.contains("fr")); + assertTrue(result.contains("hi")); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/SwaggerConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/SwaggerConfigTest.java new file mode 100644 index 00000000000..879a8b2cb8a --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/SwaggerConfigTest.java @@ -0,0 +1,93 @@ +package io.mosip.authentication.common.service.config; + +import static org.junit.Assert.*; + +import java.lang.reflect.Field; +import java.util.List; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.servers.Server; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springdoc.core.models.GroupedOpenApi; + +@RunWith(MockitoJUnitRunner.class) +public class SwaggerConfigTest { + + private SwaggerConfig config; + + @Before + public void setup() throws Exception { + config = new SwaggerConfig(); + + // Setup License + LicenseProperty license = new LicenseProperty(); + license.setName("MIT"); + license.setUrl("http://license.url"); + + // Setup Info + InfoProperty info = new InfoProperty(); + info.setTitle("Test API"); + info.setVersion("1.0"); + info.setDescription("Test description"); + info.setLicense(license); + + // Setup Server + io.mosip.authentication.common.service.config.Server server = new io.mosip.authentication.common.service.config.Server(); + server.setDescription("Test server"); + server.setUrl("http://localhost:8080"); + + // Setup Service + Service service = new Service(); + service.setServers(List.of(server)); + + // Setup Group + Group group = new Group(); + group.setName("test-group"); + group.setPaths(List.of("/api/**")); + + // Setup OpenApiProperties + OpenApiProperties openApiProperties = new OpenApiProperties(); + openApiProperties.setInfo(info); + openApiProperties.setService(service); + openApiProperties.setGroup(group); + + // Inject private field using reflection + Field field = SwaggerConfig.class.getDeclaredField("openApiProperties"); + field.setAccessible(true); + field.set(config, openApiProperties); + } + + @Test + public void testOpenApi() { + OpenAPI api = config.openApi(); + assertNotNull(api); + + // Validate Info + assertEquals("Test API", api.getInfo().getTitle()); + assertEquals("1.0", api.getInfo().getVersion()); + assertEquals("Test description", api.getInfo().getDescription()); + + // Validate License + assertNotNull(api.getInfo().getLicense()); + assertEquals("MIT", api.getInfo().getLicense().getName()); + assertEquals("http://license.url", api.getInfo().getLicense().getUrl()); + + // Validate Server + assertNotNull(api.getServers()); + assertEquals(1, api.getServers().size()); + Server swaggerServer = api.getServers().get(0); + assertEquals("Test server", swaggerServer.getDescription()); + assertEquals("http://localhost:8080", swaggerServer.getUrl()); + } + + @Test + public void testGroupedOpenApi() { + GroupedOpenApi groupedApi = config.groupedOpenApi(); + assertNotNull(groupedApi); + assertEquals("test-group", groupedApi.getGroup()); + assertArrayEquals(new String[]{"/api/**"}, groupedApi.getPathsToMatch().toArray(new String[0])); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/TrailingSlashRedirectFilterTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/TrailingSlashRedirectFilterTest.java new file mode 100644 index 00000000000..712fff6076b --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/TrailingSlashRedirectFilterTest.java @@ -0,0 +1,79 @@ +package io.mosip.authentication.common.service.config; + +import io.mosip.authentication.core.dto.ObjectWithMetadata; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; + +import java.io.IOException; + +import jakarta.servlet.ServletException; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class TrailingSlashRedirectFilterTest { + + private TrailingSlashRedirectFilter filter; + private HttpServletRequest request; + private ServletResponse response; + private FilterChain chain; + + @Before + public void setup() { + filter = new TrailingSlashRedirectFilter(); + request = mock(HttpServletRequest.class); + response = mock(ServletResponse.class); + chain = mock(FilterChain.class); + } + + @Test + public void testDoFilterTrailingSlash() throws IOException, ServletException { + when(request.getRequestURI()).thenReturn("/test/"); + when(request.getScheme()).thenReturn("http"); + when(request.getServerName()).thenReturn("localhost"); + when(request.getServerPort()).thenReturn(8080); + + filter.doFilter(request, response, chain); + + // Capture the HttpServletRequest passed to chain + ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(HttpServletRequest.class); + verify(chain).doFilter(requestCaptor.capture(), eq(response)); + + HttpServletRequest wrappedRequest = requestCaptor.getValue(); + assertEquals("/test", wrappedRequest.getRequestURI()); + + // Call getRequestURL() to cover that method + StringBuffer url = wrappedRequest.getRequestURL(); + assertTrue(url.toString().contains("/test")); + assertTrue(url.toString().startsWith("http://localhost:8080")); + } + + @Test + public void testDoFilterNoTrailingSlash() throws IOException, ServletException { + when(request.getRequestURI()).thenReturn("/test"); + + filter.doFilter(request, response, chain); + + // The same request should be passed + verify(chain).doFilter(request, response); + } + + @Test + public void testDoFilterObjectWithMetadata() throws IOException, ServletException { + // Mock HttpServletRequest that ALSO implements ObjectWithMetadata + ServletRequest objRequest = mock(HttpServletRequest.class, + withSettings().extraInterfaces(ObjectWithMetadata.class)); + + // Call the filter + filter.doFilter(objRequest, response, chain); + + // Verify the same request object is passed unchanged + verify(chain).doFilter(objRequest, response); + } + +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java index 74ba73c815c..580ed25fc5c 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java @@ -2,12 +2,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.fasterxml.jackson.databind.exc.InvalidFormatException; import jakarta.servlet.http.HttpServletRequest; import org.junit.Before; @@ -27,6 +31,7 @@ import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageConversionException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContext; import org.springframework.test.context.junit4.SpringRunner; @@ -34,7 +39,9 @@ import org.springframework.validation.BindException; import org.springframework.validation.Errors; import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.request.WebRequest; import org.springframework.web.context.request.async.AsyncRequestTimeoutException; import io.mosip.authentication.common.service.util.EnvUtil; @@ -72,6 +79,12 @@ public class IDAuthExceptionHandlerTest { @Mock private HttpServletRequest servletRequest; + @InjectMocks + private IdAuthExceptionHandler exceptionHandler; + + @Mock + private WebRequest webRequest; + @Before public void before() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); @@ -480,4 +493,71 @@ public void testHandleAllException2() { assertEquals("Request could not be processed. Please try again", e.getErrorMessage()); }); } + + @Test + public void testHandleAllExceptionsReturnsUnknownException() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); + + Exception ex = new Exception("Test"); + ResponseEntity response = exceptionHandler.handleAllExceptions(ex, webRequest); + assertNotNull(response.getBody()); + assertEquals(200, response.getStatusCodeValue()); + } + + // ---------- handleExceptionInternal / notify InvalidFormatException eventType ---------- + @Test + public void testHandleExceptionInternalNotifyEventType() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/notify")); + InvalidFormatException cause = InvalidFormatException.from(null, "eventType", null, null); + HttpMessageConversionException ex = new HttpMessageConversionException("Test", cause); + + ResponseEntity response = exceptionHandler.handleExceptionInternal(ex, null, null, null, webRequest); + assertNotNull(response.getBody()); + assertEquals(200, response.getStatusCodeValue()); + } + + // ---------- handleExceptionInternal / notify InvalidFormatException expiryTimestamp ---------- + @Test + public void testHandleExceptionInternalNotifyExpiryTimestamp() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/notify")); + InvalidFormatException cause = InvalidFormatException.from(null, "expiryTimestamp", null, null); + HttpMessageConversionException ex = new HttpMessageConversionException("Test", cause); + + ResponseEntity response = exceptionHandler.handleExceptionInternal(ex, null, null, null, webRequest); + assertNotNull(response.getBody()); + assertEquals(200, response.getStatusCodeValue()); + } + + // ---------- handleExceptionInternal / ServletException ---------- + @Test + public void testHandleExceptionInternalServletException() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); + ResponseEntity response = exceptionHandler.handleExceptionInternal(new ServletRequestBindingException("Test"), null, null, null, webRequest); + assertNotNull(response.getBody()); + } + + // ---------- handleExceptionInternal / HttpMessageConversionException ---------- + @Test + public void testHandleExceptionInternalHttpMessageConversionException() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); + ResponseEntity response = exceptionHandler.handleExceptionInternal(new HttpMessageConversionException("Test"), null, null, null, webRequest); + assertNotNull(response.getBody()); + } + + // ---------- handleExceptionInternal / AsyncRequestTimeoutException ---------- + @Test + public void testHandleExceptionInternalAsyncRequestTimeoutException() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); + ResponseEntity response = exceptionHandler.handleExceptionInternal(new AsyncRequestTimeoutException(), null, null, null, webRequest); + assertNotNull(response.getBody()); + } + + // ---------- buildExceptionResponse ---------- + @Test + public void testBuildExceptionResponseWithEmptyErrors() { + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); + Exception ex = new Exception("Test"); + Object response = IdAuthExceptionHandler.buildExceptionResponse(ex, servletRequest, Collections.emptyList()); + assertNull(response); + } } \ No newline at end of file diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/DefaultInternalFilterTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/DefaultInternalFilterTest.java new file mode 100644 index 00000000000..ccf0e0ea7c0 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/DefaultInternalFilterTest.java @@ -0,0 +1,89 @@ +package io.mosip.authentication.common.service.filter; + +import io.mosip.authentication.core.constant.IdAuthConfigKeyConstants; +import io.mosip.authentication.core.partner.dto.AuthPolicy; +import org.junit.Before; +import org.junit.Test; + +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class DefaultInternalFilterTest { + + private DefaultInternalFilter filter; + + @Before + public void setUp() { + filter = new DefaultInternalFilter(); + } + + @Test + public void testDecipherAndValidateRequest() throws Exception { + ResettableStreamHttpServletRequest req = mock(ResettableStreamHttpServletRequest.class); + Map body = new HashMap<>(); + filter.decipherAndValidateRequest(req, body); // no exception, coverage + } + + @Test + public void testCheckAllowedAuthTypeBasedOnPolicy() throws Exception { + Map body = new HashMap<>(); + List policies = new ArrayList<>(); + filter.checkAllowedAuthTypeBasedOnPolicy(body, policies); // no-op + } + + @Test + public void testCheckMandatoryAuthTypeBasedOnPolicy() throws Exception { + Map body = new HashMap<>(); + List policies = new ArrayList<>(); + filter.checkMandatoryAuthTypeBasedOnPolicy(body, policies); // no-op + } + + @Test + public void testRemoveNullOrEmptyFieldsInResponse() { + Map nested = new HashMap<>(); + nested.put("innerKey", null); + + Map map = new HashMap<>(); + map.put("key1", null); + map.put("key2", new ArrayList<>()); + map.put("key3", "value3"); + map.put("key4", nested); + + Map result = filter.removeNullOrEmptyFieldsInResponse(map); + + assertEquals(2, result.size()); + assertEquals("value3", result.get("key3")); + assertTrue(result.containsKey("key4")); + assertTrue(((Map) result.get("key4")).isEmpty()); + } + + @Test + public void testFetchIdOtp() { + ResettableStreamHttpServletRequest req = mock(ResettableStreamHttpServletRequest.class); + when(req.getRequestURL()).thenReturn(new StringBuffer("/internal/otp/somepath")); + + String id = filter.fetchId(req, "attribute"); + assertEquals("attribute" + IdAuthConfigKeyConstants.OTP_INTERNAL_ID_SUFFIX, id); + } + + @Test + public void testFetchIdOtherPath() { + ResettableStreamHttpServletRequest req = mock(ResettableStreamHttpServletRequest.class); + when(req.getRequestURL()).thenReturn(new StringBuffer("/internal/unknown/somepath")); + + String id = filter.fetchId(req, "attr"); + assertNull(id); + } + + @Test + public void testNeedStoreAuthTransaction() { + assertFalse(filter.needStoreAuthTransaction()); + } + + @Test + public void testNeedStoreAnonymousProfile() { + assertFalse(filter.needStoreAnonymousProfile()); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/ExternalAuthFilterTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/ExternalAuthFilterTest.java new file mode 100644 index 00000000000..00a6a579383 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/filter/ExternalAuthFilterTest.java @@ -0,0 +1,50 @@ +package io.mosip.authentication.common.service.filter; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class ExternalAuthFilterTest { + + private ExternalAuthFilter filter; + + @Before + public void setUp() { + filter = new ExternalAuthFilter(); + } + + @Test + public void testFetchId() { + ResettableStreamHttpServletRequest request = mock(ResettableStreamHttpServletRequest.class); + String attribute = "attribute"; + String id = filter.fetchId(request, attribute); + assertEquals("attributeauth", id); + } + + @Test + public void testNeedStoreAuthTransaction() { + assertTrue(filter.needStoreAuthTransaction()); + } + + @Test + public void testNeedStoreAnonymousProfile() { + assertTrue(filter.needStoreAnonymousProfile()); + } + + @Test + public void testIsMispPolicyValidationRequired() { + assertFalse(filter.isMispPolicyValidationRequired()); + } + + @Test + public void testIsCertificateValidationRequired() { + assertTrue(filter.isCertificateValidationRequired()); + } + + @Test + public void testIsAMRValidationRequired() { + assertFalse(filter.isAMRValidationRequired()); + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/IdentityAttributesForMatchTypeHelperTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/IdentityAttributesForMatchTypeHelperTest.java new file mode 100644 index 00000000000..a3d8cb76e15 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/IdentityAttributesForMatchTypeHelperTest.java @@ -0,0 +1,153 @@ +package io.mosip.authentication.common.service.helper; + +import io.mosip.authentication.common.service.config.IDAMappingConfig; +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.spi.indauth.match.IdMapping; +import io.mosip.authentication.core.spi.indauth.match.MatchType; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class IdentityAttributesForMatchTypeHelperTest { + + @Mock + private IDAMappingConfig idMappingConfig; + + private IdentityAttributesForMatchTypeHelper helper; + + @Before + public void setUp() { + helper = new IdentityAttributesForMatchTypeHelper(); + ReflectionTestUtils.setField(helper, "idMappingConfig", idMappingConfig); + } + + @Test(expected = IdAuthenticationBusinessException.class) + public void getIdMappingValue_throws_whenMappingsNull() throws Exception { + MatchType matchType = mock(MatchType.class); + when(matchType.getCategory()).thenReturn(MatchType.Category.DEMO); + + IdMapping idMapping = mock(IdMapping.class); + @SuppressWarnings("unchecked") + BiFunction> func = (cfg, mt) -> null; + when(idMapping.getMappingFunction()).thenReturn((BiFunction) func); + + helper.getIdMappingValue(idMapping, matchType); + } + + @Test(expected = NullPointerException.class) + public void getIdMappingValue_throws_whenMappingContainsNull() throws Exception { + MatchType matchType = mock(MatchType.class); + when(matchType.getCategory()).thenReturn(MatchType.Category.DEMO); + + IdMapping idMapping = mock(IdMapping.class); + when(idMapping.getMappingFunction()).thenReturn((cfg, mt) -> List.of((String) null)); + + helper.getIdMappingValue(idMapping, matchType); + } + + @Test + public void getIdMappingValue_recursesIntoDynamicIdMapping() throws Exception { + when(idMappingConfig.getDynamicAttributes()).thenReturn(Map.of("dynKey", List.of("a", "b"))); + + MatchType matchType = mock(MatchType.class); + when(matchType.getCategory()).thenReturn(MatchType.Category.DEMO); + + IdMapping idMapping = mock(IdMapping.class); + when(idMapping.getMappingFunction()).thenReturn((cfg, mt) -> List.of("dynKey")); + + List result = helper.getIdMappingValue(idMapping, matchType); + assertEquals(List.of("a", "b"), result); + } + + @Test + public void getIdentityAttributesForMatchType_returnsEmpty_whenIdNameMismatch() { + MatchType matchType = mock(MatchType.class); + when(matchType.isDynamic()).thenReturn(false); + + IdMapping idMapping = mock(IdMapping.class); + when(idMapping.getIdname()).thenReturn("name"); + when(matchType.getIdMapping()).thenReturn(idMapping); + + List result = helper.getIdentityAttributesForMatchType(matchType, "different"); + assertTrue(result.isEmpty()); + } + + @Test + public void getIdentityAttributesForMatchType_returnsEmpty_whenGetIdMappingValueThrows() throws Exception { + IdentityAttributesForMatchTypeHelper spyHelper = spy(helper); + + MatchType matchType = mock(MatchType.class); + when(matchType.isDynamic()).thenReturn(false); + + IdMapping idMapping = mock(IdMapping.class); + when(idMapping.getIdname()).thenReturn("name"); + when(matchType.getIdMapping()).thenReturn(idMapping); + + doThrow(new IdAuthenticationBusinessException("E", "m")).when(spyHelper).getIdMappingValue(idMapping, matchType); + + List result = spyHelper.getIdentityAttributesForMatchType(matchType, "name"); + assertTrue(result.isEmpty()); + } + + @Test + public void getIdentityAttributesForMatchType_returnsFromGetIdMappingValue_whenNotDynamicAndNameMatches() throws Exception { + IdentityAttributesForMatchTypeHelper spyHelper = spy(helper); + + MatchType matchType = mock(MatchType.class); + when(matchType.isDynamic()).thenReturn(false); + + IdMapping idMapping = mock(IdMapping.class); + when(idMapping.getIdname()).thenReturn("name"); + when(matchType.getIdMapping()).thenReturn(idMapping); + + doReturn(List.of("fullName")).when(spyHelper).getIdMappingValue(idMapping, matchType); + + List result = spyHelper.getIdentityAttributesForMatchType(matchType, "name"); + assertEquals(List.of("fullName"), result); + } + + @Test + public void getIdentityAttributesForMatchType_dynamic_returnsConfiguredListWhenPresent() { + when(idMappingConfig.getDynamicAttributes()).thenReturn(Map.of("residenceStatus", List.of("residenceStatus"))); + + MatchType matchType = mock(MatchType.class); + when(matchType.isDynamic()).thenReturn(true); + + IdMapping idMapping = mock(IdMapping.class); + + List result = helper.getIdentityAttributesForMatchType(matchType, "residenceStatus"); + assertEquals(List.of("residenceStatus"), result); + } + + @Test + public void getIdentityAttributesForMatchType_dynamic_returnsIdNameWhenNotConfigured() { + when(idMappingConfig.getDynamicAttributes()).thenReturn(Map.of()); + + MatchType matchType = mock(MatchType.class); + when(matchType.isDynamic()).thenReturn(true); + + IdMapping idMapping = mock(IdMapping.class); + + List result = helper.getIdentityAttributesForMatchType(matchType, "newAttribute"); + assertEquals(List.of("newAttribute"), result); + } +} + + diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java new file mode 100644 index 00000000000..c425e4208ac --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java @@ -0,0 +1,71 @@ +package io.mosip.authentication.common.service.validator; + +import io.mosip.authentication.authfilter.exception.IdAuthenticationFilterException; +import io.mosip.authentication.authfilter.spi.IMosipAuthFilter; +import io.mosip.authentication.common.service.factory.MosipAuthFilterFactory; +import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; +import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.List; +import java.util.Map; + +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class AuthFiltersValidatorTest { + + @Mock + private MosipAuthFilterFactory mosipAuthFilterFactory; + + @Mock + private IMosipAuthFilter filter1; + + @Mock + private IMosipAuthFilter filter2; + + @InjectMocks + private AuthFiltersValidator validator; + + private AuthRequestDTO authRequestDTO; + private Map> identityData; + private Map properties; + + @Before + public void setUp() { + authRequestDTO = new AuthRequestDTO(); + identityData = Map.of(); + properties = Map.of(); + } + + @Test + public void validateAuthFilters_callsEachEnabledFilterInOrder() throws Exception { + when(mosipAuthFilterFactory.getEnabledAuthFilters()).thenReturn(List.of(filter1, filter2)); + + validator.validateAuthFilters(authRequestDTO, identityData, properties); + + verify(filter1, times(1)).validate(authRequestDTO, identityData, properties); + verify(filter2, times(1)).validate(authRequestDTO, identityData, properties); + } + + @Test(expected = IdAuthenticationFilterException.class) + public void validateAuthFilters_stopsWhenAFilterThrows() throws Exception { + when(mosipAuthFilterFactory.getEnabledAuthFilters()).thenReturn(List.of(filter1, filter2)); + doThrow(new IdAuthenticationFilterException("E", "m")).when(filter1).validate(authRequestDTO, identityData, properties); + + validator.validateAuthFilters(authRequestDTO, identityData, properties); + + verify(filter2, never()).validate(authRequestDTO, identityData, properties); + } +} + + diff --git a/authentication/authentication-otp-service/src/test/java/io/mosip/authentication/otp/service/filter/OTPFilterTest.java b/authentication/authentication-otp-service/src/test/java/io/mosip/authentication/otp/service/filter/OTPFilterTest.java index 0d7807820ec..7e0291becf9 100644 --- a/authentication/authentication-otp-service/src/test/java/io/mosip/authentication/otp/service/filter/OTPFilterTest.java +++ b/authentication/authentication-otp-service/src/test/java/io/mosip/authentication/otp/service/filter/OTPFilterTest.java @@ -76,6 +76,27 @@ void testRemoveNullOrEmptyFieldsInResponse() { assertFalse(((Map) result.get("g")).containsKey("e")); } + @Test + void testCheckAllowedAuthTypeBasedOnPolicy_allowsWhenOtpRequestPresent() throws Exception { + AuthPolicy policy = new AuthPolicy(); + policy.setAuthType("otp-request"); + policy.setAuthSubType(""); + policy.setMandatory(true); + + assertDoesNotThrow(() -> filter.checkAllowedAuthTypeBasedOnPolicy(new HashMap<>(), List.of(policy))); + } + + @Test + void testCheckAllowedAuthTypeBasedOnPolicy_throwsWhenOtpRequestMissing() { + AuthPolicy policy = new AuthPolicy(); + policy.setAuthType("something-else"); + policy.setAuthSubType(""); + policy.setMandatory(true); + + Assertions.assertThrows(IdAuthenticationAppException.class, + () -> filter.checkAllowedAuthTypeBasedOnPolicy(new HashMap<>(), List.of(policy))); + } + @org.junit.jupiter.api.Test void testCheckMandatoryAuthTypeBasedOnPolicy() { // Should do nothing and not throw diff --git a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/IdentityKeyBindingRequestValidatorUnitTest.java b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/IdentityKeyBindingRequestValidatorUnitTest.java new file mode 100644 index 00000000000..3539460a9fc --- /dev/null +++ b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/validator/IdentityKeyBindingRequestValidatorUnitTest.java @@ -0,0 +1,54 @@ +package io.mosip.authentication.service.kyc.validator; + +import io.mosip.authentication.core.indauth.dto.IdentityKeyBindingDTO; +import io.mosip.authentication.core.indauth.dto.IdentityKeyBindingRequestDTO; +import org.junit.Test; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.Errors; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Focused unit tests to directly exercise the internal validation branches. + * These branches are often skipped when base AuthRequest validation fails early. + */ +public class IdentityKeyBindingRequestValidatorUnitTest { + + private final IdentityKeyBindingRequestValidator validator = new IdentityKeyBindingRequestValidator(); + + private static Errors errors() { + return new BeanPropertyBindingResult(new IdentityKeyBindingRequestDTO(), "request"); + } + + @Test + public void validateIdentityKeyBindingAddsErrorWhenBindingIsNull() { + Errors errors = errors(); + ReflectionTestUtils.invokeMethod(validator, "validateIdentityKeyBinding", (IdentityKeyBindingDTO) null, errors); + assertTrue(errors.hasErrors()); + } + + @Test + public void validateIdentityKeyBindingPublicKeyNoErrorWhenModulusAndExponentPresent() { + Errors errors = errors(); + Map jwk = new HashMap<>(); + jwk.put("n", "modulusValue"); + jwk.put("e", "AQAB"); + ReflectionTestUtils.invokeMethod(validator, "validateIdentityKeyBindingPublicKey", jwk, errors); + assertFalse(errors.hasErrors()); + } + + + @Test + public void validateIdentityKeyBindingAuthFactorTypeNoErrorWhenNonBlank() { + Errors errors = errors(); + ReflectionTestUtils.invokeMethod(validator, "validateIdentityKeyBindingAuthFactorType", "OTP", errors); + assertFalse(errors.hasErrors()); + } +} + + From c6863ec8814c9ffed88f1bd453b4d90bc07d9724 Mon Sep 17 00:00:00 2001 From: tarique-azeez Date: Wed, 24 Dec 2025 12:04:15 +0000 Subject: [PATCH 2/3] build issue fixed Signed-off-by: tarique-azeez --- .../service/config/IdAuthConfigTest.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java index 3ed694c4f51..b9c2dbbf429 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/config/IdAuthConfigTest.java @@ -37,27 +37,6 @@ public void setup() throws Exception { field.set(config, environment); } - @Test - public void testInitialize() { - when(environment.getEnvironment()).thenReturn(null); - - // should not throw - config.initialize(); - } - - @Test - public void testLocaleResolver() { - try (MockedStatic env = mockStatic(EnvUtil.class)) { - env.when(EnvUtil::getErrorMsgDefaultLang).thenReturn("en"); - - LocaleResolver resolver = config.localeResolver(); - - assertNotNull(resolver); - // ✅ correct assertion - assertEquals("en", LocaleContextHolder.getLocale().getLanguage()); - } - } - @Test public void testMessageSource() { assertNotNull(config.messageSource()); From 0744923dce235494635ed84f4d7f6f989e7ebdd8 Mon Sep 17 00:00:00 2001 From: tarique-azeez Date: Wed, 24 Dec 2025 12:25:17 +0000 Subject: [PATCH 3/3] fixed code rabbit pr reivew comments Signed-off-by: tarique-azeez --- .../exception/IDAuthExceptionHandlerTest.java | 15 ++++++--------- .../validator/AuthFiltersValidatorTest.java | 2 -- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java index 580ed25fc5c..76b87504cb4 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/exception/IDAuthExceptionHandlerTest.java @@ -79,9 +79,6 @@ public class IDAuthExceptionHandlerTest { @Mock private HttpServletRequest servletRequest; - @InjectMocks - private IdAuthExceptionHandler exceptionHandler; - @Mock private WebRequest webRequest; @@ -499,7 +496,7 @@ public void testHandleAllExceptionsReturnsUnknownException() { when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); Exception ex = new Exception("Test"); - ResponseEntity response = exceptionHandler.handleAllExceptions(ex, webRequest); + ResponseEntity response = handler.handleAllExceptions(ex, webRequest); assertNotNull(response.getBody()); assertEquals(200, response.getStatusCodeValue()); } @@ -511,7 +508,7 @@ public void testHandleExceptionInternalNotifyEventType() { InvalidFormatException cause = InvalidFormatException.from(null, "eventType", null, null); HttpMessageConversionException ex = new HttpMessageConversionException("Test", cause); - ResponseEntity response = exceptionHandler.handleExceptionInternal(ex, null, null, null, webRequest); + ResponseEntity response = handler.handleExceptionInternal(ex, null, null, null, webRequest); assertNotNull(response.getBody()); assertEquals(200, response.getStatusCodeValue()); } @@ -523,7 +520,7 @@ public void testHandleExceptionInternalNotifyExpiryTimestamp() { InvalidFormatException cause = InvalidFormatException.from(null, "expiryTimestamp", null, null); HttpMessageConversionException ex = new HttpMessageConversionException("Test", cause); - ResponseEntity response = exceptionHandler.handleExceptionInternal(ex, null, null, null, webRequest); + ResponseEntity response = handler.handleExceptionInternal(ex, null, null, null, webRequest); assertNotNull(response.getBody()); assertEquals(200, response.getStatusCodeValue()); } @@ -532,7 +529,7 @@ public void testHandleExceptionInternalNotifyExpiryTimestamp() { @Test public void testHandleExceptionInternalServletException() { when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); - ResponseEntity response = exceptionHandler.handleExceptionInternal(new ServletRequestBindingException("Test"), null, null, null, webRequest); + ResponseEntity response = handler.handleExceptionInternal(new ServletRequestBindingException("Test"), null, null, null, webRequest); assertNotNull(response.getBody()); } @@ -540,7 +537,7 @@ public void testHandleExceptionInternalServletException() { @Test public void testHandleExceptionInternalHttpMessageConversionException() { when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); - ResponseEntity response = exceptionHandler.handleExceptionInternal(new HttpMessageConversionException("Test"), null, null, null, webRequest); + ResponseEntity response = handler.handleExceptionInternal(new HttpMessageConversionException("Test"), null, null, null, webRequest); assertNotNull(response.getBody()); } @@ -548,7 +545,7 @@ public void testHandleExceptionInternalHttpMessageConversionException() { @Test public void testHandleExceptionInternalAsyncRequestTimeoutException() { when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://localhost/test")); - ResponseEntity response = exceptionHandler.handleExceptionInternal(new AsyncRequestTimeoutException(), null, null, null, webRequest); + ResponseEntity response = handler.handleExceptionInternal(new AsyncRequestTimeoutException(), null, null, null, webRequest); assertNotNull(response.getBody()); } diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java index c425e4208ac..964e385bcff 100644 --- a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/validator/AuthFiltersValidatorTest.java @@ -63,8 +63,6 @@ public void validateAuthFilters_stopsWhenAFilterThrows() throws Exception { doThrow(new IdAuthenticationFilterException("E", "m")).when(filter1).validate(authRequestDTO, identityData, properties); validator.validateAuthFilters(authRequestDTO, identityData, properties); - - verify(filter2, never()).validate(authRequestDTO, identityData, properties); } }