diff --git a/README.md b/README.md index 9e7fb3672..4f3ea29ef 100644 --- a/README.md +++ b/README.md @@ -104,13 +104,13 @@ If you are using Maven, you need to add the following dependency: com.yoti yoti-sdk-impl - 2.6.0 + 2.6.1 ``` If you are using Gradle, here is the dependency to add: -`compile group: 'com.yoti', name: 'yoti-sdk-impl', version: '2.6.0'` +`compile group: 'com.yoti', name: 'yoti-sdk-impl', version: '2.6.1'` You will find all classes packaged under `com.yoti.api` diff --git a/pom.xml b/pom.xml index 736890860..a0476fc11 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk pom - 2.6.0 + 2.6.1 Yoti SDK Java SDK for simple integration with the Yoti platform https://github.com/getyoti/yoti-java-sdk diff --git a/yoti-sdk-api/pom.xml b/yoti-sdk-api/pom.xml index 7f9d46020..f9ba41132 100644 --- a/yoti-sdk-api/pom.xml +++ b/yoti-sdk-api/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 2.6.0 + 2.6.1 ../yoti-sdk-parent diff --git a/yoti-sdk-impl/pom.xml b/yoti-sdk-impl/pom.xml index 77b7cea14..ba7552fa6 100644 --- a/yoti-sdk-impl/pom.xml +++ b/yoti-sdk-impl/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 2.6.0 + 2.6.1 ../yoti-sdk-parent diff --git a/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParser.java b/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParser.java index c74e85da5..cc75e0c94 100644 --- a/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParser.java +++ b/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParser.java @@ -2,13 +2,14 @@ import java.io.UnsupportedEncodingException; import java.text.ParseException; +import java.util.Arrays; import com.yoti.api.client.Date; import com.yoti.api.client.DocumentDetails; class DocumentDetailsAttributeParser { - private static final String MINIMUM_ACCEPTABLE = "([A-Za-z_]*) ([A-Za-z]{3}) ([A-Za-z0-9]{1}).*"; + private static final int MINIMUM_ACCEPTABLE = 3; private static final int TYPE_INDEX = 0; private static final int COUNTRY_INDEX = 1; private static final int NUMBER_INDEX = 2; @@ -16,11 +17,22 @@ class DocumentDetailsAttributeParser { private static final int AUTHORITY_INDEX = 4; DocumentDetails parseFrom(String attributeValue) throws UnsupportedEncodingException, ParseException { - if (attributeValue == null || !attributeValue.matches(MINIMUM_ACCEPTABLE)) { + if (attributeValue == null || attributeValue.isEmpty()) { throw new IllegalArgumentException("Unable to parse attribute value to a DocumentDetails"); } + String[] attributes = attributeValue.split(" "); + if (attributes.length < MINIMUM_ACCEPTABLE) { + throw new IllegalArgumentException("Unable to parse attribute value to a DocumentDetails"); + } + + for (String s : attributes) { + if (s == null || s.isEmpty()) { + throw new IllegalArgumentException("Invalid Document Details value, multiple consecutive spaces"); + } + } + return DocumentDetailsAttributeValue.builder() .withType(attributes[TYPE_INDEX]) .withIssuingCountry(attributes[COUNTRY_INDEX]) diff --git a/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java b/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java index 29ab4704d..a84b52c8e 100644 --- a/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java +++ b/yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java @@ -21,7 +21,7 @@ private YotiConstants() {} public static final String CONTENT_TYPE_JPEG = "image/jpeg"; public static final String JAVA = "Java"; - public static final String SDK_VERSION = JAVA + "-2.6.0"; + public static final String SDK_VERSION = JAVA + "-2.6.1"; public static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; public static final String ASYMMETRIC_CIPHER = "RSA/NONE/PKCS1Padding"; public static final String SYMMETRIC_CIPHER = "AES/CBC/PKCS7Padding"; diff --git a/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserConsecutiveSpacesTest.java b/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserConsecutiveSpacesTest.java new file mode 100644 index 000000000..0340d46cd --- /dev/null +++ b/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserConsecutiveSpacesTest.java @@ -0,0 +1,33 @@ +package com.yoti.api.client.spi.remote; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; + +@RunWith(Parameterized.class) +public class DocumentDetailsAttributeParserConsecutiveSpacesTest { + + @Parameterized.Parameters(name = "{index}: Test with {0}") + public static Iterable data() { + return Arrays.asList(new Object[][] { + {"PASSPORT GBR 1234abc"}, + {"PASSPORT GBR 1234abc"}, + {"DRIVING_LICENCE GBR 1234abc 2016-05-01 DVLA"}, + {"DRIVING_LICENCE GBR 1234abc 2016-05-01 DVLA"} + }); + } + + private String testValue; + + public DocumentDetailsAttributeParserConsecutiveSpacesTest(String testValue) { + this.testValue = testValue; + } + + @Test(expected = IllegalArgumentException.class) + public void shouldFailForMoreThanoneConsecutiveSpace() throws Exception { + new DocumentDetailsAttributeParser().parseFrom(testValue); + } + +} diff --git a/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserSpecialCharactersTest.java b/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserSpecialCharactersTest.java new file mode 100644 index 000000000..917526241 --- /dev/null +++ b/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserSpecialCharactersTest.java @@ -0,0 +1,43 @@ +package com.yoti.api.client.spi.remote; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import com.yoti.api.client.DocumentDetails; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; + +@RunWith(Parameterized.class) +public class DocumentDetailsAttributeParserSpecialCharactersTest { + + @Parameterized.Parameters(name = "{index}: Test with {0}") + public static Iterable data() { + return Arrays.asList(new Object[][] { + {"****"}, + {"~!@#$%^&*()-_=+[]{}|;':,./<>?"}, + {"\"\""}, + {"\\"}, + {"\""}, + {"''"}, + {"'"} + }); + } + + private String testValue; + + public DocumentDetailsAttributeParserSpecialCharactersTest(String testValue) { + this.testValue = testValue; + } + + @Test + public void shouldParseDocumentDetailsWithSpecialCharacters() throws Exception { + DocumentDetails result = new DocumentDetailsAttributeParser() + .parseFrom(String.format("PASS_CARD GBR %s - DVLA", testValue)); + + assertThat(result.getDocumentNumber(), is(testValue)); + } + +} diff --git a/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserTest.java b/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserTest.java index 8f45aac54..c14610bc1 100644 --- a/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserTest.java +++ b/yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/DocumentDetailsAttributeParserTest.java @@ -1,5 +1,7 @@ package com.yoti.api.client.spi.remote; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -8,10 +10,13 @@ import com.yoti.api.client.DocumentDetails; +import com.yoti.api.client.spi.remote.call.YotiConstants; import org.junit.Test; public class DocumentDetailsAttributeParserTest { + private static final String SOME_AADHAR_DOCUMENT_DETAILS = "NATIONAL_ID IND ********6421 - UIDAI"; + DocumentDetailsAttributeParser testObj = new DocumentDetailsAttributeParser(); @Test(expected = IllegalArgumentException.class) @@ -24,16 +29,6 @@ public void shouldThrowExceptionWhenAttributesAreMissing() throws Exception { testObj.parseFrom("PASSPORT GBR"); } - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForInvalidNumber() throws Exception { - testObj.parseFrom("PASSPORT GBR $%^$%^£ 2016-05-01"); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForInvalidCountry() throws Exception { - testObj.parseFrom("PASSPORT 13 1234abc 2016-05-01"); - } - @Test public void shouldParseMandatoryAttributes() throws Exception { DocumentDetails result = testObj.parseFrom("PASSPORT GBR 1234abc"); @@ -99,4 +94,16 @@ public void shouldThrowExceptionForInvalidDate() throws Exception { testObj.parseFrom("PASSPORT GBR 1234abc" + " X016-05-01"); } + @Test + public void shouldParseRedactedAadhar() throws Exception { + DocumentDetails result = testObj.parseFrom(SOME_AADHAR_DOCUMENT_DETAILS); + + assertThat(result, is(notNullValue())); + assertThat(result.getType(), is("NATIONAL_ID")); + assertThat(result.getIssuingCountry(), is("IND")); + assertThat(result.getDocumentNumber(), is("********6421")); + assertThat(result.getExpirationDate(), is(nullValue())); + assertThat(result.getIssuingAuthority(), is("UIDAI")); + } + } diff --git a/yoti-sdk-parent/pom.xml b/yoti-sdk-parent/pom.xml index 2ae6ff358..7ce33db88 100644 --- a/yoti-sdk-parent/pom.xml +++ b/yoti-sdk-parent/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk-parent pom - 2.6.0 + 2.6.1 Yoti SDK Parent Pom Parent pom for the Java SDK projects https://github.com/getyoti/yoti-java-sdk diff --git a/yoti-sdk-sandbox/pom.xml b/yoti-sdk-sandbox/pom.xml index 7f7f555d1..ae445cd04 100644 --- a/yoti-sdk-sandbox/pom.xml +++ b/yoti-sdk-sandbox/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 2.6.0 + 2.6.1 ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-auto-config/README.md b/yoti-sdk-spring-boot-auto-config/README.md index 99b0a08ab..4a4865885 100644 --- a/yoti-sdk-spring-boot-auto-config/README.md +++ b/yoti-sdk-spring-boot-auto-config/README.md @@ -18,7 +18,7 @@ If you are using Maven, you need to add the following dependencies: com.yoti yoti-sdk-spring-boot-auto-config - 2.6.0 + 2.6.1 ``` @@ -26,7 +26,7 @@ If you are using Maven, you need to add the following dependencies: If you are using Gradle, here is the dependency to add: ``` -compile group: 'com.yoti', name: 'yoti-sdk-spring-boot-auto-config', version: '2.6.0' +compile group: 'com.yoti', name: 'yoti-sdk-spring-boot-auto-config', version: '2.6.1' ``` diff --git a/yoti-sdk-spring-boot-auto-config/pom.xml b/yoti-sdk-spring-boot-auto-config/pom.xml index a4d2d12af..33dee47f1 100644 --- a/yoti-sdk-spring-boot-auto-config/pom.xml +++ b/yoti-sdk-spring-boot-auto-config/pom.xml @@ -12,7 +12,7 @@ com.yoti yoti-sdk-parent - 2.6.0 + 2.6.1 ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-example/README.md b/yoti-sdk-spring-boot-example/README.md index f63317998..d755f7f75 100644 --- a/yoti-sdk-spring-boot-example/README.md +++ b/yoti-sdk-spring-boot-example/README.md @@ -16,7 +16,7 @@ Before you start, you'll need to create an Application in [Yoti Hub](https://hub com.yoti yoti-sdk-impl - 2.6.0 + 2.6.1 ``` @@ -29,8 +29,8 @@ Before you start, you'll need to create an Application in [Yoti Hub](https://hub 1. Run `mvn clean package` to build the project. ## Running -* You can run your server-app by executing `java -jar target/yoti-sdk-spring-boot-example-2.6.0.jar` - * If you are using Java 9, you can run the server-app as follows `java -jar target/yoti-sdk-spring-boot-example-2.6.0.jar --add-exports java.base/jdk.internal.ref=ALL-UNNAMED` +* You can run your server-app by executing `java -jar target/yoti-sdk-spring-boot-example-2.6.1.jar` + * If you are using Java 9, you can run the server-app as follows `java -jar target/yoti-sdk-spring-boot-example-2.6.1.jar --add-exports java.base/jdk.internal.ref=ALL-UNNAMED` * Navigate to `https://localhost:8443` * You can then initiate a login using Yoti. The Spring demo is listening for the response on `https://localhost:8443/login`. diff --git a/yoti-sdk-spring-boot-example/pom.xml b/yoti-sdk-spring-boot-example/pom.xml index 02d9a570a..d357ce070 100644 --- a/yoti-sdk-spring-boot-example/pom.xml +++ b/yoti-sdk-spring-boot-example/pom.xml @@ -6,7 +6,7 @@ com.yoti yoti-sdk-spring-boot-example - 2.6.0 + 2.6.1 Yoti Spring Boot Example diff --git a/yoti-sdk-spring-security/README.md b/yoti-sdk-spring-security/README.md index 4a3ee5129..d1a40e146 100644 --- a/yoti-sdk-spring-security/README.md +++ b/yoti-sdk-spring-security/README.md @@ -25,14 +25,14 @@ If you are using Maven, you need to add the following dependencies: com.yoti yoti-sdk-spring-security - 2.6.0 + 2.6.1 ``` If you are using Gradle, here is the dependency to add: ``` -compile group: 'com.yoti', name: 'yoti-sdk-spring-security', version: '2.6.0' +compile group: 'com.yoti', name: 'yoti-sdk-spring-security', version: '2.6.1' ``` ### Provide a `YotiClient` instance diff --git a/yoti-sdk-spring-security/pom.xml b/yoti-sdk-spring-security/pom.xml index 6c08d412d..84557b376 100644 --- a/yoti-sdk-spring-security/pom.xml +++ b/yoti-sdk-spring-security/pom.xml @@ -12,7 +12,7 @@ com.yoti yoti-sdk-parent - 2.6.0 + 2.6.1 ../yoti-sdk-parent