-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/mosip/id-authentication …
…into develop
- Loading branch information
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...ava/io/mosip/authentication/authfilter/exception/IdAuthenticationFilterExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...mosip/authentication/authfilter/exception/InvalidAuthFilterJarSignatureExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...n-service/src/test/java/io/mosip/authentication/service/kyc/filter/KycAuthFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
||
} |