From f26ddde7e3f383ed310fdfb8d01e512f989ca923 Mon Sep 17 00:00:00 2001 From: irotech Date: Wed, 13 Mar 2024 17:11:38 +0000 Subject: [PATCH 1/2] SDK-2431: Drop null check for optional receipt properties --- .../com/yoti/api/client/ActivityDetails.java | 6 ++--- .../yoti/api/client/ActivityDetailsTest.java | 25 ++----------------- .../remote/ActivityDetailsFactoryTest.java | 18 +++++-------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java index ae5263d36..f6ba52a80 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java @@ -1,6 +1,6 @@ package com.yoti.api.client; -import static com.yoti.api.client.spi.remote.util.Validation.notNull; +import static com.yoti.validation.Validation.notNull; import static org.bouncycastle.util.encoders.Base64.toBase64String; @@ -26,13 +26,13 @@ public ActivityDetails(String rememberMeId, ExtraData extraData, Date timestamp, byte[] receiptId) { - this.rememberMeId = notNull(rememberMeId, "Remember Me id"); + this.rememberMeId = rememberMeId; this.parentRememberMeId = parentRememberMeId; this.userProfile = notNull(userProfile, "User profile"); this.applicationProfile = notNull(applicationProfile, "Application profile"); this.timestamp = notNull(timestamp, "Timestamp"); this.receiptId = toBase64String(notNull(receiptId, "Receipt id")); - this.extraData = notNull(extraData, "extraData"); + this.extraData = extraData; } /** diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/ActivityDetailsTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/ActivityDetailsTest.java index 6dd3cdfeb..57f7fb673 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/ActivityDetailsTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/ActivityDetailsTest.java @@ -5,8 +5,8 @@ import java.util.Date; import org.bouncycastle.util.encoders.Base64; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.*; +import org.mockito.*; public class ActivityDetailsTest { @@ -18,22 +18,6 @@ public class ActivityDetailsTest { private static final byte[] RECEIPT_ID = { 1, 2, 3, 4, 5, 6, 7, 8 }; private static final String RECEIPT_ID_STRING = Base64.toBase64String(RECEIPT_ID); private static final Date TIMESTAMP = new Date(); - private static final byte[] SOME_SELFIE_BYTES = "selfieTestVal".getBytes(); - - @Test(expected = IllegalArgumentException.class) - public void shouldFailConstructionForNullRememberMeId() { - new ActivityDetails(null, null, USER_PROFILE, APP_PROFILE, EXTRA_DATA, TIMESTAMP, RECEIPT_ID); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailConstructionForNullUserProfile() { - new ActivityDetails(REMEMBER_ME, null, null, APP_PROFILE, EXTRA_DATA, TIMESTAMP, RECEIPT_ID); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailConstructionForNullAppProfile() { - new ActivityDetails(REMEMBER_ME, null, USER_PROFILE, null, EXTRA_DATA, TIMESTAMP, RECEIPT_ID); - } @Test(expected = IllegalArgumentException.class) public void shouldFailConstructionForNullTimestamp() { @@ -45,11 +29,6 @@ public void shouldFailConstructionForNullReceiptId() { new ActivityDetails(REMEMBER_ME, null, USER_PROFILE, APP_PROFILE, EXTRA_DATA, TIMESTAMP, null); } - @Test(expected = IllegalArgumentException.class) - public void shouldFailConstructionForNullProfile() { - new ActivityDetails(REMEMBER_ME, null, null, APP_PROFILE, EXTRA_DATA, TIMESTAMP, RECEIPT_ID); - } - @Test public void shouldReturnUserId() { ActivityDetails s = new ActivityDetails(REMEMBER_ME, PARENT_REMEMBER_ME, USER_PROFILE, APP_PROFILE, EXTRA_DATA, TIMESTAMP, RECEIPT_ID); diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/ActivityDetailsFactoryTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/ActivityDetailsFactoryTest.java index 662a8b8df..ee664d49a 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/ActivityDetailsFactoryTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/ActivityDetailsFactoryTest.java @@ -14,9 +14,8 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; import java.security.GeneralSecurityException; import java.security.Key; @@ -31,17 +30,14 @@ import com.yoti.api.client.ActivityDetails; import com.yoti.api.client.ExtraData; -import com.yoti.api.client.Profile; import com.yoti.api.client.ProfileException; import com.yoti.api.client.spi.remote.call.Receipt; import com.yoti.api.client.spi.remote.util.CryptoUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.*; +import org.mockito.junit.*; @RunWith(MockitoJUnitRunner.class) public class ActivityDetailsFactoryTest { @@ -68,8 +64,6 @@ public class ActivityDetailsFactoryTest { KeyPair keyPair; byte[] validReceiptKey; - @Mock Profile profileMock; - @Mock Profile otherProfileMock; @Mock ExtraData extraDataMock; @Before @@ -235,4 +229,4 @@ public void shouldReThrowProfileExceptionFromExtraDataConverter() throws Excepti fail("Expected an exception"); } -} \ No newline at end of file +} From 7263b4b436e471e392c36118bfb456a9d633791a Mon Sep 17 00:00:00 2001 From: irotech Date: Wed, 13 Mar 2024 17:22:28 +0000 Subject: [PATCH 2/2] NA: Align terminology from receipt --- .../com/yoti/api/client/ActivityDetails.java | 16 +++++++-------- .../spi/remote/ActivityDetailsFactory.java | 20 +++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java index f6ba52a80..794fec6ce 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java @@ -13,23 +13,23 @@ public final class ActivityDetails { private final String rememberMeId; private final String parentRememberMeId; - private final ApplicationProfile applicationProfile; - private final HumanProfile userProfile; + private final ApplicationProfile thisPartyProfile; + private final HumanProfile otherPartyProfile; private final Date timestamp; private final String receiptId; private final ExtraData extraData; public ActivityDetails(String rememberMeId, String parentRememberMeId, - HumanProfile userProfile, - ApplicationProfile applicationProfile, + HumanProfile otherPartyProfile, + ApplicationProfile thisPartyProfile, ExtraData extraData, Date timestamp, byte[] receiptId) { this.rememberMeId = rememberMeId; this.parentRememberMeId = parentRememberMeId; - this.userProfile = notNull(userProfile, "User profile"); - this.applicationProfile = notNull(applicationProfile, "Application profile"); + this.otherPartyProfile = notNull(otherPartyProfile, "User profile"); + this.thisPartyProfile = notNull(thisPartyProfile, "Application profile"); this.timestamp = notNull(timestamp, "Timestamp"); this.receiptId = toBase64String(notNull(receiptId, "Receipt id")); this.extraData = extraData; @@ -41,7 +41,7 @@ public ActivityDetails(String rememberMeId, * @return profile containing attributes for the user */ public HumanProfile getUserProfile() { - return userProfile; + return otherPartyProfile; } /** @@ -50,7 +50,7 @@ public HumanProfile getUserProfile() { * @return profile containing attributes for the application */ public ApplicationProfile getApplicationProfile() { - return applicationProfile; + return thisPartyProfile; } /** diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/ActivityDetailsFactory.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/ActivityDetailsFactory.java index cd3f1b3d1..cd7248075 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/ActivityDetailsFactory.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/ActivityDetailsFactory.java @@ -3,7 +3,7 @@ import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_CHARSET; import static com.yoti.api.client.spi.remote.call.YotiConstants.RFC3339_PATTERN; import static com.yoti.api.client.spi.remote.call.YotiConstants.SYMMETRIC_CIPHER; -import static com.yoti.api.client.spi.remote.util.Validation.notNull; +import static com.yoti.validation.Validation.notNull; import java.io.UnsupportedEncodingException; import java.security.Key; @@ -53,11 +53,11 @@ public ActivityDetails create(Receipt receipt, PrivateKey privateKey) throws Pro byte[] decryptedKey = DecryptionHelper.decryptAsymmetric(receipt.getWrappedReceiptKey(), privateKey); Key secretKey = new SecretKeySpec(decryptedKey, SYMMETRIC_CIPHER); - List> userProfileAttr = attributeListReader.read(receipt.getOtherPartyProfile(), secretKey); - List> applicationProfileAttr = attributeListReader.read(receipt.getProfile(), secretKey); + List> otherPartyAttr = attributeListReader.read(receipt.getOtherPartyProfile(), secretKey); + List> thisPartyAttr = attributeListReader.read(receipt.getProfile(), secretKey); - HumanProfile userProfile = new HumanProfile(userProfileAttr); - ApplicationProfile applicationProfile = new ApplicationProfile(applicationProfileAttr); + HumanProfile otherPartyProfile = new HumanProfile(otherPartyAttr); + ApplicationProfile thisPartyProfile = new ApplicationProfile(thisPartyAttr); ExtraData extraData = parseExtraData(receipt.getExtraData(), secretKey); @@ -65,7 +65,15 @@ public ActivityDetails create(Receipt receipt, PrivateKey privateKey) throws Pro String parentRememberMeId = parseRememberMeId(receipt.getParentRememberMeId()); Date timestamp = parseTimestamp(receipt.getTimestamp()); - return new ActivityDetails(rememberMeId, parentRememberMeId, userProfile, applicationProfile, extraData, timestamp, receipt.getReceiptId()); + return new ActivityDetails( + rememberMeId, + parentRememberMeId, + otherPartyProfile, + thisPartyProfile, + extraData, + timestamp, + receipt.getReceiptId() + ); } private ExtraData parseExtraData(byte[] extraDataBytes, Key secretKey) throws ProfileException {