Compare commits

...
13 changed files with 296 additions and 55 deletions

No files matched your search

+22 -21
View File
@@ -107,6 +107,7 @@
<version>JGITVER</version>
<dependencyManagement>
<!-- note: order matters, and earlier declarations take precedence -->
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
@@ -115,20 +116,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-dependencies</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Needed for gRPC with Java 9+ -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-bom</artifactId>
@@ -136,13 +123,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>${aws.sdk2.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-bom</artifactId>
@@ -157,6 +137,27 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>${aws.sdk2.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-dependencies</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Needed for gRPC with Java 9+ -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-bom</artifactId>
-12
View File
@@ -311,18 +311,6 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<exclusions>
<!-- incubator packages aren't included in the opentelemetry BOM, and we don't use them -->
<exclusion>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-api-incubator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
@@ -334,9 +334,9 @@ public class RegistrationController {
throw new BadRequestException("login purchases are not enabled");
}
if (registrationRequest.accountAttributes().recoveryPassword().isEmpty()) {
throw new WebApplicationException("Account recovery password is required", 422);
}
registrationRequest.accountAttributes().recoveryPassword()
.filter(ArrayUtils::isNotEmpty)
.orElseThrow(() -> new WebApplicationException("Account recovery password is required", 422));
final ReceiptCredentialPresentation receiptCredentialPresentation;
try {
@@ -16,11 +16,11 @@ import java.util.HexFormat;
import java.util.Optional;
import org.bouncycastle.crypto.digests.TupleHash;
import org.signal.chat.common.S3UploadForm;
import org.signal.chat.profile.AccountInfo;
import org.signal.chat.profile.GetExpiringProfileKeyCredentialResult;
import org.signal.chat.profile.LegacyProfileResult;
import org.signal.chat.profile.ProfileResult;
import org.signal.chat.profile.ProfileResultOrBuilder;
import org.signal.chat.profile.LegacyProfileResult;
import org.signal.chat.profile.AccountInfo;
import org.signal.libsignal.protocol.ServiceId;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.VerificationFailedException;
@@ -30,7 +30,6 @@ import org.signal.libsignal.zkgroup.profiles.ProfileKeyCredentialRequest;
import org.signal.libsignal.zkgroup.profiles.ServerZkProfileOperations;
import org.whispersystems.textsecuregcm.auth.UnidentifiedAccessChecksum;
import org.whispersystems.textsecuregcm.badges.ProfileBadgeConverter;
import org.whispersystems.textsecuregcm.identity.IdentityType;
import org.whispersystems.textsecuregcm.s3.PostPolicyGenerator;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.DeviceCapability;
@@ -60,12 +59,20 @@ public class ProfileGrpcHelper {
final VersionedProfileV1 v1Profile = maybeV1Profile.get();
final LegacyProfileResult.Builder builder = LegacyProfileResult.newBuilder()
.setAccountInfo(buildAccountInfo(profileBadgeConverter, account))
.setName(ByteString.copyFrom(v1Profile.name()))
.setAbout(ByteString.copyFrom(v1Profile.about()))
.setAboutEmoji(ByteString.copyFrom(v1Profile.aboutEmoji()))
.setPhoneNumberSharing(ByteString.copyFrom(v1Profile.phoneNumberSharing()));
.setAccountInfo(buildAccountInfo(profileBadgeConverter, account));
if (v1Profile.name() != null) {
builder.setName(ByteString.copyFrom(v1Profile.name()));
}
if (v1Profile.about() != null) {
builder.setAbout(ByteString.copyFrom(v1Profile.about()));
}
if (v1Profile.aboutEmoji() != null) {
builder.setAboutEmoji(ByteString.copyFrom(v1Profile.aboutEmoji()));
}
if (v1Profile.phoneNumberSharing() != null) {
builder.setPhoneNumberSharing(ByteString.copyFrom(v1Profile.phoneNumberSharing()));
}
if (v1Profile.avatar() != null) {
builder.setAvatar(v1Profile.avatar());
}
@@ -31,6 +31,8 @@ import org.signal.chat.profile.SetProfileRequest;
import org.signal.chat.profile.SetProfileResponse;
import org.signal.chat.profile.SetProfileResult;
import org.signal.chat.profile.SetProfileV1Request.AvatarChange;
import org.signal.chat.profile.SetV1AvatarRequest;
import org.signal.chat.profile.SetV1AvatarResponse;
import org.signal.chat.profile.SimpleProfileGrpc;
import org.signal.libsignal.protocol.ServiceId;
import org.signal.libsignal.zkgroup.GenericServerSecretParams;
@@ -107,7 +109,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase {
final AuthenticatedDevice authenticatedDevice = AuthenticationUtil.requireAuthenticatedDevice();
final Account account = accountsManager.getByAccountIdentifier(authenticatedDevice.accountIdentifier())
.orElseThrow(() -> GrpcExceptions.invalidArguments("Account not found"));
.orElseThrow(() -> GrpcExceptions.invalidCredentials("invalid credentials"));
if (!account.hasCapability(DeviceCapability.PROFILES_V2)) {
return SetProfileResponse.newBuilder()
@@ -224,7 +226,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase {
final AuthenticatedDevice authenticatedDevice = AuthenticationUtil.requireAuthenticatedDevice();
final Account account = accountsManager.getByAccountIdentifier(authenticatedDevice.accountIdentifier())
.orElseThrow(() -> GrpcExceptions.invalidCredentials("account not found"));
.orElseThrow(() -> GrpcExceptions.invalidCredentials("invalid credentials"));
if (account.getZkCredentialKey().isEmpty()) {
return GetAvatarCredentialsResponse.newBuilder()
@@ -275,6 +277,35 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase {
.orElseGet(() -> GetProfileResponse.newBuilder().setNotFound(NotFound.getDefaultInstance()).build());
}
@Override
public SetV1AvatarResponse setV1Avatar(final SetV1AvatarRequest request) {
final AuthenticatedDevice authenticatedDevice = AuthenticationUtil.requireAuthenticatedDevice();
final String version = request.getVersion();
final Optional<VersionedProfileV1> maybeV1Profile = profilesManager.getV1(authenticatedDevice.accountIdentifier(),
version);
if (maybeV1Profile.isEmpty() && request.getCommitment().isEmpty()) {
throw GrpcExceptions.fieldViolation("commitment", "Commitment is required for new profile versions");
}
maybeV1Profile.map(VersionedProfileV1::avatar).filter(a -> a.startsWith("profiles/"))
.ifPresent(profilesManager::deleteAvatar);
final byte[] commitment = maybeV1Profile.map(VersionedProfileV1::commitment).orElseGet(request.getCommitment()::toByteArray);
final String updateAvatarObjectName = ProfileHelper.generateAvatarObjectName();
profilesManager.setV1Avatar(authenticatedDevice.accountIdentifier(), version, updateAvatarObjectName, commitment);
return SetV1AvatarResponse.newBuilder()
.setForm(ProfileGrpcHelper.generateAvatarUploadForm(updateAvatarObjectName,
ProfileHelper.MAX_PROFILE_AVATAR_SIZE_BYTES,
policyGenerator, clock))
.build();
}
private Optional<Account> validateRateLimitAndGetAccount(final UUID requesterUuid,
final ServiceIdentifier targetIdentifier) throws RateLimitExceededException {
rateLimiters.getProfileLimiter().validate(requesterUuid);
@@ -29,9 +29,11 @@ import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
import software.amazon.awssdk.services.dynamodb.model.GetItemResponse;
import software.amazon.awssdk.services.dynamodb.model.QueryRequest;
import software.amazon.awssdk.services.dynamodb.model.ReturnValue;
import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem;
import software.amazon.awssdk.services.dynamodb.model.Update;
import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
import software.amazon.awssdk.services.dynamodb.model.UpdateItemResponse;
public class Profiles {
@@ -282,4 +284,28 @@ public class Profiles {
.doOnError(ignored -> sample.stop(Metrics.timer(DELETE_PROFILES_TIMER_NAME, "outcome", "error")))
.toFuture();
}
/**
* Upserts the avatar for a v1 profile
*/
public VersionedProfileV1 setAvatar(UUID accountIdentifier, String version, String avatar, byte[] commitment) {
final UpdateItemResponse response = SET_PROFILES_TIMER.record(() ->
dynamoDbClient.updateItem(UpdateItemRequest.builder()
.tableName(tableName)
.key(buildPrimaryKey(accountIdentifier, version))
.updateExpression("SET #avatar = :avatar, #commitment = if_not_exists(#commitment, :commitment)")
.expressionAttributeNames(Map.of(
"#avatar", ATTR_AVATAR,
"#commitment", ATTR_COMMITMENT
))
.expressionAttributeValues(Map.of(
":avatar", AttributeValues.s(avatar),
":commitment", AttributeValues.b(commitment)
))
.returnValues(ReturnValue.ALL_NEW)
.build())
);
return fromItem(response.attributes());
}
}
@@ -338,4 +338,14 @@ public class ProfilesManager {
}
});
}
public void setV1Avatar(UUID accountIdentifier, String version, String avatar, byte[] commitment) {
ResilienceUtil.getGeneralRedisRetry(RETRY_NAME)
.executeRunnable(() -> cacheCluster.withBinaryCluster(
connection -> connection.sync().del(getCacheKeyV1(accountIdentifier))));
final VersionedProfileV1 versionedProfileV1 = profilesV1.setAvatar(accountIdentifier, version, avatar, commitment);
redisSet(accountIdentifier, null, versionedProfileV1);
}
}
@@ -31,6 +31,17 @@ service Profile {
//
// Note: `Accounts.SetZkCredentialKey` is a pre-requisite for this RPC
rpc GetAvatarCredentials(GetAvatarCredentialsRequest) returns (GetAvatarCredentialsResponse) {}
// Returns credentials used by clients to upload a v1 avatar, deleting any current avatar.
//
// This RPC streamlines avatar changes during the v1 -> v2 transition by minimizing uploads:
// 1. SetV1Avatar
// 2. Upload to CDN
// 3. SetProfile with v1 `AVATAR_CHANGE_UNCHANGED` and the v1 avatar in the v2 profile body
//
// Clients that do this will be required to upload current avatars using `ProfilesAnonymous.GetAvatarUploadFormRequest`
// once v1 Profile APIs are no longer supported.
rpc SetV1Avatar(SetV1AvatarRequest) returns (SetV1AvatarResponse) {}
}
// Provides methods for working with profiles and profile-related data using "unidentified access"
@@ -90,6 +101,19 @@ message SetProfileV1Request {
bytes phone_number_sharing = 6 [(require.exactlySize) = 29];
}
message SetV1AvatarRequest {
// The profile version. Required.
string version = 1 [(require.exactlySize) = 64];
// The profile key commitment. Required if this is a new profile version.
bytes commitment = 2 [(require.exactlySize) = 0, (require.exactlySize) = 97];
}
message SetV1AvatarResponse {
// the policy and credential used by clients to upload an avatar to the CDN
common.S3UploadForm form = 1;
}
message SetProfileRequest {
// The profile version. Required.
@@ -374,6 +398,7 @@ message GetAvatarUploadFormRequest {
message GetAvatarUploadFormResponse {
oneof response {
// the policy and credential used by clients to upload an avatar to the CDN
common.S3UploadForm avatar_upload_form = 1;
errors.FailedZkAuthentication invalid_credentials_presentation = 2 [(tag.reason) = "invalid_credentials_presentation"];
@@ -60,6 +60,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junitpioneer.jupiter.cartesian.ArgumentSets;
import org.junitpioneer.jupiter.cartesian.CartesianTest;
@@ -1022,19 +1023,22 @@ class RegistrationControllerTest {
}
@Test
void registerAccountMissingRecoveryPassword() throws Exception {
@ParameterizedTest
@NullSource
@ValueSource(ints = 0)
void registerAccountMissingRecoveryPassword(@Nullable final Integer recoveryPasswordLength) throws Exception {
final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate();
final IdentityKey aciIdentityKey = new IdentityKey(aciIdentityKeyPair.getPublicKey());
final AccountAttributes accountAttributes =
new AccountAttributes(true, 1, null, "test".getBytes(StandardCharsets.UTF_8), null, false,
DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES, null)
DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES,
recoveryPasswordLength == null ? null : new byte[recoveryPasswordLength])
.setUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
final RegistrationRequest registrationRequest = new RegistrationRequest(null,
new byte[0],
receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), 1).serialize(),
receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), ReceiptLevel.LOGIN.getValue()).serialize(),
null,
accountAttributes,
true,
@@ -8,6 +8,7 @@ package org.whispersystems.textsecuregcm.grpc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.ArgumentMatchers.any;
@@ -41,6 +42,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HexFormat;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@@ -57,6 +59,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.signal.chat.common.IdentityType;
import org.signal.chat.common.ServiceIdentifier;
import org.signal.chat.profile.AccountInfo;
import org.signal.chat.profile.GetAvatarCredentialsRequest;
import org.signal.chat.profile.GetAvatarCredentialsResponse;
import org.signal.chat.profile.GetProfileRequest;
@@ -64,12 +67,13 @@ import org.signal.chat.profile.GetProfileResponse;
import org.signal.chat.profile.LegacyProfileResult;
import org.signal.chat.profile.ProfileGrpc;
import org.signal.chat.profile.ProfileResult;
import org.signal.chat.profile.AccountInfo;
import org.signal.chat.profile.SetProfileRequest;
import org.signal.chat.profile.SetProfileResponse;
import org.signal.chat.profile.SetProfileResult;
import org.signal.chat.profile.SetProfileV1Request;
import org.signal.chat.profile.SetProfileV1Request.AvatarChange;
import org.signal.chat.profile.SetV1AvatarRequest;
import org.signal.chat.profile.SetV1AvatarResponse;
import org.signal.chat.profile.test.PlaintextProfileData;
import org.signal.libsignal.protocol.IdentityKey;
import org.signal.libsignal.protocol.ServiceId;
@@ -195,8 +199,6 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
when(accountsManager.getByAccountIdentifier(AUTHENTICATED_ACI)).thenReturn(Optional.of(account));
when(accountsManager.getByServiceIdentifier(new AciServiceIdentifier(AUTHENTICATED_ACI))).thenReturn(Optional.of(account));
when(profilesManager.getV1(any(), any())).thenReturn(Optional.of(profile));
when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration);
when(dynamicConfiguration.getPaymentsConfiguration()).thenReturn(dynamicPaymentsConfiguration);
when(dynamicPaymentsConfiguration.disallowedPrefixes()).thenReturn(Collections.emptyList());
@@ -376,6 +378,23 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
assertTrue(response.hasProfilesV2CapabilityRequired());
}
@Test
void setProfileUnauthenticated() {
when(accountsManager.getByAccountIdentifier(AUTHENTICATED_ACI)).thenReturn(Optional.empty());
final SetProfileRequest request = SetProfileRequest.newBuilder()
.setVersion(ByteString.copyFrom(VERSION))
.setData(ByteString.copyFrom(VALID_DATA))
.setExpectedCurrentDataHash(ByteString.copyFrom(TestRandomUtil.nextBytes(32)))
.setV1Request(V1_REQUEST)
.build();
final StatusRuntimeException statusRuntimeException = assertStatusException(Status.UNAUTHENTICATED,
() -> authenticatedServiceStub().setProfile(request));
assertEquals("invalid credentials", statusRuntimeException.getStatus().getDescription());
}
@ParameterizedTest
@MethodSource
void setProfileUpload(final AvatarChange avatarChange, final boolean hasPreviousProfile,
@@ -862,7 +881,7 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
final StatusRuntimeException statusRuntimeException = assertStatusException(Status.UNAUTHENTICATED,
() -> authenticatedServiceStub().getAvatarCredentials(GetAvatarCredentialsRequest.getDefaultInstance()));
assertEquals("account not found", statusRuntimeException.getStatus().getDescription());
assertEquals("invalid credentials", statusRuntimeException.getStatus().getDescription());
}
@Test
@@ -902,6 +921,70 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
assertEquals("invalid credential request", statusRuntimeException.getStatus().getDescription());
}
@ParameterizedTest
@ValueSource(booleans = {true, false})
void setV1Avatar(boolean hasAvatar) {
final String version = HexFormat.of().formatHex(TestRandomUtil.nextBytes(32));
final VersionedProfileV1 profile = new VersionedProfileV1(version,
TestRandomUtil.nextBytes(81),
hasAvatar ? "profiles/old-avatar" : null,
null,
TestRandomUtil.nextBytes(156),
null,
TestRandomUtil.nextBytes(582),
TestRandomUtil.nextBytes(32)
);
when(profilesManager.getV1(AUTHENTICATED_ACI, profile.version()))
.thenReturn(Optional.of(profile));
final SetV1AvatarResponse response = authenticatedServiceStub().setV1Avatar(
SetV1AvatarRequest.newBuilder()
.setVersion(version)
.build());
verify(profilesManager).setV1Avatar(eq(AUTHENTICATED_ACI), eq(version), anyString(), aryEq(profile.commitment()));
assertTrue(response.hasForm());
assertTrue(response.getForm().getKey().startsWith("profiles/"));
}
@Test
void setV1AvatarNewVersion() throws Exception {
final ProfileKey profileKey = new ProfileKey(new byte[32]);
final byte[] commitment = profileKey.getCommitment(new ServiceId.Aci(AUTHENTICATED_ACI)).serialize();
final String version = profileKey.getProfileKeyVersion(new ServiceId.Aci(AUTHENTICATED_ACI)).serialize();
when(profilesManager.getV1(eq(AUTHENTICATED_ACI), anyString()))
.thenReturn(Optional.empty());
final SetV1AvatarResponse response = authenticatedServiceStub().setV1Avatar(
SetV1AvatarRequest.newBuilder()
.setVersion(version)
.setCommitment(ByteString.copyFrom(commitment))
.build());
verify(profilesManager).setV1Avatar(eq(AUTHENTICATED_ACI), eq(version), anyString(), aryEq(commitment));
assertTrue(response.hasForm());
assertTrue(response.getForm().getKey().startsWith("profiles/"));
}
@Test
void setV1AvatarNewVersionMissingCommitment() {
when(profilesManager.getV1(eq(AUTHENTICATED_ACI), anyString()))
.thenReturn(Optional.empty());
final StatusRuntimeException statusRuntimeException = assertStatusInvalidArgument(
() -> authenticatedServiceStub().setV1Avatar(
SetV1AvatarRequest.newBuilder().setVersion(HexFormat.of().formatHex(TestRandomUtil.nextBytes(32)))
.build()));
assertNotNull(statusRuntimeException.getStatus().getDescription());
assertTrue(statusRuntimeException.getStatus().getDescription().toLowerCase(Locale.ROOT).contains("commitment"));
}
@ParameterizedTest
@ValueSource(ints = {0, 1, 16, 32})
void testProfileSerialized(int aboutEmojiLength) {
@@ -556,6 +556,33 @@ public class ProfilesManagerTest {
verifyNoInteractions(s3Client);
}
@Test
void setV1Avatar() {
final UUID uuid = UUID.randomUUID();
final String version = HexFormat.of().formatHex(TestRandomUtil.nextBytes(32));
final String avatar = "avatar";
final byte[] commitment = TestRandomUtil.nextBytes(97);
final VersionedProfileV1 profile = mock(VersionedProfileV1.class);
when(profile.version()).thenReturn(version);
when(profile.commitment()).thenReturn(commitment);
when(profile.avatar()).thenReturn(avatar);
when(profilesV1.setAvatar(any(UUID.class), anyString(), anyString(), any(byte[].class)))
.thenReturn(profile);
profilesManager.setV1Avatar(uuid, version, avatar, commitment);
verify(commands).del(aryEq(ProfilesManager.getCacheKeyV1(uuid)));
verify(profilesV1).setAvatar(uuid, version, avatar, commitment);
verify(setLuaScript).executeBinary(
argThat(keys ->
Arrays.equals(keys.get(0), ProfilesManager.getCacheKeyV1(uuid))),
argThat(args ->
Arrays.equals(args.get(0), version.getBytes())));
verifyNoMoreInteractions(setLuaScript);
}
@Nested
class Redis {
@@ -6,7 +6,9 @@
package org.whispersystems.textsecuregcm.storage;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.List;
import java.util.Map;
@@ -384,4 +386,41 @@ public class ProfilesTest {
Map.of(":commitment", AttributeValues.fromByteArray(commitment)))
);
}
@Test
void setAvatarInsert() {
final String avatar = "avatar";
final String version = "version";
final byte[] commitment = TestRandomUtil.nextBytes(97);
final VersionedProfileV1 profile = profiles.setAvatar(UUID.randomUUID(), version, avatar,
commitment);
assertEquals(version, profile.version());
assertEquals(avatar, profile.avatar());
assertArrayEquals(commitment, profile.commitment());
assertNull(profile.name());
}
@Test
void setAvatarUpdate() {
final String version = "version";
final byte[] commitment = TestRandomUtil.nextBytes(97);
final byte[] name = TestRandomUtil.nextBytes(81);
final UUID uuid = UUID.randomUUID();
{
final VersionedProfileV1 initialProfile = new VersionedProfileV1(version, name, null, null, null, null, null,
commitment);
profiles.set(uuid, initialProfile);
}
final String avatar = "avatar";
final VersionedProfileV1 profile = profiles.setAvatar(uuid, version, avatar, commitment);
assertEquals(version, profile.version());
assertEquals(avatar, profile.avatar());
assertArrayEquals(commitment, profile.commitment());
assertArrayEquals(name, profile.name());
}
}