Skip to content

Commit

Permalink
RN Added support for CHILDREN_DOCUMENT_INFO_WITH_PDF attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkostojmenovic-frejaeid committed May 9, 2024
1 parent a99fa9f commit e9860c7
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 99 deletions.
2 changes: 1 addition & 1 deletion FrejaEidClient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.verisec.frejaeid</groupId>
<artifactId>FrejaEidClient</artifactId>
<version>2.22.1-SNAPSHOT</version>
<version>2.23.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>FrejaEidClient</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class RequestedAttributes {
private final String documentPhoto;
private final CovidCertificates covidCertificates;
private final DocumentInfoWithPdf documentInfoWithPdf;
private final List<DocumentInfoWithPdf> childrenDocumentInfoWithPdf;

@JsonCreator
public RequestedAttributes(@JsonProperty(value = "basicUserInfo") BasicUserInfo basicUserInfo,
Expand All @@ -54,7 +55,8 @@ public RequestedAttributes(@JsonProperty(value = "basicUserInfo") BasicUserInfo
@JsonProperty(value = "documentPhoto") String documentPhoto,
@JsonProperty(value = "covidCertificates") CovidCertificates covidCertificates,
@JsonProperty(value = "organisationId") OrganisationIdInfo organisationId,
@JsonProperty(value = "documentInfoWithPdf") DocumentInfoWithPdf documentInfoWithPdf) {
@JsonProperty(value = "documentInfoWithPdf") DocumentInfoWithPdf documentInfoWithPdf,
@JsonProperty(value = "childrenDocumentInfoWithPdf") List<DocumentInfoWithPdf> childrenDocumentInfoWithPdf) {
this.basicUserInfo = basicUserInfo;
this.customIdentifier = customIdentifier;
this.ssn = ssn;
Expand All @@ -74,6 +76,7 @@ public RequestedAttributes(@JsonProperty(value = "basicUserInfo") BasicUserInfo
this.documentPhoto = documentPhoto;
this.covidCertificates = covidCertificates;
this.documentInfoWithPdf = documentInfoWithPdf;
this.childrenDocumentInfoWithPdf = childrenDocumentInfoWithPdf;
}

public BasicUserInfo getBasicUserInfo() {
Expand Down Expand Up @@ -152,12 +155,17 @@ public DocumentInfoWithPdf getDocumentInfoWithPdf() {
return documentInfoWithPdf;
}

public List<DocumentInfoWithPdf> getChildrenDocumentInfoWithPdf() {
return childrenDocumentInfoWithPdf;
}

@Override
public int hashCode() {
return Objects.hash(basicUserInfo, customIdentifier, ssn, integratorSpecificUserId,
dateOfBirth, relyingPartyUserId, emailAddress, organisationIdIdentifier,
organisationId, addresses, allEmailAddresses, allPhoneNumbers, registrationLevel, age,
photo, document, documentPhoto, covidCertificates, documentInfoWithPdf);
photo, document, documentPhoto, covidCertificates, documentInfoWithPdf,
childrenDocumentInfoWithPdf);
}

@Override
Expand Down Expand Up @@ -229,6 +237,9 @@ public boolean equals(Object obj) {
if (!Objects.equals(this.documentInfoWithPdf, other.documentInfoWithPdf)) {
return false;
}
if (!Objects.equals(this.childrenDocumentInfoWithPdf, other.childrenDocumentInfoWithPdf)) {
return false;
}
return true;
}

Expand All @@ -254,6 +265,7 @@ public java.lang.String toString() {
", documentPhoto=" + documentPhoto +
", covidCertificates=" + covidCertificates +
", documentInfoWithPdf=" + documentInfoWithPdf +
", childrenDocumentInfoWithPdf=" + childrenDocumentInfoWithPdf +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.verisec.frejaeid.client.client.impl;

import com.verisec.frejaeid.client.beans.authentication.get.AuthenticationResult;
import com.verisec.frejaeid.client.beans.authentication.get.AuthenticationResultRequest;
import com.verisec.frejaeid.client.beans.general.SslSettings;
import com.verisec.frejaeid.client.beans.sign.cancel.CancelSignRequest;
import com.verisec.frejaeid.client.beans.sign.get.SignResultRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* <br> - {@link #DOCUMENT_PHOTO}
* <br> - {@link #COVID_CERTIFICATES}
* <br> - {@link #DOCUMENT_INFO_WITH_PDF}
* <br> - {@link #CHILDREN_DOCUMENT_INFO_WITH_PDF}
*/
public enum AttributeToReturn {

Expand Down Expand Up @@ -151,7 +152,14 @@ public enum AttributeToReturn {
* {@linkplain MinRegistrationLevel#EXTENDED} and
* {@linkplain MinRegistrationLevel#PLUS}.
*/
DOCUMENT_INFO_WITH_PDF("DOCUMENT_INFO_WITH_PDF");
DOCUMENT_INFO_WITH_PDF("DOCUMENT_INFO_WITH_PDF"),
/**
* Data about the user's children's documents and accompanying PDF files as a Base64-encoded String.
* Children documents with PDF can be requested only for
* {@linkplain MinRegistrationLevel#EXTENDED} and
* {@linkplain MinRegistrationLevel#PLUS}.
*/
CHILDREN_DOCUMENT_INFO_WITH_PDF("CHILDREN_DOCUMENT_INFO_WITH_PDF");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BasicService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void createRequestedAttributes() {
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.DOCUMENT_PHOTO));
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.COVID_CERTIFICATES));
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.DOCUMENT_INFO_WITH_PDF));
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.CHILDREN_DOCUMENT_INFO_WITH_PDF));
}

private static AttributeToReturnInfo attributeOf(AttributeToReturn attributeToReturn){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void createRequestedAttributes() {
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.DOCUMENT_PHOTO));
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.COVID_CERTIFICATES));
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.DOCUMENT_INFO_WITH_PDF));
REQUESTED_ATTRIBUTES.add(attributeOf(AttributeToReturn.CHILDREN_DOCUMENT_INFO_WITH_PDF));
}

private static AttributeToReturnInfo attributeOf(AttributeToReturn attributeToReturn){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -58,11 +59,13 @@ public class AuthenticationClientGetResultTest {
private static final List<Email> ALL_EMAIL_ADDRESSES = Arrays.asList(new Email(EMAIL_ADDRESS));
private static final List<PhoneNumberInfo> ALL_PHONE_NUMBERS = Arrays.asList(new PhoneNumberInfo(PHONE_NUMBER));
private static final Integer AGE = 35;
private static final String PHOTO = "https://image-hashId/test";
private static final String PHOTO = "https://image-hashId/test";
private static final DocumentInfo DOCUMENT_INFO =
new DocumentInfo(DocumentType.PASSPORT, "123456789", Country.SWEDEN, "2050-01-01");
private static final DocumentInfoWithPdf DOCUMENT_WITH_PDF =
new DocumentInfoWithPdf(DocumentType.PASSPORT, "123456789", Country.SWEDEN, "2050-01-01", "Base64Pdf");
private static final DocumentInfoWithPdf CHILDREN_DOCUMENT_WITH_PDF =
new DocumentInfoWithPdf(DocumentType.PASSPORT, "987654321", Country.SWEDEN, "20240-01-01", "Base64Pdf");
private static final String DOCUMENT_PHOTO = "Base64EncodedDocPhoto";
private static final CovidCertificates COVID_CERTIFICATES =
new CovidCertificates(new Vaccines("covidCertificate"), null, null, true);
Expand All @@ -71,7 +74,7 @@ public class AuthenticationClientGetResultTest {

@BeforeClass
public static void initTestData() {
HashMap<String,String> organisationIdIssuerNames = new HashMap<>();
Map<String, String> organisationIdIssuerNames = new HashMap<>();
organisationIdIssuerNames.put("EN", "Org ID issuer");
organisationIdIssuerNames.put("SV", "Org ID issuer Swedish");
ORGANISATION_ID_INFO =
Expand All @@ -87,7 +90,7 @@ public static void initTestData() {
ALL_EMAIL_ADDRESSES, ALL_PHONE_NUMBERS, RegistrationLevel.EXTENDED,
AGE, PHOTO, DOCUMENT_INFO, DOCUMENT_PHOTO,
COVID_CERTIFICATES, ORGANISATION_ID_INFO,
DOCUMENT_WITH_PDF);
DOCUMENT_WITH_PDF, Arrays.asList(CHILDREN_DOCUMENT_WITH_PDF));
}

@Before
Expand All @@ -102,14 +105,14 @@ public void getAuthenticationResult_relyingPartyIdNull_success()
throws FrejaEidClientInternalException, FrejaEidException {
AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.create(REFERENCE);
when(httpServiceMock.send(anyString(), any(RequestTemplate.class),
any(RelyingPartyRequest.class),
Mockito.eq(AuthenticationResult.class), (String) Mockito.isNull()))
any(RelyingPartyRequest.class),
Mockito.eq(AuthenticationResult.class), (String) Mockito.isNull()))
.thenReturn(new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, DETAILS,
REQUESTED_ATTRIBUTES));
AuthenticationResult response = authenticationClient.getResult(authenticationResultRequest);
verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT,
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, null);
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, null);
assertEquals(REFERENCE, response.getAuthRef());
assertEquals(TransactionStatus.STARTED, response.getStatus());
assertEquals(DETAILS, response.getDetails());
Expand All @@ -127,8 +130,8 @@ public void getAuthenticationResultPersonal_success() throws FrejaEidClientInter
REQUESTED_ATTRIBUTES));
AuthenticationResult response = authenticationClient.getResult(authenticationResultRequest);
verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT,
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, RELYING_PARTY_ID);
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, RELYING_PARTY_ID);
assertEquals(REFERENCE, response.getAuthRef());
assertEquals(TransactionStatus.STARTED, response.getStatus());
assertEquals(DETAILS, response.getDetails());
Expand Down Expand Up @@ -170,7 +173,8 @@ public void getAuthenticationResultOrganisational_withAdditionalAttributes_succe
ALL_EMAIL_ADDRESSES, ALL_PHONE_NUMBERS,
RegistrationLevel.EXTENDED, AGE, PHOTO,
DOCUMENT_INFO, DOCUMENT_PHOTO, COVID_CERTIFICATES,
ORGANISATION_ID_INFO_WITH_ADDITIONAL_ATTRIBUTES, DOCUMENT_WITH_PDF);
ORGANISATION_ID_INFO_WITH_ADDITIONAL_ATTRIBUTES, DOCUMENT_WITH_PDF,
Arrays.asList(CHILDREN_DOCUMENT_WITH_PDF));
AuthenticationClientApi authenticationClient =
AuthenticationClient.create(TestUtil.getDefaultSslSettings(), FrejaEnvironment.TEST)
.setHttpService(httpServiceMock)
Expand Down Expand Up @@ -208,9 +212,9 @@ public void getAuthenticationResult_invalidReference_expectInvalidReferenceError
Assert.fail("Test should throw exception!");
} catch (FrejaEidException rpEx) {
verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT,
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
getOneAuthenticationResultRequest, AuthenticationResult.class,
RELYING_PARTY_ID);
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
getOneAuthenticationResultRequest, AuthenticationResult.class,
RELYING_PARTY_ID);
assertEquals(1100, rpEx.getErrorCode());
assertEquals("Invalid reference (for example, nonexistent or expired).", rpEx.getLocalizedMessage());
}
Expand All @@ -228,8 +232,8 @@ public void pollForResult_relyingPartyIdNull_finalResponseRejected_success()
.thenReturn(expectedResponse);
AuthenticationResult response = authenticationClient.pollForResult(authenticationResultRequest, 10000);
verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT,
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, null);
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, null);
assertEquals(TransactionStatus.REJECTED, response.getStatus());
}

Expand All @@ -247,8 +251,8 @@ public void pollForResult_relyingPartyIdNotNull_finalResponseRejected_success()
AuthenticationResult response = authenticationClient
.pollForResult(AuthenticationResultRequest.create(REFERENCE, RELYING_PARTY_ID), 10000);
verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULT,
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, RELYING_PARTY_ID);
RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE,
authenticationResultRequest, AuthenticationResult.class, RELYING_PARTY_ID);
assertEquals(TransactionStatus.REJECTED, response.getStatus());
}

Expand Down Expand Up @@ -293,9 +297,9 @@ private void getAuthenticationResults_success(AuthenticationResultsRequest getAu
throws FrejaEidClientInternalException, FrejaEidException {
List<AuthenticationResult> response = authenticationClient.getResults(getAuthenticationResultsRequest);
verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.AUTHENTICATION_GET_RESULTS,
RequestTemplate.AUTHENTICATION_RESULTS_TEMPLATE,
getAuthenticationResultsRequest, AuthenticationResults.class,
getAuthenticationResultsRequest.getRelyingPartyId());
RequestTemplate.AUTHENTICATION_RESULTS_TEMPLATE,
getAuthenticationResultsRequest, AuthenticationResults.class,
getAuthenticationResultsRequest.getRelyingPartyId());
AuthenticationResult first = response.get(0);
assertEquals(REFERENCE, first.getAuthRef());
assertEquals(TransactionStatus.STARTED, first.getStatus());
Expand All @@ -315,12 +319,13 @@ private AuthenticationResults prepareResponse() {
RELYING_PARTY_USER_ID, EMAIL_ADDRESS, ORGANISATION_ID, ADDRESSES,
ALL_EMAIL_ADDRESSES, ALL_PHONE_NUMBERS, RegistrationLevel.EXTENDED, AGE,
PHOTO, DOCUMENT_INFO, DOCUMENT_PHOTO, COVID_CERTIFICATES,
ORGANISATION_ID_INFO, DOCUMENT_WITH_PDF);
ORGANISATION_ID_INFO, DOCUMENT_WITH_PDF,
Arrays.asList(CHILDREN_DOCUMENT_WITH_PDF));
AuthenticationResult firstResponse =
new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, DETAILS, attributes1);
RequestedAttributes attributes2 =
new RequestedAttributes(null, "test", null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null, null);
AuthenticationResult secondResponse =
new AuthenticationResult(REFERENCE, TransactionStatus.DELIVERED_TO_MOBILE, "test", attributes2);
List<AuthenticationResult> responses = new ArrayList<>();
Expand Down
Loading

0 comments on commit e9860c7

Please sign in to comment.