Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/mosip/id-authentication
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
Rakshithb1 committed Nov 8, 2023
2 parents f663ed6 + 6f0b220 commit 2a416e1
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 2a416e1

Please sign in to comment.