Skip to content

Commit

Permalink
Update to libsignal 0.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jrose-signal authored and eager-signal committed Jul 21, 2023
1 parent 3b3ecc0 commit e6f7d32
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -99,7 +99,7 @@
<dependency>
<groupId>org.signal</groupId>
<artifactId>libsignal-server</artifactId>
<version>0.21.1</version>
<version>0.30.0</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
Expand Down
Expand Up @@ -13,6 +13,8 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.signal.libsignal.protocol.ServiceId.Aci;
import org.signal.libsignal.protocol.ServiceId.Pni;
import org.signal.libsignal.zkgroup.ServerSecretParams;
import org.signal.libsignal.zkgroup.VerificationFailedException;
import org.signal.libsignal.zkgroup.auth.AuthCredential;
Expand Down Expand Up @@ -74,8 +76,8 @@ private static void assertGroupUserEqual(final GroupUser expected, final GroupUs
}

private static Stream<Arguments> authenticate() throws VerificationFailedException {
final UUID aci = UUID.randomUUID();
final UUID pni = UUID.randomUUID();
final Aci aci = new Aci(UUID.randomUUID());
final Pni pni = new Pni(UUID.randomUUID());

final Instant redemptionInstant = Instant.now().truncatedTo(ChronoUnit.DAYS);
final int redemptionDaysSinceEpoch = (int) ChronoUnit.DAYS.between(Instant.EPOCH, redemptionInstant);
Expand All @@ -101,8 +103,8 @@ private static Stream<Arguments> authenticate() throws VerificationFailedExcepti
final byte[] aciPniAuthCredentialPresentation;
final GroupUser expectedAciPniGroupUser;
{
final AuthCredentialWithPniResponse authCredentialWithPniResponse = serverZkAuthOperations.issueAuthCredentialWithPni(aci, pni, redemptionInstant);
final AuthCredentialWithPni authCredentialWithPni = clientZkAuthOperations.receiveAuthCredentialWithPni(aci, pni, redemptionInstant.getEpochSecond(), authCredentialWithPniResponse);
final AuthCredentialWithPniResponse authCredentialWithPniResponse = serverZkAuthOperations.issueAuthCredentialWithPniAsServiceId(aci, pni, redemptionInstant);
final AuthCredentialWithPni authCredentialWithPni = clientZkAuthOperations.receiveAuthCredentialWithPniAsServiceId(aci, pni, redemptionInstant.getEpochSecond(), authCredentialWithPniResponse);
final AuthCredentialPresentation authCredentialPresentation = clientZkAuthOperations.createAuthCredentialPresentation(GROUP_SECRET_PARAMS, authCredentialWithPni);

aciPniAuthCredentialPresentation = authCredentialPresentation.serialize();
Expand Down
Expand Up @@ -67,7 +67,7 @@ class StorageControllerTest {

@Test
void testGetManifest() throws IOException {
when(storageManager.getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER)))))
when(storageManager.getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID()))))
.thenReturn(CompletableFuture.completedFuture(Optional.of(StorageManifest.newBuilder()
.setVersion(22)
.setValue(ByteString.copyFromUtf8("A manifest"))
Expand All @@ -89,13 +89,13 @@ void testGetManifest() throws IOException {
assertThat(manifest.getVersion()).isEqualTo(22);
assertThat(manifest.getValue().toStringUtf8()).isEqualTo("A manifest");

verify(storageManager, times(1)).getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER))));
verify(storageManager, times(1)).getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID())));
verifyNoMoreInteractions(storageManager);
}

@Test
void testGetManifestIfDifferentFromVersionSuccess() throws IOException {
when(storageManager.getManifestIfNotVersion(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), eq(21L)))
when(storageManager.getManifestIfNotVersion(eq(new User(AuthHelper.VALID_USER.getRawUUID())), eq(21L)))
.thenReturn(CompletableFuture.completedFuture(Optional.of(StorageManifest.newBuilder()
.setVersion(22)
.setValue(ByteString.copyFromUtf8("A manifest"))
Expand All @@ -117,13 +117,13 @@ void testGetManifestIfDifferentFromVersionSuccess() throws IOException {
assertThat(manifest.getVersion()).isEqualTo(22L);
assertThat(manifest.getValue().toStringUtf8()).isEqualTo("A manifest");

verify(storageManager, times(1)).getManifestIfNotVersion(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), eq(21L));
verify(storageManager, times(1)).getManifestIfNotVersion(eq(new User(AuthHelper.VALID_USER.getRawUUID())), eq(21L));
verifyNoMoreInteractions(storageManager);
}

@Test
void testGetManifestIfDifferentFromVersionNoUpdate() throws IOException {
when(storageManager.getManifestIfNotVersion(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), eq(22L)))
when(storageManager.getManifestIfNotVersion(eq(new User(AuthHelper.VALID_USER.getRawUUID())), eq(22L)))
.thenReturn(CompletableFuture.completedFuture(Optional.empty()));

Response response = resources.getJerseyTest()
Expand All @@ -134,14 +134,14 @@ void testGetManifestIfDifferentFromVersionNoUpdate() throws IOException {

assertThat(response.getStatus()).isEqualTo(204);

verify(storageManager, times(1)).getManifestIfNotVersion(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), eq(22L));
verify(storageManager, times(1)).getManifestIfNotVersion(eq(new User(AuthHelper.VALID_USER.getRawUUID())), eq(22L));
verifyNoMoreInteractions(storageManager);
}


@Test
void testGetManifestUnauthorized() throws IOException {
when(storageManager.getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER)))))
when(storageManager.getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID()))))
.thenReturn(CompletableFuture.completedFuture(Optional.of(StorageManifest.newBuilder()
.setVersion(22)
.setValue(ByteString.copyFromUtf8("A manifest"))
Expand All @@ -159,7 +159,7 @@ void testGetManifestUnauthorized() throws IOException {

@Test
void testGetManifestFiveHundred() throws IOException {
when(storageManager.getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER)))))
when(storageManager.getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID()))))
.thenReturn(CompletableFuture.failedFuture(new RuntimeException("Bad news")));

Response response = resources.getJerseyTest()
Expand All @@ -170,13 +170,13 @@ void testGetManifestFiveHundred() throws IOException {

assertThat(response.getStatus()).isEqualTo(500);

verify(storageManager).getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER))));
verify(storageManager).getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID())));
verifyNoMoreInteractions(storageManager);
}

@Test
void testGetManifestNotFound() throws IOException {
when(storageManager.getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER))))).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
when(storageManager.getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID())))).thenReturn(CompletableFuture.completedFuture(Optional.empty()));

Response response = resources.getJerseyTest()
.target("/v1/storage/manifest")
Expand All @@ -185,13 +185,13 @@ void testGetManifestNotFound() throws IOException {
.get();

assertThat(response.getStatus()).isEqualTo(404);
verify(storageManager, times(1)).getManifest(eq(new User(UUID.fromString(AuthHelper.VALID_USER))));
verify(storageManager, times(1)).getManifest(eq(new User(AuthHelper.VALID_USER.getRawUUID())));
verifyNoMoreInteractions(storageManager);
}

@Test
void testWrite() {
when(storageManager.set(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), any(StorageManifest.class), anyList(), anyList())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
when(storageManager.set(eq(new User(AuthHelper.VALID_USER.getRawUUID())), any(StorageManifest.class), anyList(), anyList())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));

StorageManifest manifest = StorageManifest.newBuilder()
.setVersion(1337)
Expand Down Expand Up @@ -234,7 +234,7 @@ void testWrite() {
ArgumentCaptor<List<StorageItem>> insertCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<List<ByteString>> deleteCaptor = ArgumentCaptor.forClass(List.class);

verify(storageManager, times(1)).set(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), eq(manifest), insertCaptor.capture(), deleteCaptor.capture());
verify(storageManager, times(1)).set(eq(new User(AuthHelper.VALID_USER.getRawUUID())), eq(manifest), insertCaptor.capture(), deleteCaptor.capture());
verifyNoMoreInteractions(storageManager);

assertThat(insertCaptor.getValue().size()).isEqualTo(2);
Expand All @@ -249,7 +249,7 @@ void testWrite() {

@Test
void testWriteUnauthorized() {
when(storageManager.set(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), any(StorageManifest.class), anyList(), anyList())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
when(storageManager.set(eq(new User(AuthHelper.VALID_USER.getRawUUID())), any(StorageManifest.class), anyList(), anyList())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));

StorageManifest manifest = StorageManifest.newBuilder()
.setVersion(1337)
Expand Down Expand Up @@ -298,7 +298,7 @@ void testWriteStale() throws IOException {
.setValue(ByteString.copyFromUtf8("Current manifest"))
.build();

when(storageManager.set(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), any(StorageManifest.class), anyList(), anyList()))
when(storageManager.set(eq(new User(AuthHelper.VALID_USER.getRawUUID())), any(StorageManifest.class), anyList(), anyList()))
.thenReturn(CompletableFuture.completedFuture(Optional.of(currentManifest)));

StorageManifest stale = StorageManifest.newBuilder()
Expand Down Expand Up @@ -346,7 +346,7 @@ void testWriteStale() throws IOException {

assertThat(manifest).isEqualTo(currentManifest);

verify(storageManager, times(1)).set(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), eq(stale), anyList(), anyList());
verify(storageManager, times(1)).set(eq(new User(AuthHelper.VALID_USER.getRawUUID())), eq(stale), anyList(), anyList());
verifyNoMoreInteractions(storageManager);
}

Expand Down Expand Up @@ -430,7 +430,7 @@ void testRead() throws IOException {
.setValue(ByteString.copyFromUtf8("valueTwo"))
.build();

when(storageManager.getItems(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), anyList()))
when(storageManager.getItems(eq(new User(AuthHelper.VALID_USER.getRawUUID())), anyList()))
.thenReturn(CompletableFuture.completedFuture(List.of(queryOne, queryTwo)));


Expand All @@ -457,7 +457,7 @@ void testRead() throws IOException {

ArgumentCaptor<List<ByteString>> keysCaptor = ArgumentCaptor.forClass(List.class);

verify(storageManager, times(1)).getItems(eq(new User(UUID.fromString(AuthHelper.VALID_USER))), keysCaptor.capture());
verify(storageManager, times(1)).getItems(eq(new User(AuthHelper.VALID_USER.getRawUUID())), keysCaptor.capture());
verifyNoMoreInteractions(storageManager);

assertThat(keysCaptor.getValue().size()).isEqualTo(2);
Expand All @@ -478,7 +478,7 @@ void testDelete() {
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.hasEntity()).isFalse();

verify(storageManager).delete(eq(new User(UUID.fromString(AuthHelper.VALID_USER))));
verify(storageManager).delete(eq(new User(AuthHelper.VALID_USER.getRawUUID())));
verifyNoMoreInteractions(storageManager);
}

Expand Down

0 comments on commit e6f7d32

Please sign in to comment.