From 2344d3d9b74d8158a981752ea36cbf2db08cd441 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Mon, 13 Apr 2026 15:29:37 -0500 Subject: [PATCH] Add AccountAttributes serialization test --- .../entities/AccountAttributesTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 service/src/test/java/org/whispersystems/textsecuregcm/entities/AccountAttributesTest.java diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/entities/AccountAttributesTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/entities/AccountAttributesTest.java new file mode 100644 index 000000000..420b04524 --- /dev/null +++ b/service/src/test/java/org/whispersystems/textsecuregcm/entities/AccountAttributesTest.java @@ -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(); + + } + + +}