mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 12:18:07 +01:00
Update to libsignal 0.45 and use libsignal's BackupLevel
This commit is contained in:
committed by
ravi-signal
parent
c8efcf5105
commit
19944bfdb2
@@ -37,6 +37,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.NullSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.signal.libsignal.zkgroup.InvalidInputException;
|
||||
@@ -44,6 +45,7 @@ import org.signal.libsignal.zkgroup.ServerSecretParams;
|
||||
import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialRequest;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialRequestContext;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupLevel;
|
||||
import org.signal.libsignal.zkgroup.receipts.ClientZkReceiptOperations;
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptCredential;
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialPresentation;
|
||||
@@ -61,6 +63,7 @@ import org.whispersystems.textsecuregcm.tests.util.ExperimentHelper;
|
||||
import org.whispersystems.textsecuregcm.util.CompletableFutureTestUtil;
|
||||
import org.whispersystems.textsecuregcm.util.TestClock;
|
||||
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BackupAuthManagerTest {
|
||||
|
||||
@@ -79,9 +82,9 @@ public class BackupAuthManagerTest {
|
||||
reset(redeemedReceiptsManager);
|
||||
}
|
||||
|
||||
BackupAuthManager create(BackupTier backupTier, boolean rateLimit) {
|
||||
BackupAuthManager create(@Nullable BackupLevel backupLevel, boolean rateLimit) {
|
||||
return new BackupAuthManager(
|
||||
ExperimentHelper.withEnrollment(experimentName(backupTier), aci),
|
||||
ExperimentHelper.withEnrollment(experimentName(backupLevel), aci),
|
||||
rateLimit ? denyRateLimiter(aci) : allowRateLimiter(),
|
||||
accountsManager,
|
||||
new ServerZkReceiptOperations(receiptParams),
|
||||
@@ -92,15 +95,16 @@ public class BackupAuthManagerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource
|
||||
void commitRequiresBackupTier(final BackupTier backupTier) {
|
||||
final BackupAuthManager authManager = create(backupTier, false);
|
||||
@NullSource
|
||||
void commitRequiresBackupLevel(final BackupLevel backupLevel) {
|
||||
final BackupAuthManager authManager = create(backupLevel, false);
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
when(accountsManager.updateAsync(any(), any())).thenReturn(CompletableFuture.completedFuture(account));
|
||||
|
||||
final ThrowableAssert.ThrowingCallable commit = () ->
|
||||
authManager.commitBackupId(account, backupAuthTestUtil.getRequest(backupKey, aci)).join();
|
||||
if (backupTier == BackupTier.NONE) {
|
||||
if (backupLevel == null) {
|
||||
Assertions.assertThatExceptionOfType(StatusRuntimeException.class)
|
||||
.isThrownBy(commit)
|
||||
.extracting(ex -> ex.getStatus().getCode())
|
||||
@@ -113,8 +117,9 @@ public class BackupAuthManagerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource
|
||||
void credentialsRequiresBackupTier(final BackupTier backupTier) {
|
||||
final BackupAuthManager authManager = create(backupTier, false);
|
||||
@NullSource
|
||||
void credentialsRequiresBackupLevel(final BackupLevel backupLevel) {
|
||||
final BackupAuthManager authManager = create(backupLevel, false);
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
@@ -125,7 +130,7 @@ public class BackupAuthManagerTest {
|
||||
clock.instant().truncatedTo(ChronoUnit.DAYS),
|
||||
clock.instant().plus(Duration.ofDays(1)).truncatedTo(ChronoUnit.DAYS)).join())
|
||||
.hasSize(2);
|
||||
if (backupTier == BackupTier.NONE) {
|
||||
if (backupLevel == null) {
|
||||
Assertions.assertThatExceptionOfType(StatusRuntimeException.class)
|
||||
.isThrownBy(getCreds)
|
||||
.extracting(ex -> ex.getStatus().getCode())
|
||||
@@ -136,9 +141,9 @@ public class BackupAuthManagerTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = {"NONE"})
|
||||
void getReceiptCredentials(final BackupTier backupTier) throws VerificationFailedException {
|
||||
final BackupAuthManager authManager = create(backupTier, false);
|
||||
@EnumSource
|
||||
void getReceiptCredentials(final BackupLevel backupLevel) throws VerificationFailedException {
|
||||
final BackupAuthManager authManager = create(backupLevel, false);
|
||||
|
||||
final BackupAuthCredentialRequestContext requestContext = BackupAuthCredentialRequestContext.create(backupKey, aci);
|
||||
|
||||
@@ -153,10 +158,11 @@ public class BackupAuthManagerTest {
|
||||
assertThat(creds).hasSize(8);
|
||||
Instant redemptionTime = start;
|
||||
for (BackupAuthManager.Credential cred : creds) {
|
||||
requestContext.receiveResponse(cred.credential(), backupAuthTestUtil.params.getPublicParams(),
|
||||
backupTier.getReceiptLevel());
|
||||
assertThat(cred.redemptionTime().getEpochSecond())
|
||||
.isEqualTo(redemptionTime.getEpochSecond());
|
||||
assertThat(requestContext
|
||||
.receiveResponse(cred.credential(), redemptionTime, backupAuthTestUtil.params.getPublicParams())
|
||||
.getBackupLevel())
|
||||
.isEqualTo(backupLevel);
|
||||
assertThat(cred.redemptionTime().getEpochSecond()).isEqualTo(redemptionTime.getEpochSecond());
|
||||
redemptionTime = redemptionTime.plus(Duration.ofDays(1));
|
||||
}
|
||||
}
|
||||
@@ -185,7 +191,7 @@ public class BackupAuthManagerTest {
|
||||
@MethodSource
|
||||
void invalidCredentialTimeWindows(final Instant requestRedemptionStart, final Instant requestRedemptionEnd,
|
||||
final Instant now) {
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
@@ -206,21 +212,24 @@ public class BackupAuthManagerTest {
|
||||
final Instant day4 = Instant.EPOCH.plus(Duration.ofDays(4));
|
||||
final Instant dayMax = day0.plus(BackupAuthManager.MAX_REDEMPTION_DURATION);
|
||||
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
when(account.getBackupCredentialRequest()).thenReturn(backupAuthTestUtil.getRequest(backupKey, aci).serialize());
|
||||
when(account.getBackupVoucher()).thenReturn(new Account.BackupVoucher(BackupTier.MEDIA.getReceiptLevel(), day4));
|
||||
when(account.getBackupVoucher()).thenReturn(new Account.BackupVoucher(201, day4));
|
||||
|
||||
final List<BackupAuthManager.Credential> creds = authManager.getBackupAuthCredentials(account, day0, dayMax).join();
|
||||
Instant redemptionTime = day0;
|
||||
final BackupAuthCredentialRequestContext requestContext = BackupAuthCredentialRequestContext.create(backupKey, aci);
|
||||
for (int i = 0; i < creds.size(); i++) {
|
||||
// Before the expiration, credentials should have a media receipt, otherwise messages only
|
||||
final long level = i < 5 ? BackupTier.MEDIA.getReceiptLevel() : BackupTier.MESSAGES.getReceiptLevel();
|
||||
final BackupLevel level = i < 5 ? BackupLevel.MEDIA : BackupLevel.MESSAGES;
|
||||
final BackupAuthManager.Credential cred = creds.get(i);
|
||||
requestContext.receiveResponse(cred.credential(), backupAuthTestUtil.params.getPublicParams(), level);
|
||||
assertThat(requestContext
|
||||
.receiveResponse(cred.credential(), redemptionTime, backupAuthTestUtil.params.getPublicParams())
|
||||
.getBackupLevel())
|
||||
.isEqualTo(level);
|
||||
assertThat(cred.redemptionTime().getEpochSecond()).isEqualTo(redemptionTime.getEpochSecond());
|
||||
redemptionTime = redemptionTime.plus(Duration.ofDays(1));
|
||||
}
|
||||
@@ -232,7 +241,7 @@ public class BackupAuthManagerTest {
|
||||
final Instant day2 = Instant.EPOCH.plus(Duration.ofDays(2));
|
||||
final Instant day3 = Instant.EPOCH.plus(Duration.ofDays(3));
|
||||
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
when(account.getBackupVoucher()).thenReturn(new Account.BackupVoucher(3, day1));
|
||||
@@ -247,8 +256,8 @@ public class BackupAuthManagerTest {
|
||||
assertThat(authManager.getBackupAuthCredentials(account, day2, day2.plus(Duration.ofDays(7))).join())
|
||||
.hasSize(8);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArgumentCaptor<Consumer<Account>> accountUpdater = ArgumentCaptor.forClass(Consumer.class);
|
||||
@SuppressWarnings("unchecked") final ArgumentCaptor<Consumer<Account>> accountUpdater = ArgumentCaptor.forClass(
|
||||
Consumer.class);
|
||||
verify(accountsManager, times(1)).updateAsync(any(), accountUpdater.capture());
|
||||
|
||||
// If the account is not expired when we go to update it, we shouldn't wipe it out
|
||||
@@ -268,7 +277,7 @@ public class BackupAuthManagerTest {
|
||||
@Test
|
||||
void redeemReceipt() throws InvalidInputException, VerificationFailedException {
|
||||
final Instant expirationTime = Instant.EPOCH.plus(Duration.ofDays(1));
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
|
||||
@@ -285,8 +294,7 @@ public class BackupAuthManagerTest {
|
||||
final Instant newExpirationTime = Instant.EPOCH.plus(Duration.ofDays(1));
|
||||
final Instant existingExpirationTime = Instant.EPOCH.plus(Duration.ofDays(1)).plus(Duration.ofSeconds(1));
|
||||
|
||||
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
|
||||
@@ -311,7 +319,7 @@ public class BackupAuthManagerTest {
|
||||
void redeemExpiredReceipt() {
|
||||
final Instant expirationTime = Instant.EPOCH.plus(Duration.ofDays(1));
|
||||
clock.pin(expirationTime.plus(Duration.ofSeconds(1)));
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
Assertions.assertThatExceptionOfType(StatusRuntimeException.class)
|
||||
.isThrownBy(() -> authManager.redeemReceipt(mock(Account.class), receiptPresentation(3, expirationTime)).join())
|
||||
.extracting(ex -> ex.getStatus().getCode())
|
||||
@@ -325,7 +333,7 @@ public class BackupAuthManagerTest {
|
||||
void redeemInvalidLevel(long level) {
|
||||
final Instant expirationTime = Instant.EPOCH.plus(Duration.ofDays(1));
|
||||
clock.pin(expirationTime.plus(Duration.ofSeconds(1)));
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
Assertions.assertThatExceptionOfType(StatusRuntimeException.class)
|
||||
.isThrownBy(() ->
|
||||
authManager.redeemReceipt(mock(Account.class), receiptPresentation(level, expirationTime)).join())
|
||||
@@ -337,7 +345,7 @@ public class BackupAuthManagerTest {
|
||||
|
||||
@Test
|
||||
void redeemInvalidPresentation() throws InvalidInputException, VerificationFailedException {
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
final ReceiptCredentialPresentation invalid = receiptPresentation(ServerSecretParams.generate(), 3L, Instant.EPOCH);
|
||||
Assertions.assertThatExceptionOfType(StatusRuntimeException.class)
|
||||
.isThrownBy(() -> authManager.redeemReceipt(mock(Account.class), invalid).join())
|
||||
@@ -350,7 +358,7 @@ public class BackupAuthManagerTest {
|
||||
@Test
|
||||
void receiptAlreadyRedeemed() throws InvalidInputException, VerificationFailedException {
|
||||
final Instant expirationTime = Instant.EPOCH.plus(Duration.ofDays(1));
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, false);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, false);
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
|
||||
@@ -390,7 +398,7 @@ public class BackupAuthManagerTest {
|
||||
@Test
|
||||
void testRateLimits() {
|
||||
final AccountsManager accountsManager = mock(AccountsManager.class);
|
||||
final BackupAuthManager authManager = create(BackupTier.MESSAGES, true);
|
||||
final BackupAuthManager authManager = create(BackupLevel.MESSAGES, true);
|
||||
|
||||
final BackupAuthCredentialRequest credentialRequest = backupAuthTestUtil.getRequest(backupKey, aci);
|
||||
|
||||
@@ -407,11 +415,11 @@ public class BackupAuthManagerTest {
|
||||
assertDoesNotThrow(() -> authManager.commitBackupId(account, credentialRequest).join());
|
||||
}
|
||||
|
||||
private static String experimentName(BackupTier backupTier) {
|
||||
return switch (backupTier) {
|
||||
private static String experimentName(@Nullable BackupLevel backupLevel) {
|
||||
return switch (backupLevel) {
|
||||
case MESSAGES -> BackupAuthManager.BACKUP_EXPERIMENT_NAME;
|
||||
case MEDIA -> BackupAuthManager.BACKUP_MEDIA_EXPERIMENT_NAME;
|
||||
case NONE -> "fake_experiment";
|
||||
case null -> "fake_experiment";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialPresentation;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialRequest;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialRequestContext;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupLevel;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.tests.util.ExperimentHelper;
|
||||
|
||||
@@ -35,32 +36,32 @@ public class BackupAuthTestUtil {
|
||||
}
|
||||
|
||||
public BackupAuthCredentialPresentation getPresentation(
|
||||
final BackupTier backupTier, final byte[] backupKey, final UUID aci)
|
||||
final BackupLevel backupLevel, final byte[] backupKey, final UUID aci)
|
||||
throws VerificationFailedException {
|
||||
return getPresentation(params, backupTier, backupKey, aci);
|
||||
return getPresentation(params, backupLevel, backupKey, aci);
|
||||
}
|
||||
|
||||
public BackupAuthCredentialPresentation getPresentation(
|
||||
GenericServerSecretParams params, final BackupTier backupTier, final byte[] backupKey, final UUID aci)
|
||||
GenericServerSecretParams params, final BackupLevel backupLevel, final byte[] backupKey, final UUID aci)
|
||||
throws VerificationFailedException {
|
||||
final Instant redemptionTime = clock.instant().truncatedTo(ChronoUnit.DAYS);
|
||||
final BackupAuthCredentialRequestContext ctx = BackupAuthCredentialRequestContext.create(backupKey, aci);
|
||||
return ctx.receiveResponse(
|
||||
ctx.getRequest()
|
||||
.issueCredential(clock.instant().truncatedTo(ChronoUnit.DAYS), backupTier.getReceiptLevel(), params),
|
||||
params.getPublicParams(),
|
||||
backupTier.getReceiptLevel())
|
||||
.issueCredential(clock.instant().truncatedTo(ChronoUnit.DAYS), backupLevel, params),
|
||||
redemptionTime,
|
||||
params.getPublicParams())
|
||||
.present(params.getPublicParams());
|
||||
}
|
||||
|
||||
public List<BackupAuthManager.Credential> getCredentials(
|
||||
final BackupTier backupTier,
|
||||
final BackupLevel backupLevel,
|
||||
final BackupAuthCredentialRequest request,
|
||||
final Instant redemptionStart,
|
||||
final Instant redemptionEnd) {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
|
||||
final String experimentName = switch (backupTier) {
|
||||
case NONE -> "notUsed";
|
||||
final String experimentName = switch (backupLevel) {
|
||||
case MESSAGES -> BackupAuthManager.BACKUP_EXPERIMENT_NAME;
|
||||
case MEDIA -> BackupAuthManager.BACKUP_MEDIA_EXPERIMENT_NAME;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
@@ -61,6 +60,7 @@ import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.signal.libsignal.zkgroup.GenericServerSecretParams;
|
||||
import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialPresentation;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupLevel;
|
||||
import org.whispersystems.textsecuregcm.attachments.TusAttachmentGenerator;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticatedBackupUser;
|
||||
import org.whispersystems.textsecuregcm.controllers.RateLimitExceededException;
|
||||
@@ -90,7 +90,6 @@ public class BackupManagerTest {
|
||||
private final RemoteStorageManager remoteStorageManager = mock(RemoteStorageManager.class);
|
||||
private final byte[] backupKey = TestRandomUtil.nextBytes(32);
|
||||
private final UUID aci = UUID.randomUUID();
|
||||
private final SecureRandom secureRandom = new SecureRandom();
|
||||
|
||||
private BackupManager backupManager;
|
||||
private BackupsDb backupsDb;
|
||||
@@ -119,13 +118,13 @@ public class BackupManagerTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = {"NONE"})
|
||||
public void createBackup(final BackupTier backupTier) {
|
||||
@EnumSource
|
||||
public void createBackup(final BackupLevel backupLevel) {
|
||||
|
||||
final Instant now = Instant.ofEpochSecond(Duration.ofDays(1).getSeconds());
|
||||
testClock.pin(now);
|
||||
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), backupTier);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), backupLevel);
|
||||
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser).join();
|
||||
verify(tusCredentialGenerator, times(1))
|
||||
@@ -137,12 +136,12 @@ public class BackupManagerTest {
|
||||
assertThat(info.mediaUsedSpace()).isEqualTo(Optional.empty());
|
||||
|
||||
// Check that the initial expiration times are the initial write times
|
||||
checkExpectedExpirations(now, backupTier == BackupTier.MEDIA ? now : null, backupUser);
|
||||
checkExpectedExpirations(now, backupLevel == BackupLevel.MEDIA ? now : null, backupUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTemporaryMediaAttachmentRateLimited() throws RateLimitExceededException {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
doThrow(new RateLimitExceededException(null, true))
|
||||
.when(mediaUploadLimiter)
|
||||
.validate(eq(BackupManager.rateLimitKey(backupUser)));
|
||||
@@ -153,8 +152,8 @@ public class BackupManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTemporaryMediaAttachmentWrongTier() throws RateLimitExceededException {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MESSAGES);
|
||||
public void createTemporaryMediaAttachmentWrongTier() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MESSAGES);
|
||||
assertThatExceptionOfType(StatusRuntimeException.class)
|
||||
.isThrownBy(() -> backupManager.createTemporaryAttachmentUploadDescriptor(backupUser))
|
||||
.extracting(StatusRuntimeException::getStatus)
|
||||
@@ -163,9 +162,9 @@ public class BackupManagerTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = {"NONE"})
|
||||
public void ttlRefresh(final BackupTier backupTier) {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), backupTier);
|
||||
@EnumSource
|
||||
public void ttlRefresh(final BackupLevel backupLevel) {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), backupLevel);
|
||||
|
||||
final Instant tstart = Instant.ofEpochSecond(1).plus(Duration.ofDays(1));
|
||||
final Instant tnext = tstart.plus(Duration.ofSeconds(1));
|
||||
@@ -180,17 +179,17 @@ public class BackupManagerTest {
|
||||
|
||||
checkExpectedExpirations(
|
||||
tnext,
|
||||
backupTier == BackupTier.MEDIA ? tnext : null,
|
||||
backupLevel == BackupLevel.MEDIA ? tnext : null,
|
||||
backupUser);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = {"NONE"})
|
||||
public void createBackupRefreshesTtl(final BackupTier backupTier) {
|
||||
@EnumSource
|
||||
public void createBackupRefreshesTtl(final BackupLevel backupLevel) {
|
||||
final Instant tstart = Instant.ofEpochSecond(1).plus(Duration.ofDays(1));
|
||||
final Instant tnext = tstart.plus(Duration.ofSeconds(1));
|
||||
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), backupTier);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), backupLevel);
|
||||
|
||||
// create backup at t=tstart
|
||||
testClock.pin(tstart);
|
||||
@@ -202,7 +201,7 @@ public class BackupManagerTest {
|
||||
|
||||
checkExpectedExpirations(
|
||||
tnext,
|
||||
backupTier == BackupTier.MEDIA ? tnext : null,
|
||||
backupLevel == BackupLevel.MEDIA ? tnext : null,
|
||||
backupUser);
|
||||
}
|
||||
|
||||
@@ -210,7 +209,7 @@ public class BackupManagerTest {
|
||||
public void invalidPresentationNoPublicKey() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation invalidPresentation = backupAuthTestUtil.getPresentation(
|
||||
GenericServerSecretParams.generate(),
|
||||
BackupTier.MESSAGES, backupKey, aci);
|
||||
BackupLevel.MESSAGES, backupKey, aci);
|
||||
|
||||
final ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
|
||||
@@ -228,10 +227,10 @@ public class BackupManagerTest {
|
||||
@Test
|
||||
public void invalidPresentationCorrectSignature() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MESSAGES, backupKey, aci);
|
||||
BackupLevel.MESSAGES, backupKey, aci);
|
||||
final BackupAuthCredentialPresentation invalidPresentation = backupAuthTestUtil.getPresentation(
|
||||
GenericServerSecretParams.generate(),
|
||||
BackupTier.MESSAGES, backupKey, aci);
|
||||
BackupLevel.MESSAGES, backupKey, aci);
|
||||
|
||||
final ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
backupManager.setPublicKey(
|
||||
@@ -251,7 +250,7 @@ public class BackupManagerTest {
|
||||
@Test
|
||||
public void unknownPublicKey() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MESSAGES, backupKey, aci);
|
||||
BackupLevel.MESSAGES, backupKey, aci);
|
||||
|
||||
final ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
final byte[] signature = keyPair.getPrivateKey().calculateSignature(presentation.serialize());
|
||||
@@ -267,7 +266,7 @@ public class BackupManagerTest {
|
||||
@Test
|
||||
public void mismatchedPublicKey() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MESSAGES, backupKey, aci);
|
||||
BackupLevel.MESSAGES, backupKey, aci);
|
||||
|
||||
final ECKeyPair keyPair1 = Curve.generateKeyPair();
|
||||
final ECKeyPair keyPair2 = Curve.generateKeyPair();
|
||||
@@ -290,7 +289,7 @@ public class BackupManagerTest {
|
||||
@Test
|
||||
public void signatureValidation() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MESSAGES, backupKey, aci);
|
||||
BackupLevel.MESSAGES, backupKey, aci);
|
||||
|
||||
final ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
final byte[] signature = keyPair.getPrivateKey().calculateSignature(presentation.serialize());
|
||||
@@ -317,7 +316,7 @@ public class BackupManagerTest {
|
||||
// correct signature
|
||||
final AuthenticatedBackupUser user = backupManager.authenticateBackupUser(presentation, signature).join();
|
||||
assertThat(user.backupId()).isEqualTo(presentation.getBackupId());
|
||||
assertThat(user.backupTier()).isEqualTo(BackupTier.MESSAGES);
|
||||
assertThat(user.backupLevel()).isEqualTo(BackupLevel.MESSAGES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -325,7 +324,7 @@ public class BackupManagerTest {
|
||||
|
||||
// credential for 1 day after epoch
|
||||
testClock.pin(Instant.ofEpochSecond(1).plus(Duration.ofDays(1)));
|
||||
final BackupAuthCredentialPresentation oldCredential = backupAuthTestUtil.getPresentation(BackupTier.MESSAGES,
|
||||
final BackupAuthCredentialPresentation oldCredential = backupAuthTestUtil.getPresentation(BackupLevel.MESSAGES,
|
||||
backupKey, aci);
|
||||
final ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
final byte[] signature = keyPair.getPrivateKey().calculateSignature(oldCredential.serialize());
|
||||
@@ -350,7 +349,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void copySuccess() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
when(tusCredentialGenerator.generateUpload(any()))
|
||||
.thenReturn(new BackupUploadDescriptor(3, "def", Collections.emptyMap(), ""));
|
||||
when(remoteStorageManager.copy(eq(URI.create("cdn3.example.org/attachments/abc")), eq(100), any(), any()))
|
||||
@@ -376,7 +375,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void copyFailure() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
when(tusCredentialGenerator.generateUpload(any()))
|
||||
.thenReturn(new BackupUploadDescriptor(3, "def", Collections.emptyMap(), ""));
|
||||
when(remoteStorageManager.copy(eq(URI.create("cdn3.example.org/attachments/abc")), eq(100), any(), any()))
|
||||
@@ -397,7 +396,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void unknownSourceCdn() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
CompletableFutureTestUtil.assertFailsWithCause(SourceObjectNotFoundException.class,
|
||||
backupManager.copyToBackup(
|
||||
backupUser,
|
||||
@@ -408,7 +407,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void quotaEnforcementNoRecalculation() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
verifyNoInteractions(remoteStorageManager);
|
||||
|
||||
// set the backupsDb to be out of quota at t=0
|
||||
@@ -423,7 +422,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void quotaEnforcementRecalculation() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
final String backupMediaPrefix = "%s/%s/".formatted(backupUser.backupDir(), backupUser.mediaDir());
|
||||
|
||||
// on recalculation, say there's actually 10 bytes left
|
||||
@@ -460,7 +459,7 @@ public class BackupManagerTest {
|
||||
final long spaceLeft,
|
||||
final long mediaToAddSize,
|
||||
boolean shouldAccept) {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
final String backupMediaPrefix = "%s/%s/".formatted(backupUser.backupDir(), backupUser.mediaDir());
|
||||
|
||||
// set the backupsDb to be out of quota at t=0
|
||||
@@ -485,7 +484,7 @@ public class BackupManagerTest {
|
||||
@ValueSource(strings = {"", "cursor"})
|
||||
public void list(final String cursorVal) {
|
||||
final Optional<String> cursor = Optional.of(cursorVal).filter(StringUtils::isNotBlank);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
final String backupMediaPrefix = "%s/%s/".formatted(backupUser.backupDir(), backupUser.mediaDir());
|
||||
|
||||
when(remoteStorageManager.cdnNumber()).thenReturn(13);
|
||||
@@ -498,24 +497,24 @@ public class BackupManagerTest {
|
||||
final BackupManager.ListMediaResult result = backupManager.list(backupUser, cursor, 17)
|
||||
.toCompletableFuture().join();
|
||||
assertThat(result.media()).hasSize(1);
|
||||
assertThat(result.media().get(0).cdn()).isEqualTo(13);
|
||||
assertThat(result.media().get(0).key()).isEqualTo(
|
||||
assertThat(result.media().getFirst().cdn()).isEqualTo(13);
|
||||
assertThat(result.media().getFirst().key()).isEqualTo(
|
||||
Base64.getDecoder().decode("aaa".getBytes(StandardCharsets.UTF_8)));
|
||||
assertThat(result.media().get(0).length()).isEqualTo(123);
|
||||
assertThat(result.media().getFirst().length()).isEqualTo(123);
|
||||
assertThat(result.cursor().get()).isEqualTo("newCursor");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEntireBackup() {
|
||||
final AuthenticatedBackupUser original = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser original = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
|
||||
testClock.pin(Instant.ofEpochSecond(10));
|
||||
|
||||
// Deleting should swap the backupDir for the user
|
||||
backupManager.deleteEntireBackup(original).join();
|
||||
verifyNoInteractions(remoteStorageManager);
|
||||
final AuthenticatedBackupUser after = retrieveBackupUser(original.backupId(), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser after = retrieveBackupUser(original.backupId(), BackupLevel.MEDIA);
|
||||
assertThat(original.backupDir()).isNotEqualTo(after.backupDir());
|
||||
assertThat(original.mediaDir()).isNotEqualTo(after.mediaDir());
|
||||
|
||||
@@ -541,7 +540,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void delete() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
final byte[] mediaId = TestRandomUtil.nextBytes(16);
|
||||
final String backupMediaKey = "%s/%s/%s".formatted(
|
||||
backupUser.backupDir(),
|
||||
@@ -562,7 +561,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void deleteUnknownCdn() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
when(remoteStorageManager.cdnNumber()).thenReturn(5);
|
||||
assertThatThrownBy(() ->
|
||||
backupManager.delete(backupUser, List.of(new BackupManager.StorageDescriptor(4, TestRandomUtil.nextBytes(15)))))
|
||||
@@ -572,7 +571,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void deletePartialFailure() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
|
||||
final List<BackupManager.StorageDescriptor> descriptors = new ArrayList<>();
|
||||
long initialBytes = 0;
|
||||
@@ -605,7 +604,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void alreadyDeleted() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
final byte[] mediaId = TestRandomUtil.nextBytes(16);
|
||||
final String backupMediaKey = "%s/%s/%s".formatted(
|
||||
backupUser.backupDir(),
|
||||
@@ -627,7 +626,7 @@ public class BackupManagerTest {
|
||||
@Test
|
||||
public void listExpiredBackups() {
|
||||
final List<AuthenticatedBackupUser> backupUsers = IntStream.range(0, 10)
|
||||
.mapToObj(i -> backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA))
|
||||
.mapToObj(i -> backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA))
|
||||
.toList();
|
||||
for (int i = 0; i < backupUsers.size(); i++) {
|
||||
testClock.pin(Instant.ofEpochSecond(i));
|
||||
@@ -665,11 +664,11 @@ public class BackupManagerTest {
|
||||
|
||||
// refreshed media timestamp at t=5
|
||||
testClock.pin(Instant.ofEpochSecond(5));
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser(backupId, BackupTier.MEDIA)).join();
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser(backupId, BackupLevel.MEDIA)).join();
|
||||
|
||||
// refreshed messages timestamp at t=6
|
||||
testClock.pin(Instant.ofEpochSecond(6));
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser(backupId, BackupTier.MESSAGES)).join();
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser(backupId, BackupLevel.MESSAGES)).join();
|
||||
|
||||
Function<Instant, List<ExpiredBackup>> getExpired = time -> backupManager
|
||||
.getExpiredBackups(1, Schedulers.immediate(), time)
|
||||
@@ -689,7 +688,7 @@ public class BackupManagerTest {
|
||||
@ParameterizedTest
|
||||
@EnumSource(mode = EnumSource.Mode.INCLUDE, names = {"MEDIA", "ALL"})
|
||||
public void expireBackup(ExpiredBackup.ExpirationType expirationType) {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser).join();
|
||||
|
||||
final String expectedPrefixToDelete = switch (expirationType) {
|
||||
@@ -731,7 +730,7 @@ public class BackupManagerTest {
|
||||
|
||||
@Test
|
||||
public void deleteBackupPaginated() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
backupManager.createMessageBackupUploadDescriptor(backupUser).join();
|
||||
|
||||
final ExpiredBackup expiredBackup = expiredBackup(ExpiredBackup.ExpirationType.MEDIA, backupUser);
|
||||
@@ -814,23 +813,23 @@ public class BackupManagerTest {
|
||||
/**
|
||||
* Create BackupUser with the provided backupId and tier
|
||||
*/
|
||||
private AuthenticatedBackupUser backupUser(final byte[] backupId, final BackupTier backupTier) {
|
||||
private AuthenticatedBackupUser backupUser(final byte[] backupId, final BackupLevel backupLevel) {
|
||||
// Won't actually validate the public key, but need to have a public key to perform BackupsDB operations
|
||||
byte[] privateKey = new byte[32];
|
||||
ByteBuffer.wrap(privateKey).put(backupId);
|
||||
try {
|
||||
backupsDb.setPublicKey(backupId, backupTier, Curve.decodePrivatePoint(privateKey).publicKey()).join();
|
||||
backupsDb.setPublicKey(backupId, backupLevel, Curve.decodePrivatePoint(privateKey).publicKey()).join();
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return retrieveBackupUser(backupId, backupTier);
|
||||
return retrieveBackupUser(backupId, backupLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an existing BackupUser from the database
|
||||
*/
|
||||
private AuthenticatedBackupUser retrieveBackupUser(final byte[] backupId, final BackupTier backupTier) {
|
||||
private AuthenticatedBackupUser retrieveBackupUser(final byte[] backupId, final BackupLevel backupLevel) {
|
||||
final BackupsDb.AuthenticationData authData = backupsDb.retrieveAuthenticationData(backupId).join().get();
|
||||
return new AuthenticatedBackupUser(backupId, backupTier, authData.backupDir(), authData.mediaDir());
|
||||
return new AuthenticatedBackupUser(backupId, backupLevel, authData.backupDir(), authData.mediaDir());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.signal.libsignal.protocol.ecc.Curve;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupLevel;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticatedBackupUser;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamoDbExtension;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamoDbExtensionSchema;
|
||||
@@ -48,7 +49,7 @@ public class BackupsDbTest {
|
||||
|
||||
@Test
|
||||
public void trackMediaStats() {
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
// add at least one message backup so we can describe it
|
||||
backupsDb.addMessageBackup(backupUser).join();
|
||||
int total = 0;
|
||||
@@ -71,7 +72,7 @@ public class BackupsDbTest {
|
||||
@ValueSource(booleans = {false, true})
|
||||
public void setUsage(boolean mediaAlreadyExists) {
|
||||
testClock.pin(Instant.ofEpochSecond(5));
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupLevel.MEDIA);
|
||||
if (mediaAlreadyExists) {
|
||||
this.backupsDb.trackMedia(backupUser, 1, 10).join();
|
||||
}
|
||||
@@ -87,12 +88,12 @@ public class BackupsDbTest {
|
||||
final byte[] backupId = TestRandomUtil.nextBytes(16);
|
||||
// Refresh media/messages at t=0
|
||||
testClock.pin(Instant.ofEpochSecond(0L));
|
||||
backupsDb.setPublicKey(backupId, BackupTier.MEDIA, Curve.generateKeyPair().getPublicKey()).join();
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupTier.MEDIA)).join();
|
||||
backupsDb.setPublicKey(backupId, BackupLevel.MEDIA, Curve.generateKeyPair().getPublicKey()).join();
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupLevel.MEDIA)).join();
|
||||
|
||||
// refresh only messages at t=2
|
||||
testClock.pin(Instant.ofEpochSecond(2L));
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupTier.MESSAGES)).join();
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupLevel.MESSAGES)).join();
|
||||
|
||||
final Function<Instant, List<ExpiredBackup>> expiredBackups = purgeTime -> backupsDb
|
||||
.getExpiredBackups(1, Schedulers.immediate(), purgeTime)
|
||||
@@ -104,8 +105,8 @@ public class BackupsDbTest {
|
||||
.matches(eb -> eb.expirationType() == ExpiredBackup.ExpirationType.MEDIA);
|
||||
|
||||
// Expire the media
|
||||
backupsDb.startExpiration(expired.get(0)).join();
|
||||
backupsDb.finishExpiration(expired.get(0)).join();
|
||||
backupsDb.startExpiration(expired.getFirst()).join();
|
||||
backupsDb.finishExpiration(expired.getFirst()).join();
|
||||
|
||||
// should be nothing to expire at t=1
|
||||
assertThat(expiredBackups.apply(Instant.ofEpochSecond(1))).isEmpty();
|
||||
@@ -116,8 +117,8 @@ public class BackupsDbTest {
|
||||
.matches(eb -> eb.expirationType() == ExpiredBackup.ExpirationType.ALL);
|
||||
|
||||
// Expire the messages
|
||||
backupsDb.startExpiration(expired.get(0)).join();
|
||||
backupsDb.finishExpiration(expired.get(0)).join();
|
||||
backupsDb.startExpiration(expired.getFirst()).join();
|
||||
backupsDb.finishExpiration(expired.getFirst()).join();
|
||||
|
||||
// should be nothing to expire at t=3
|
||||
assertThat(expiredBackups.apply(Instant.ofEpochSecond(3))).isEmpty();
|
||||
@@ -129,13 +130,13 @@ public class BackupsDbTest {
|
||||
final byte[] backupId = TestRandomUtil.nextBytes(16);
|
||||
// Refresh media/messages at t=0
|
||||
testClock.pin(Instant.ofEpochSecond(0L));
|
||||
backupsDb.setPublicKey(backupId, BackupTier.MEDIA, Curve.generateKeyPair().getPublicKey()).join();
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupTier.MEDIA)).join();
|
||||
backupsDb.setPublicKey(backupId, BackupLevel.MEDIA, Curve.generateKeyPair().getPublicKey()).join();
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupLevel.MEDIA)).join();
|
||||
|
||||
if (expirationType == ExpiredBackup.ExpirationType.MEDIA) {
|
||||
// refresh only messages at t=2 so that we only expire media at t=1
|
||||
testClock.pin(Instant.ofEpochSecond(2L));
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupTier.MESSAGES)).join();
|
||||
this.backupsDb.ttlRefresh(backupUser(backupId, BackupLevel.MESSAGES)).join();
|
||||
}
|
||||
|
||||
final Function<Instant, Optional<ExpiredBackup>> expiredBackups = purgeTime -> {
|
||||
@@ -160,17 +161,17 @@ public class BackupsDbTest {
|
||||
if (expirationType == ExpiredBackup.ExpirationType.MEDIA) {
|
||||
// Media expiration should swap the media name and keep the backup name, marking the old media name for expiration
|
||||
assertThat(expired.prefixToDelete())
|
||||
.isEqualTo(originalBackupDir + "/" + originalMediaDir)
|
||||
.withFailMessage("Should expire media directory, expired %s", expired.prefixToDelete());
|
||||
assertThat(info.backupDir()).isEqualTo(originalBackupDir).withFailMessage("should keep backupDir");
|
||||
assertThat(info.mediaDir()).isNotEqualTo(originalMediaDir).withFailMessage("should change mediaDir");
|
||||
.withFailMessage("Should expire media directory, expired %s", expired.prefixToDelete())
|
||||
.isEqualTo(originalBackupDir + "/" + originalMediaDir);
|
||||
assertThat(info.backupDir()).withFailMessage("should keep backupDir").isEqualTo(originalBackupDir);
|
||||
assertThat(info.mediaDir()).withFailMessage("should change mediaDir").isNotEqualTo(originalMediaDir);
|
||||
} else {
|
||||
// Full expiration should swap the media name and the backup name, marking the old backup name for expiration
|
||||
assertThat(expired.prefixToDelete())
|
||||
.isEqualTo(originalBackupDir)
|
||||
.withFailMessage("Should expire whole backupDir, expired %s", expired.prefixToDelete());
|
||||
assertThat(info.backupDir()).isNotEqualTo(originalBackupDir).withFailMessage("should change backupDir");
|
||||
assertThat(info.mediaDir()).isNotEqualTo(originalMediaDir).withFailMessage("should change mediaDir");
|
||||
.withFailMessage("Should expire whole backupDir, expired %s", expired.prefixToDelete())
|
||||
.isEqualTo(originalBackupDir);
|
||||
assertThat(info.backupDir()).withFailMessage("should change backupDir").isNotEqualTo(originalBackupDir);
|
||||
assertThat(info.mediaDir()).withFailMessage("should change mediaDir").isNotEqualTo(originalMediaDir);
|
||||
}
|
||||
final String expiredPrefix = expired.prefixToDelete();
|
||||
|
||||
@@ -189,7 +190,7 @@ public class BackupsDbTest {
|
||||
// should be nothing to expire at t=1
|
||||
assertThat(opt).isEmpty();
|
||||
// The backup should still exist
|
||||
backupsDb.describeBackup(backupUser(backupId, BackupTier.MEDIA)).join();
|
||||
backupsDb.describeBackup(backupUser(backupId, BackupLevel.MEDIA)).join();
|
||||
} else {
|
||||
// Cleaned up the failed attempt, now should tell us to clean the whole backup
|
||||
assertThat(opt.get()).matches(eb -> eb.expirationType() == ExpiredBackup.ExpirationType.ALL,
|
||||
@@ -199,20 +200,14 @@ public class BackupsDbTest {
|
||||
|
||||
// The backup entry should be gone
|
||||
assertThat(CompletableFutureTestUtil.assertFailsWithCause(StatusRuntimeException.class,
|
||||
backupsDb.describeBackup(backupUser(backupId, BackupTier.MEDIA)))
|
||||
.getStatus().getCode())
|
||||
backupsDb.describeBackup(backupUser(backupId, BackupLevel.MEDIA)))
|
||||
.getStatus().getCode())
|
||||
.isEqualTo(Status.Code.NOT_FOUND);
|
||||
assertThat(expiredBackups.apply(Instant.ofEpochSecond(10))).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
private AuthenticatedBackupUser backupUser(final byte[] backupId, final BackupTier backupTier) {
|
||||
return new AuthenticatedBackupUser(backupId, backupTier, "myBackupDir", "myMediaDir");
|
||||
}
|
||||
|
||||
private AuthenticatedBackupUser backupUserFromDb(final byte[] backupId, final BackupTier backupTier) {
|
||||
final BackupsDb.AuthenticationData authenticationData = backupsDb.retrieveAuthenticationData(backupId).join().get();
|
||||
return new AuthenticatedBackupUser(backupId, backupTier,
|
||||
authenticationData.backupDir(), authenticationData.mediaDir());
|
||||
private AuthenticatedBackupUser backupUser(final byte[] backupId, final BackupLevel backupLevel) {
|
||||
return new AuthenticatedBackupUser(backupId, backupLevel, "myBackupDir", "myMediaDir");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,18 +51,18 @@ import org.whispersystems.textsecuregcm.util.TestRandomUtil;
|
||||
@ExtendWith(DropwizardExtensionsSupport.class)
|
||||
public class Cdn3RemoteStorageManagerTest {
|
||||
|
||||
private static byte[] HMAC_KEY = TestRandomUtil.nextBytes(32);
|
||||
private static byte[] AES_KEY = TestRandomUtil.nextBytes(32);
|
||||
private static byte[] IV = TestRandomUtil.nextBytes(16);
|
||||
private static final byte[] HMAC_KEY = TestRandomUtil.nextBytes(32);
|
||||
private static final byte[] AES_KEY = TestRandomUtil.nextBytes(32);
|
||||
private static final byte[] IV = TestRandomUtil.nextBytes(16);
|
||||
|
||||
@RegisterExtension
|
||||
private final WireMockExtension wireMock = WireMockExtension.newInstance()
|
||||
private static final WireMockExtension wireMock = WireMockExtension.newInstance()
|
||||
.options(wireMockConfig().dynamicPort())
|
||||
.build();
|
||||
|
||||
private static String SMALL_CDN2 = "a small object from cdn2";
|
||||
private static String SMALL_CDN3 = "a small object from cdn3";
|
||||
private static String LARGE = "a".repeat(1024 * 1024 * 5);
|
||||
private static final String SMALL_CDN2 = "a small object from cdn2";
|
||||
private static final String SMALL_CDN3 = "a small object from cdn3";
|
||||
private static final String LARGE = "a".repeat(1024 * 1024 * 5);
|
||||
|
||||
private RemoteStorageManager remoteStorageManager;
|
||||
|
||||
@@ -127,7 +127,7 @@ public class Cdn3RemoteStorageManagerTest {
|
||||
new BackupUploadDescriptor(3, "test", Collections.emptyMap(), wireMock.url("/cdn3/dest")))
|
||||
.toCompletableFuture().join();
|
||||
|
||||
final byte[] destBody = wireMock.findAll(postRequestedFor(urlEqualTo("/cdn3/dest"))).get(0).getBody();
|
||||
final byte[] destBody = wireMock.findAll(postRequestedFor(urlEqualTo("/cdn3/dest"))).getFirst().getBody();
|
||||
assertThat(new String(decrypt(destBody), StandardCharsets.UTF_8))
|
||||
.isEqualTo(expectedSource);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class Cdn3RemoteStorageManagerTest {
|
||||
new BackupUploadDescriptor(3, "test", Collections.emptyMap(), wireMock.url("/cdn3/dest")))
|
||||
.toCompletableFuture().join();
|
||||
|
||||
final byte[] destBody = wireMock.findAll(postRequestedFor(urlEqualTo("/cdn3/dest"))).get(0).getBody();
|
||||
final byte[] destBody = wireMock.findAll(postRequestedFor(urlEqualTo("/cdn3/dest"))).getFirst().getBody();
|
||||
assertThat(destBody.length)
|
||||
.isEqualTo(new BackupMediaEncrypter(params).outputSize(LARGE.length()))
|
||||
.isEqualTo(params.outputSize(LARGE.length()));
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.signal.libsignal.zkgroup.InvalidInputException;
|
||||
import org.signal.libsignal.zkgroup.ServerSecretParams;
|
||||
import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialPresentation;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupLevel;
|
||||
import org.signal.libsignal.zkgroup.receipts.ClientZkReceiptOperations;
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptCredential;
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialPresentation;
|
||||
@@ -65,7 +66,6 @@ import org.whispersystems.textsecuregcm.auth.AuthenticatedBackupUser;
|
||||
import org.whispersystems.textsecuregcm.backup.BackupAuthManager;
|
||||
import org.whispersystems.textsecuregcm.backup.BackupAuthTestUtil;
|
||||
import org.whispersystems.textsecuregcm.backup.BackupManager;
|
||||
import org.whispersystems.textsecuregcm.backup.BackupTier;
|
||||
import org.whispersystems.textsecuregcm.backup.InvalidLengthException;
|
||||
import org.whispersystems.textsecuregcm.backup.SourceObjectNotFoundException;
|
||||
import org.whispersystems.textsecuregcm.backup.BackupUploadDescriptor;
|
||||
@@ -133,7 +133,7 @@ public class ArchiveControllerTest {
|
||||
public void anonymousAuthOnly(final String method, final String path, final String body)
|
||||
throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
.target(path)
|
||||
.request()
|
||||
@@ -192,7 +192,7 @@ public class ArchiveControllerTest {
|
||||
when(backupManager.setPublicKey(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
final Response response = resources.getJerseyTest()
|
||||
.target("v1/archives/keys")
|
||||
.request()
|
||||
@@ -209,7 +209,7 @@ public class ArchiveControllerTest {
|
||||
when(backupManager.setPublicKey(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
final Response response = resources.getJerseyTest()
|
||||
.target("v1/archives/keys")
|
||||
.request()
|
||||
@@ -224,7 +224,7 @@ public class ArchiveControllerTest {
|
||||
when(backupManager.setPublicKey(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
final Response response = resources.getJerseyTest()
|
||||
.target("v1/archives/keys")
|
||||
.request()
|
||||
@@ -283,7 +283,7 @@ public class ArchiveControllerTest {
|
||||
final Instant start = Instant.now().truncatedTo(ChronoUnit.DAYS);
|
||||
final Instant end = start.plus(Duration.ofDays(1));
|
||||
final List<BackupAuthManager.Credential> expectedResponse = backupAuthTestUtil.getCredentials(
|
||||
BackupTier.MEDIA, backupAuthTestUtil.getRequest(backupKey, aci), start, end);
|
||||
BackupLevel.MEDIA, backupAuthTestUtil.getRequest(backupKey, aci), start, end);
|
||||
when(backupAuthManager.getBackupAuthCredentials(any(), eq(start), eq(end))).thenReturn(
|
||||
CompletableFuture.completedFuture(expectedResponse));
|
||||
final ArchiveController.BackupAuthCredentialsResponse creds = resources.getJerseyTest()
|
||||
@@ -293,10 +293,10 @@ public class ArchiveControllerTest {
|
||||
.request()
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.get(ArchiveController.BackupAuthCredentialsResponse.class);
|
||||
assertThat(creds.credentials().get(0).redemptionTime()).isEqualTo(start.getEpochSecond());
|
||||
assertThat(creds.credentials().getFirst().redemptionTime()).isEqualTo(start.getEpochSecond());
|
||||
}
|
||||
|
||||
enum BadCredentialsType {MISSING_START, MISSING_END, MISSING_BOTH}
|
||||
public enum BadCredentialsType {MISSING_START, MISSING_END, MISSING_BOTH}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource
|
||||
@@ -323,9 +323,9 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void getBackupInfo() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
when(backupManager.backupInfo(any())).thenReturn(CompletableFuture.completedFuture(new BackupManager.BackupInfo(
|
||||
1, "myBackupDir", "myMediaDir", "filename", Optional.empty())));
|
||||
final ArchiveController.BackupInfoResponse response = resources.getJerseyTest()
|
||||
@@ -343,9 +343,9 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void putMediaBatchSuccess() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
when(backupManager.canStoreMedia(any(), anyLong())).thenReturn(CompletableFuture.completedFuture(true));
|
||||
when(backupManager.copyToBackup(any(), anyInt(), any(), anyInt(), any(), any()))
|
||||
.thenAnswer(invocation -> {
|
||||
@@ -393,9 +393,9 @@ public class ArchiveControllerTest {
|
||||
public void putMediaBatchPartialFailure() throws VerificationFailedException {
|
||||
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
|
||||
final byte[][] mediaIds = IntStream.range(0, 3).mapToObj(i -> TestRandomUtil.nextBytes(15)).toArray(byte[][]::new);
|
||||
when(backupManager.canStoreMedia(any(), anyLong())).thenReturn(CompletableFuture.completedFuture(true));
|
||||
@@ -448,9 +448,9 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void putMediaBatchOutOfSpace() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
|
||||
when(backupManager.canStoreMedia(any(), eq(1L + 2L + 3L)))
|
||||
.thenReturn(CompletableFuture.completedFuture(false));
|
||||
@@ -478,9 +478,9 @@ public class ArchiveControllerTest {
|
||||
@CartesianTest.Values(booleans = {true, false}) final boolean cursorReturned)
|
||||
throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(
|
||||
BackupTier.MEDIA, backupKey, aci);
|
||||
BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
|
||||
final byte[] mediaId = TestRandomUtil.nextBytes(15);
|
||||
final Optional<String> expectedCursor = cursorProvided ? Optional.of("myCursor") : Optional.empty();
|
||||
@@ -505,17 +505,17 @@ public class ArchiveControllerTest {
|
||||
.get(ArchiveController.ListResponse.class);
|
||||
|
||||
assertThat(response.storedMediaObjects()).hasSize(1);
|
||||
assertThat(response.storedMediaObjects().get(0).objectLength()).isEqualTo(100);
|
||||
assertThat(response.storedMediaObjects().get(0).mediaId()).isEqualTo(mediaId);
|
||||
assertThat(response.storedMediaObjects().getFirst().objectLength()).isEqualTo(100);
|
||||
assertThat(response.storedMediaObjects().getFirst().mediaId()).isEqualTo(mediaId);
|
||||
assertThat(response.cursor()).isEqualTo(returnedCursor.orElse(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(BackupTier.MEDIA,
|
||||
final BackupAuthCredentialPresentation presentation = backupAuthTestUtil.getPresentation(BackupLevel.MEDIA,
|
||||
backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
|
||||
final ArchiveController.DeleteMedia deleteRequest = new ArchiveController.DeleteMedia(
|
||||
IntStream
|
||||
@@ -537,9 +537,9 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void mediaUploadForm() throws RateLimitExceededException, VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation =
|
||||
backupAuthTestUtil.getPresentation(BackupTier.MEDIA, backupKey, aci);
|
||||
backupAuthTestUtil.getPresentation(BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
when(backupManager.createTemporaryAttachmentUploadDescriptor(any()))
|
||||
.thenReturn(new BackupUploadDescriptor(3, "abc", Map.of("k", "v"), "example.org"));
|
||||
final ArchiveController.UploadDescriptorResponse desc = resources.getJerseyTest()
|
||||
@@ -568,9 +568,9 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void readAuth() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation =
|
||||
backupAuthTestUtil.getPresentation(BackupTier.MEDIA, backupKey, aci);
|
||||
backupAuthTestUtil.getPresentation(BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
when(backupManager.generateReadAuth(any(), eq(3))).thenReturn(Map.of("key", "value"));
|
||||
final ArchiveController.ReadAuthResponse response = resources.getJerseyTest()
|
||||
.target("v1/archives/auth/read")
|
||||
@@ -585,7 +585,7 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void readAuthInvalidParam() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation =
|
||||
backupAuthTestUtil.getPresentation(BackupTier.MEDIA, backupKey, aci);
|
||||
backupAuthTestUtil.getPresentation(BackupLevel.MEDIA, backupKey, aci);
|
||||
Response response = resources.getJerseyTest()
|
||||
.target("v1/archives/auth/read")
|
||||
.request()
|
||||
@@ -607,9 +607,9 @@ public class ArchiveControllerTest {
|
||||
@Test
|
||||
public void deleteEntireBackup() throws VerificationFailedException {
|
||||
final BackupAuthCredentialPresentation presentation =
|
||||
backupAuthTestUtil.getPresentation(BackupTier.MEDIA, backupKey, aci);
|
||||
backupAuthTestUtil.getPresentation(BackupLevel.MEDIA, backupKey, aci);
|
||||
when(backupManager.authenticateBackupUser(any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupTier.MEDIA)));
|
||||
.thenReturn(CompletableFuture.completedFuture(backupUser(presentation.getBackupId(), BackupLevel.MEDIA)));
|
||||
when(backupManager.deleteEntireBackup(any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
Response response = resources.getJerseyTest()
|
||||
.target("v1/archives/")
|
||||
@@ -620,7 +620,7 @@ public class ArchiveControllerTest {
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
}
|
||||
|
||||
private static AuthenticatedBackupUser backupUser(byte[] backupId, BackupTier backupTier) {
|
||||
return new AuthenticatedBackupUser(backupId, backupTier, "myBackupDir", "myMediaDir");
|
||||
private static AuthenticatedBackupUser backupUser(byte[] backupId, BackupLevel backupLevel) {
|
||||
return new AuthenticatedBackupUser(backupId, backupLevel, "myBackupDir", "myMediaDir");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user