Convert classes using @JsonUnwrapped to records

This commit is contained in:
Chris Eager
2025-07-19 13:01:59 -05:00
committed by Chris Eager
parent 94361b2d5d
commit 4618b47141
9 changed files with 212 additions and 318 deletions

View File

@@ -930,14 +930,14 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get(VersionedProfileResponse.class);
assertThat(profile.getBaseProfileResponse().getIdentityKey()).isEqualTo(ACCOUNT_TWO_IDENTITY_KEY);
assertThat(profile.getName()).containsExactly(name);
assertThat(profile.getAbout()).containsExactly(about);
assertThat(profile.getAboutEmoji()).containsExactly(emoji);
assertThat(profile.getAvatar()).isEqualTo("profiles/validavatar");
assertThat(profile.getPhoneNumberSharing()).containsExactly(phoneNumberSharing);
assertThat(profile.getBaseProfileResponse().getUuid()).isEqualTo(new AciServiceIdentifier(AuthHelper.VALID_UUID_TWO));
assertThat(profile.getBaseProfileResponse().getBadges()).hasSize(1).element(0).has(new Condition<>(
assertThat(profile.baseProfileResponse().getIdentityKey()).isEqualTo(ACCOUNT_TWO_IDENTITY_KEY);
assertThat(profile.name()).containsExactly(name);
assertThat(profile.about()).containsExactly(about);
assertThat(profile.aboutEmoji()).containsExactly(emoji);
assertThat(profile.avatar()).isEqualTo("profiles/validavatar");
assertThat(profile.phoneNumberSharing()).containsExactly(phoneNumberSharing);
assertThat(profile.baseProfileResponse().getUuid()).isEqualTo(new AciServiceIdentifier(AuthHelper.VALID_UUID_TWO));
assertThat(profile.baseProfileResponse().getBadges()).hasSize(1).element(0).has(new Condition<>(
badge -> "Test Badge".equals(badge.getName()), "has badge with expected name"));
verify(rateLimiter, times(1)).validate(AuthHelper.VALID_UUID);
@@ -982,7 +982,7 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get(VersionedProfileResponse.class);
assertThat(profile.getPaymentAddress()).containsExactly(paymentAddress);
assertThat(profile.paymentAddress()).containsExactly(paymentAddress);
}
when(profileAccount.getCurrentProfileVersion()).thenReturn(Optional.of(version));
@@ -994,7 +994,7 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get(VersionedProfileResponse.class);
assertThat(profile.getPaymentAddress()).containsExactly(paymentAddress);
assertThat(profile.paymentAddress()).containsExactly(paymentAddress);
}
when(profileAccount.getCurrentProfileVersion()).thenReturn(Optional.of(versionHex("someotherversion")));
@@ -1006,7 +1006,7 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get(VersionedProfileResponse.class);
assertThat(profile.getPaymentAddress()).isNull();
assertThat(profile.paymentAddress()).isNull();
}
}
@@ -1026,7 +1026,7 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get(ExpiringProfileKeyCredentialProfileResponse.class);
assertThat(profile.getVersionedProfileResponse().getBaseProfileResponse().getUuid())
assertThat(profile.getVersionedProfileResponse().baseProfileResponse().getUuid())
.isEqualTo(new AciServiceIdentifier(AuthHelper.VALID_UUID));
assertThat(profile.getCredential()).isNull();
@@ -1245,7 +1245,7 @@ class ProfileControllerTest {
.headers(authHeaders)
.get(ExpiringProfileKeyCredentialProfileResponse.class);
assertThat(profile.getVersionedProfileResponse().getBaseProfileResponse().getUuid())
assertThat(profile.getVersionedProfileResponse().baseProfileResponse().getUuid())
.isEqualTo(new AciServiceIdentifier(AuthHelper.VALID_UUID));
assertThat(profile.getCredential()).isEqualTo(credentialResponse);

View File

@@ -7,7 +7,6 @@ package org.whispersystems.textsecuregcm.controllers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
@@ -32,6 +31,7 @@ import java.util.Base64;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -519,7 +519,7 @@ class RegistrationControllerTest {
}
}
static Stream<Arguments> atomicAccountCreationConflictingChannel() {
static List<Arguments> atomicAccountCreationConflictingChannel() {
final IdentityKey aciIdentityKey;
final IdentityKey pniIdentityKey;
final ECSignedPreKey aciSignedPreKey;
@@ -544,48 +544,48 @@ class RegistrationControllerTest {
final AccountAttributes pushAccountAttributes =
new AccountAttributes(false, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, Set.of());
return Stream.of(
// "Fetches messages" is true, but an APNs token is provided
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
fetchesMessagesAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.of(new ApnRegistrationId("apns-token")),
Optional.empty())),
return List.of(
Arguments.argumentSet("\"Fetches messages\" is true, but an APNs token is provided",
new RegistrationRequest("session-id",
new byte[0],
fetchesMessagesAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.of(new ApnRegistrationId("apns-token")),
Optional.empty()))),
// "Fetches messages" is true, but an FCM (GCM) token is provided
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
fetchesMessagesAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.of(new GcmRegistrationId("gcm-token")))),
Arguments.argumentSet("\"Fetches messages\" is true, but an FCM (GCM) token is provided",
new RegistrationRequest("session-id",
new byte[0],
fetchesMessagesAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.of(new GcmRegistrationId("gcm-token"))))),
// "Fetches messages" is false, but multiple types of push tokens are provided
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
pushAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.of(new ApnRegistrationId("apns-token")),
Optional.of(new GcmRegistrationId("gcm-token"))))
Arguments.argumentSet("\"Fetches messages\" is false, but multiple types of push tokens are provided",
new RegistrationRequest("session-id",
new byte[0],
pushAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.of(new ApnRegistrationId("apns-token")),
Optional.of(new GcmRegistrationId("gcm-token")))))
);
}
@@ -608,7 +608,7 @@ class RegistrationControllerTest {
}
}
static Stream<Arguments> atomicAccountCreationPartialSignedPreKeys() {
static List<Arguments> atomicAccountCreationPartialSignedPreKeys() {
final IdentityKey aciIdentityKey;
final IdentityKey pniIdentityKey;
final ECSignedPreKey aciSignedPreKey;
@@ -630,90 +630,90 @@ class RegistrationControllerTest {
final AccountAttributes accountAttributes =
new AccountAttributes(true, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, Set.of());
return Stream.of(
// Signed PNI EC pre-key is missing
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
null,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty())),
return List.of(
Arguments.argumentSet("Signed PNI EC pre-key is missing",
new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
null,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty()))),
// Signed ACI EC pre-key is missing
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
null,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty())),
Arguments.argumentSet("Signed ACI EC pre-key is missing",
new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(null,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty()))),
// Signed PNI KEM pre-key is missing
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
null,
Optional.empty(),
Optional.empty())),
Arguments.argumentSet("Signed PNI KEM pre-key is missing",
new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
null,
Optional.empty(),
Optional.empty()))),
// Signed ACI KEM pre-key is missing
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
null,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty())),
Arguments.argumentSet("Signed ACI KEM pre-key is missing",
new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
null,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty()))),
// All signed pre-keys are present, but ACI identity key is missing
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
null,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty())),
Arguments.argumentSet("All signed pre-keys are present, but ACI identity key is missing",
new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
null,
pniIdentityKey,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty()))),
// All signed pre-keys are present, but PNI identity key is missing
Arguments.of(new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
null,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty()))
Arguments.argumentSet("All signed pre-keys are present, but PNI identity key is missing",
new RegistrationRequest("session-id",
new byte[0],
accountAttributes,
true,
aciIdentityKey,
null,
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty())))
);
}
@@ -789,7 +789,7 @@ class RegistrationControllerTest {
try (Response response = request.post(Entity.json(requestJson("sessionId")))) {
assertEquals(200, response.getStatus());
final AccountCreationResponse creationResponse = response.readEntity(AccountCreationResponse.class);
assertEquals(existingAccount, creationResponse.isReregistration());
assertEquals(existingAccount, creationResponse.reregistration());
}
}
@@ -806,7 +806,7 @@ class RegistrationControllerTest {
&& Objects.equals(a.recoveryPassword(), b.recoveryPassword());
}
private static Stream<Arguments> atomicAccountCreationSuccess() {
private static List<Arguments> atomicAccountCreationSuccess() {
final IdentityKey aciIdentityKey;
final IdentityKey pniIdentityKey;
final ECSignedPreKey aciSignedPreKey;
@@ -840,20 +840,20 @@ class RegistrationControllerTest {
final String apnsToken = "apns-token";
final String gcmToken = "gcm-token";
return Stream.of(
// Fetches messages; no push tokens
Arguments.of(new RegistrationRequest("session-id",
return List.of(
Arguments.argumentSet("Fetches messages; no push tokens",
new RegistrationRequest("session-id",
new byte[0],
fetchesMessagesAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty()),
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.empty())),
aciIdentityKey,
pniIdentityKey,
new DeviceSpec(
@@ -871,19 +871,19 @@ class RegistrationControllerTest {
aciPqLastResortPreKey,
pniPqLastResortPreKey)),
// Has APNs tokens
Arguments.of(new RegistrationRequest("session-id",
Arguments.argumentSet("Has APNs tokens",
new RegistrationRequest("session-id",
new byte[0],
pushAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.of(new ApnRegistrationId(apnsToken)),
Optional.empty()),
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.of(new ApnRegistrationId(apnsToken)),
Optional.empty())),
aciIdentityKey,
pniIdentityKey,
new DeviceSpec(
@@ -901,19 +901,19 @@ class RegistrationControllerTest {
aciPqLastResortPreKey,
pniPqLastResortPreKey)),
// Has GCM token
Arguments.of(new RegistrationRequest("session-id",
Arguments.argumentSet("Has GCM token",
new RegistrationRequest("session-id",
new byte[0],
pushAccountAttributes,
true,
aciIdentityKey,
pniIdentityKey,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.of(new GcmRegistrationId(gcmToken))),
new DeviceActivationRequest(aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey,
Optional.empty(),
Optional.of(new GcmRegistrationId(gcmToken)))),
aciIdentityKey,
pniIdentityKey,
new DeviceSpec(
@@ -965,7 +965,6 @@ class RegistrationControllerTest {
KeysHelper.signedKEMPreKey(4, pniIdentityKeyPair),
Optional.empty(),
Optional.empty()));
try {
return SystemMapper.jsonMapper().writerWithDefaultPrettyPrinter().writeValueAsString(request);
} catch (final JsonProcessingException e) {