Skip to content

Commit

Permalink
added coverage (#1127)
Browse files Browse the repository at this point in the history
* [ES-417]

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>

* added test cases for KycAuthFilter and InvalidAuthFilterJarSignatureException

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>

* review changes

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>

---------

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>
  • Loading branch information
pvsaidurga authored Nov 8, 2023
1 parent fd1b3c4 commit 6f0b220
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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));
}
}

}

0 comments on commit 6f0b220

Please sign in to comment.