Skip to content

Commit

Permalink
Removed deprecated MyInfo API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vihangpatil committed Nov 5, 2019
1 parent 3dcca56 commit b17e5ca
Show file tree
Hide file tree
Showing 23 changed files with 21 additions and 916 deletions.
3 changes: 1 addition & 2 deletions .circleci/prime-canary-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ prime:
ACTIVATE_TOPIC_ID: ocs-activate
CCR_SUBSCRIPTION_ID: ocs-ccr-sub
GOOGLE_APPLICATION_CREDENTIALS: /secret/prime-service-account.json
MY_INFO_API_URI: https://myinfosg.api.gov.sg/v2
MY_INFO_API_REALM: prod
MY_INFO_V3_API_URI: https://api.myinfo.gov.sg/com/v3
MY_INFO_REDIRECT_URI: https://dl.oya.world/links/myinfo

secretVolumes:
Expand Down
2 changes: 0 additions & 2 deletions .circleci/prime-dev-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ prime:
ACTIVATE_TOPIC_ID: ocs-activate
CCR_SUBSCRIPTION_ID: ocs-ccr-sub
GOOGLE_APPLICATION_CREDENTIALS: /secret/prime-service-account.json
MY_INFO_V2_API_URI: https://myinfosgstg.api.gov.sg/test/v2
MY_INFO_V3_API_URI: https://test.api.myinfo.gov.sg/com/v3
MY_INFO_API_REALM: dev
MY_INFO_REDIRECT_URI: https://dl-dev.oya.world/links/myinfo

secretVolumes:
Expand Down
2 changes: 0 additions & 2 deletions .circleci/prime-prod-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ prime:
ACTIVATE_TOPIC_ID: ocs-activate
CCR_SUBSCRIPTION_ID: ocs-ccr-sub
GOOGLE_APPLICATION_CREDENTIALS: /secret/prime-service-account.json
MY_INFO_V2_API_URI: https://myinfosg.api.gov.sg/v2
MY_INFO_V3_API_URI: https://api.myinfo.gov.sg/com/v3
MY_INFO_API_REALM: prod
MY_INFO_REDIRECT_URI: https://dl.oya.world/links/myinfo

secretVolumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun enableRegion(email: String, region: String = "no") {
when (region) {
"sg" -> {
get<String> {
path = "/regions/sg/kyc/myInfo/activation-code"
path = "/regions/sg/kyc/myInfo/v3/personData/activation-code"
this.email = email
}
put<String>(expectedResultCode = 204) {
Expand Down
80 changes: 0 additions & 80 deletions acceptance-tests/src/main/kotlin/org/ostelco/at/jersey/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1433,32 +1433,6 @@ class JumioKycTest {

class SingaporeKycTest {

@Test
fun `jersey test - GET myinfoConfig v2`() {

val email = "myinfo-v2-${randomInt()}@test.com"
var customerId = ""
try {

customerId = createCustomer(name = "Test MyInfoConfig v2 Customer", email = email).id

val myInfoConfig = get<MyInfoConfig> {
path = "/regions/sg/kyc/myInfoConfig"
this.email = email
}

assertEquals(
"http://ext-myinfo-emulator:8080/v2/authorise" +
"?client_id=STG2-MYINFO-SELF-TEST" +
"&attributes=name,sex,dob,residentialstatus,nationality,mobileno,email,mailadd" +
"&redirect_uri=http://localhost:3001/callback",
myInfoConfig.url)

} finally {
StripePayment.deleteCustomer(customerId = customerId)
}
}

@Test
fun `jersey test - GET myinfoConfig v3`() {

Expand All @@ -1485,60 +1459,6 @@ class SingaporeKycTest {
}
}

@Test
fun `jersey test - GET myinfo v2`() {

val email = "myinfo-v2-${randomInt()}@test.com"
var customerId = ""
try {

customerId = createCustomer(name = "Test MyInfo v2 Customer", email = email).id

run {
val regionDetailsList = get<RegionDetailsList> {
path = "/regions"
this.email = email
}
regionDetailsList.forEach {
assertTrue(it.status == AVAILABLE, "All regions should be in available state")
assertTrue(it.simProfiles.isEmpty(), "All regions should have empty Sim profile list")
}
}

val personData: String = get {
path = "/regions/sg/kyc/myInfo/authCode"
this.email = email
}

val expectedPersonData = """{"name":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"TAN XIAO HUI"},"sex":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"F"},"nationality":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"SG"},"dob":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"1970-05-17"},"email":{"lastupdated":"2018-08-23","source":"4","classification":"C","value":"[email protected]"},"mobileno":{"lastupdated":"2018-08-23","code":"65","source":"4","classification":"C","prefix":"+","nbr":"97399245"},"mailadd":{"country":"SG","unit":"128","street":"BEDOK NORTH AVENUE 4","lastupdated":"2018-03-20","block":"102","postal":"460102","source":"1","classification":"C","floor":"09","building":"PEARL GARDEN"},"uinfin":"S9812381D"}"""
assertEquals(expectedPersonData, personData, "MyInfo PersonData do not match")

run {
val regionDetailsList = get<RegionDetailsList> {
path = "/regions"
this.email = email
}

val sgRegionDetails = regionDetailsList.singleOrNull { it.region.id == "sg" }
assertTrue(sgRegionDetails != null, "regionDetailsList should contain sg region")

val regionDetails = RegionDetails()
.region(Region().id("sg").name("Singapore"))
.status(PENDING)
.kycStatusMap(mutableMapOf(
KycType.JUMIO.name to KycStatus.PENDING,
KycType.MY_INFO.name to KycStatus.APPROVED,
KycType.ADDRESS.name to KycStatus.PENDING,
KycType.NRIC_FIN.name to KycStatus.PENDING))
.simProfiles(SimProfileList())

assertEquals(regionDetails, sgRegionDetails, "RegionDetails do not match")
}
} finally {
StripePayment.deleteCustomer(customerId = customerId)
}
}

@Test
fun `jersey test - GET myinfo v3`() {

Expand Down
72 changes: 0 additions & 72 deletions acceptance-tests/src/main/kotlin/org/ostelco/at/okhttp/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -605,31 +605,6 @@ class PurchaseTest {

class SingaporeKycTest {

@Test
fun `okhttp test - GET myinfoConfig v2`() {

val email = "myinfo-${randomInt()}@test.com"
var customerId = ""
try {

customerId = createCustomer(name = "Test MyInfoConfig v2 Customer", email = email).id

val client = clientForSubject(subject = email)

val myInfoConfig = client.myInfoV2Config

assertEquals(
"http://ext-myinfo-emulator:8080/v2/authorise" +
"?client_id=STG2-MYINFO-SELF-TEST" +
"&attributes=name,sex,dob,residentialstatus,nationality,mobileno,email,mailadd" +
"&redirect_uri=http://localhost:3001/callback",
myInfoConfig.url)

} finally {
StripePayment.deleteCustomer(customerId = customerId)
}
}

@Test
fun `okhttp test - GET myinfoConfig v3`() {

Expand All @@ -655,53 +630,6 @@ class SingaporeKycTest {
}
}

@Test
fun `okhttp test - GET myinfo v2`() {

val email = "myinfo-v2-${randomInt()}@test.com"
var customerId = ""
try {

customerId = createCustomer(name = "Test MyInfo v2 Customer", email = email).id

val client = clientForSubject(subject = email)

run {
val regionDetailsList = client.allRegions

regionDetailsList.forEach {
assertTrue(it.status == AVAILABLE, "All regions should be in available state")
}
}

val personData: String = jacksonObjectMapper().writeValueAsString(client.getCustomerMyInfoV2Data("authCode"))

val expectedPersonData = """{"name":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"TAN XIAO HUI"},"sex":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"F"},"nationality":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"SG"},"dob":{"lastupdated":"2018-03-20","source":"1","classification":"C","value":"1970-05-17"},"email":{"lastupdated":"2018-08-23","source":"4","classification":"C","value":"[email protected]"},"mobileno":{"lastupdated":"2018-08-23","code":"65","source":"4","classification":"C","prefix":"+","nbr":"97399245"},"mailadd":{"country":"SG","unit":"128","street":"BEDOK NORTH AVENUE 4","lastupdated":"2018-03-20","block":"102","postal":"460102","source":"1","classification":"C","floor":"09","building":"PEARL GARDEN"},"uinfin":"S9812381D"}"""
assertEquals(expectedPersonData, personData, "MyInfo PersonData do not match")

run {
val regionDetailsList = client.allRegions

val sgRegionIndex = regionDetailsList.indexOfFirst { it.region.id == "sg" }
assertTrue(sgRegionIndex != -1, "regionDetailsList should contain sg region")

val regionDetails = RegionDetails()
.region(Region().id("sg").name("Singapore"))
.status(PENDING)
.kycStatusMap(mutableMapOf(
KycType.JUMIO.name to KycStatus.PENDING,
KycType.MY_INFO.name to KycStatus.APPROVED,
KycType.ADDRESS.name to KycStatus.PENDING,
KycType.NRIC_FIN.name to KycStatus.PENDING))
.simProfiles(SimProfileList())

assertEquals(regionDetails, regionDetailsList[sgRegionIndex], "RegionDetails do not match")
}
} finally {
StripePayment.deleteCustomer(customerId = customerId)
}
}

@Test
fun `okhttp test - GET myinfo v3`() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.ostelco.prime.customer.endpoint.store.SubscriberDAO
import org.ostelco.prime.ekyc.MyInfoKycService
import org.ostelco.prime.getLogger
import org.ostelco.prime.model.MyInfoApiVersion
import org.ostelco.prime.model.MyInfoApiVersion.V2
import org.ostelco.prime.model.MyInfoApiVersion.V3
import org.ostelco.prime.module.getResource
import org.ostelco.prime.tracing.EnableTracing
Expand Down Expand Up @@ -48,36 +47,6 @@ class SingaporeKycResource(private val dao: SubscriberDAO): KycResource(regionCo

private val logger by getLogger()

// MyInfo v2
private val myInfoKycService by lazy { getResource<MyInfoKycService>("v2") }

@GET
@Path("/myInfo/{authorisationCode}")
@Produces(MediaType.APPLICATION_JSON)
fun getCustomerMyInfoData(@Auth token: AccessTokenPrincipal?,
@NotNull
@PathParam("authorisationCode")
authorisationCode: String): Response =
if (token == null) {
Response.status(Response.Status.UNAUTHORIZED)
} else {
dao.getCustomerMyInfoData(
identity = token.identity,
version = V2,
authorisationCode = authorisationCode)
.responseBuilder(jsonEncode = false)
}.build()

@GET
@Path("/myInfoConfig")
@Produces(MediaType.APPLICATION_JSON)
fun getMyInfoConfig(@Auth token: AccessTokenPrincipal?): Response =
if (token == null) {
Response.status(Response.Status.UNAUTHORIZED)
} else {
Response.status(Response.Status.OK).entity(myInfoKycService.getConfig())
}.build()

// MyInfo v3

@Path("/myInfo/v3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ import org.ostelco.prime.auth.AccessTokenPrincipal
import org.ostelco.prime.auth.OAuthAuthenticator
import org.ostelco.prime.customer.endpoint.store.SubscriberDAO
import org.ostelco.prime.customer.endpoint.util.AccessToken
import org.ostelco.prime.ekyc.MyInfoKycService
import org.ostelco.prime.jsonmapper.objectMapper
import org.ostelco.prime.model.Identity
import org.ostelco.prime.model.MyInfoApiVersion.V2
import org.ostelco.prime.model.MyInfoApiVersion.V3
import org.ostelco.prime.model.ScanInformation
import org.ostelco.prime.model.ScanStatus
import java.util.*
import javax.inject.Named
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response

private val MOCK_MY_INFO_KYC_SERVICE: MyInfoKycService = Mockito.mock(MyInfoKycService::class.java)

@Named("v3")
class MockMyInfoKycService : MyInfoKycService by MOCK_MY_INFO_KYC_SERVICE

class KycResourcesTest {

private val email = "[email protected]"
Expand Down Expand Up @@ -99,10 +106,10 @@ class KycResourcesTest {
val identityCaptor = argumentCaptor<Identity>()
val authorisationCodeCaptor = argumentCaptor<String>()

`when`<Either<ApiError, String>>(DAO.getCustomerMyInfoData(identityCaptor.capture(), eq(V2), authorisationCodeCaptor.capture()))
`when`<Either<ApiError, String>>(DAO.getCustomerMyInfoData(identityCaptor.capture(), eq(V3), authorisationCodeCaptor.capture()))
.thenReturn("{}".right())

val resp = RULE.target("regions/sg/kyc/myInfo/code123")
val resp = RULE.target("regions/sg/kyc/myInfo/v3/personData/code123")
.request()
.header("Authorization", "Bearer ${AccessToken.withEmail(email)}")
.get(Response::class.java)
Expand All @@ -123,10 +130,10 @@ class KycResourcesTest {
val identityCaptor = argumentCaptor<Identity>()
val authorisationCodeCaptor = argumentCaptor<String>()

`when`<Either<ApiError, String>>(DAO.getCustomerMyInfoData(identityCaptor.capture(), eq(V2), authorisationCodeCaptor.capture()))
`when`<Either<ApiError, String>>(DAO.getCustomerMyInfoData(identityCaptor.capture(), eq(V3), authorisationCodeCaptor.capture()))
.thenReturn("{}".right())

val resp = RULE.target("regions/no/kyc/myInfo/code123")
val resp = RULE.target("regions/no/kyc/myInfo/v3/personData/code123")
.request()
.header("Authorization", "Bearer ${AccessToken.withEmail(email)}")
.get(Response::class.java)
Expand All @@ -137,7 +144,7 @@ class KycResourcesTest {

@Before
fun setUp() {
Mockito.`when`(AUTHENTICATOR.authenticate(ArgumentMatchers.anyString()))
`when`(AUTHENTICATOR.authenticate(ArgumentMatchers.anyString()))
.thenReturn(Optional.of(AccessTokenPrincipal(Identity(email, "EMAIL","email"))))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.ostelco.prime.customer.endpoint.resources.MockMyInfoKycService
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.ostelco.prime.client.api.resources.MockPaymentProcessor
org.ostelco.prime.customer.endpoint.resources.MockPaymentProcessor
15 changes: 0 additions & 15 deletions ekyc/src/main/kotlin/org/ostelco/prime/ekyc/KycModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class KycModule : PrimeModule {

@JsonProperty
fun setConfig(config: Config) {
ConfigRegistry.myInfoV2 = config.myInfoV2
ConfigRegistry.myInfoV3 = config.myInfoV3
}

Expand All @@ -36,22 +35,9 @@ class KycModule : PrimeModule {
}

data class Config(
val myInfoV2: MyInfoV2Config,
val myInfoV3: MyInfoV3Config
)

data class MyInfoV2Config(
val myInfoApiUri: String,
val myInfoApiClientId: String,
val myInfoApiClientSecret: String,
val myInfoApiEnableSecurity: Boolean = true,
val myInfoApiRealm: String,
val myInfoRedirectUri: String,
val myInfoServerPublicKey: String,
val myInfoClientPrivateKey: String,
val myInfoPersonDataAttributes: String = "name,sex,dob,residentialstatus,nationality,mobileno,email,mailadd"
)

data class MyInfoV3Config(
val myInfoApiUri: String,
val myInfoApiClientId: String,
Expand All @@ -64,7 +50,6 @@ data class MyInfoV3Config(
)

object ConfigRegistry {
lateinit var myInfoV2: MyInfoV2Config
lateinit var myInfoV3: MyInfoV3Config
}

Expand Down
Loading

0 comments on commit b17e5ca

Please sign in to comment.