diff --git a/authentication/authentication-filter-api/src/test/java/io/mosip/authentication/authfilter/exception/IdAuthenticationFilterExceptionTest.java b/authentication/authentication-filter-api/src/test/java/io/mosip/authentication/authfilter/exception/IdAuthenticationFilterExceptionTest.java new file mode 100644 index 00000000000..c525d580e24 --- /dev/null +++ b/authentication/authentication-filter-api/src/test/java/io/mosip/authentication/authfilter/exception/IdAuthenticationFilterExceptionTest.java @@ -0,0 +1,33 @@ +package io.mosip.authentication.authfilter.exception; + +import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants; +import org.junit.Test; + +public class IdAuthenticationFilterExceptionTest { + + @Test(expected= IdAuthenticationFilterException.class) + public void IdAuthenticationFilterException() throws IdAuthenticationFilterException { + throw new IdAuthenticationFilterException(); + } + + @Test(expected=IdAuthenticationFilterException.class) + public void IdAuthenticationFilterException2args() throws IdAuthenticationFilterException { + throw new IdAuthenticationFilterException("errorcode", "errormessage"); + } + + @Test(expected=IdAuthenticationFilterException.class) + public void IdAuthenticationFilterException3args() throws IdAuthenticationFilterException { + throw new IdAuthenticationFilterException("errorcode", "errormessage", null); + } + + @Test(expected=IdAuthenticationFilterException.class) + public void IdAuthenticationFilterExceptionEnum() throws IdAuthenticationFilterException { + throw new IdAuthenticationFilterException(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED); + } + + @Test(expected=IdAuthenticationFilterException.class) + public void IdAuthenticationFilterExceptionEnumThrowable() throws IdAuthenticationFilterException { + throw new IdAuthenticationFilterException(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED, null); + } + +} diff --git a/authentication/authentication-filter-api/src/test/java/io/mosip/authentication/authfilter/exception/InvalidAuthFilterJarSignatureExceptionTest.java b/authentication/authentication-filter-api/src/test/java/io/mosip/authentication/authfilter/exception/InvalidAuthFilterJarSignatureExceptionTest.java new file mode 100644 index 00000000000..17999eaaff2 --- /dev/null +++ b/authentication/authentication-filter-api/src/test/java/io/mosip/authentication/authfilter/exception/InvalidAuthFilterJarSignatureExceptionTest.java @@ -0,0 +1,33 @@ +package io.mosip.authentication.authfilter.exception; + +import io.mosip.authentication.core.constant.IdAuthenticationErrorConstants; +import org.junit.Test; + +public class InvalidAuthFilterJarSignatureExceptionTest { + + @Test(expected= InvalidAuthFilterJarSignatureException.class) + public void InvalidAuthFilterJarSignatureException() throws InvalidAuthFilterJarSignatureException { + throw new InvalidAuthFilterJarSignatureException(); + } + + @Test(expected=InvalidAuthFilterJarSignatureException.class) + public void InvalidAuthFilterJarSignatureException2args() throws InvalidAuthFilterJarSignatureException { + throw new InvalidAuthFilterJarSignatureException("errorcode", "errormessage"); + } + + @Test(expected=InvalidAuthFilterJarSignatureException.class) + public void InvalidAuthFilterJarSignatureException3args() throws InvalidAuthFilterJarSignatureException { + throw new InvalidAuthFilterJarSignatureException("errorcode", "errormessage", null); + } + + @Test(expected=InvalidAuthFilterJarSignatureException.class) + public void InvalidAuthFilterJarSignatureExceptionEnum() throws InvalidAuthFilterJarSignatureException { + throw new InvalidAuthFilterJarSignatureException(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED); + } + + @Test(expected=InvalidAuthFilterJarSignatureException.class) + public void InvalidAuthFilterJarSignatureExceptionEnumThrowable() throws InvalidAuthFilterJarSignatureException { + throw new InvalidAuthFilterJarSignatureException(IdAuthenticationErrorConstants.OTP_GENERATION_FAILED, null); + } + +} diff --git a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/filter/KycAuthFilterTest.java b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/filter/KycAuthFilterTest.java new file mode 100644 index 00000000000..8047c54161c --- /dev/null +++ b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/filter/KycAuthFilterTest.java @@ -0,0 +1,58 @@ +package io.mosip.authentication.service.kyc.filter; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.authentication.common.service.util.EnvUtil; +import io.mosip.authentication.core.exception.IdAuthenticationAppException; +import io.mosip.authentication.core.partner.dto.AuthPolicy; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.web.context.WebApplicationContext; + +import java.lang.reflect.UndeclaredThrowableException; +import java.util.Collections; +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@WebMvcTest +@ContextConfiguration(classes = { TestContext.class, WebApplicationContext.class }) +@Import(EnvUtil.class) +public class KycAuthFilterTest { + @Autowired + EnvUtil env; + KycAuthFilter kyAuthFilter = new KycAuthFilter(); + @Autowired + ObjectMapper mapper; + + @Before + public void before() { + ReflectionTestUtils.setField(kyAuthFilter, "mapper", mapper); + ReflectionTestUtils.setField(kyAuthFilter, "env", env); + } + @Test + public void checkAllowedAuthTypeBasedOnPolicyTest() { + AuthPolicy authPolicy = new AuthPolicy(); + authPolicy.setAuthType("demo"); + authPolicy.setMandatory(true); + try { + ReflectionTestUtils.invokeMethod(kyAuthFilter, "checkAllowedAuthTypeBasedOnPolicy", new HashMap<>(), Collections.singletonList(authPolicy)); + } catch (UndeclaredThrowableException e) { + String detailMessage = e.getUndeclaredThrowable().getMessage(); + String[] error = detailMessage.split("-->"); + assertEquals("IDA-MPA-025", error[0].trim()); + assertEquals("Partner is unauthorised for KYC-Auth", error[1].trim()); + assertTrue(e.getCause().getClass().equals(IdAuthenticationAppException.class)); + } + } + +}