Add AccountAttributes serialization test

This commit is contained in:
Chris Eager 2026-04-13 15:29:37 -05:00 committed by Chris Eager
parent 04aa528ad8
commit 2344d3d9b7

View File

@ -0,0 +1,58 @@
/*
* Copyright 2026 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.entities;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Base64;
import org.junit.jupiter.api.Test;
import org.whispersystems.textsecuregcm.util.SystemMapper;
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
class AccountAttributesTest {
private static final ObjectMapper mapper = SystemMapper.jsonMapper();
@Test
void testSerializationDeserialization() throws Exception {
final String originalJson = testJson();
final AccountAttributes attributes = mapper.readValue(originalJson, AccountAttributes.class);
assertEquals(originalJson, mapper.writerWithDefaultPrettyPrinter().writeValueAsString(attributes));
}
private static String testJson() {
return String.format("""
{
"fetchesMessages" : false,
"registrationId" : 123,
"name" : "%s",
"registrationLock" : null,
"unidentifiedAccessKey" : "%s",
"unrestrictedUnidentifiedAccess" : false,
"capabilities" : {
"storage" : true
},
"discoverableByPhoneNumber" : true,
"recoveryPassword" : "%s",
"pniRegistrationId" : 456
}
""",
Base64.getEncoder().withoutPadding().encodeToString(TestRandomUtil.nextBytes(128)), // name
Base64.getEncoder().encodeToString(TestRandomUtil.nextBytes(16)), // unidentifiedAccessKey
Base64.getEncoder().encodeToString(TestRandomUtil.nextBytes(32)) // recoveryPassword
).trim();
}
}