404 instead of 400 on unknown source cdn
This commit is contained in:
parent
37b657cbbd
commit
de9eaa98db
|
@ -8,6 +8,7 @@ package org.whispersystems.textsecuregcm.backup;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
@ -248,12 +249,17 @@ public class BackupManager {
|
||||||
.asRuntimeException();
|
.asRuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final URI sourceUri;
|
||||||
|
try {
|
||||||
|
sourceUri = attachmentReadUri(sourceCdn, sourceKey);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return CompletableFuture.failedFuture(e);
|
||||||
|
}
|
||||||
|
|
||||||
final MessageBackupUploadDescriptor dst = cdn3BackupCredentialGenerator.generateUpload(
|
final MessageBackupUploadDescriptor dst = cdn3BackupCredentialGenerator.generateUpload(
|
||||||
cdnMediaPath(backupUser, destinationMediaId));
|
cdnMediaPath(backupUser, destinationMediaId));
|
||||||
|
|
||||||
final int destinationLength = encryptionParameters.outputSize(sourceLength);
|
final int destinationLength = encryptionParameters.outputSize(sourceLength);
|
||||||
|
|
||||||
final URI sourceUri = attachmentReadUri(sourceCdn, sourceKey);
|
|
||||||
return this.backupsDb
|
return this.backupsDb
|
||||||
// Write the ddb updates before actually updating backing storage
|
// Write the ddb updates before actually updating backing storage
|
||||||
.trackMedia(backupUser, 1, destinationLength)
|
.trackMedia(backupUser, 1, destinationLength)
|
||||||
|
@ -282,10 +288,10 @@ public class BackupManager {
|
||||||
* @param key the attachment key
|
* @param key the attachment key
|
||||||
* @return A {@link URI} where the attachment can be retrieved
|
* @return A {@link URI} where the attachment can be retrieved
|
||||||
*/
|
*/
|
||||||
private URI attachmentReadUri(final int cdn, final String key) {
|
private URI attachmentReadUri(final int cdn, final String key) throws IOException {
|
||||||
final String baseUri = attachmentCdnBaseUris.get(cdn);
|
final String baseUri = attachmentCdnBaseUris.get(cdn);
|
||||||
if (baseUri == null) {
|
if (baseUri == null) {
|
||||||
throw Status.INVALID_ARGUMENT.withDescription("Unknown cdn " + cdn).asRuntimeException();
|
throw new SourceObjectNotFoundException("Unknown attachment cdn " + cdn);
|
||||||
}
|
}
|
||||||
return URI.create("%s/%s".formatted(baseUri, key));
|
return URI.create("%s/%s".formatted(baseUri, key));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,10 @@ package org.whispersystems.textsecuregcm.backup;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class SourceObjectNotFoundException extends IOException {
|
public class SourceObjectNotFoundException extends IOException {
|
||||||
|
public SourceObjectNotFoundException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
public SourceObjectNotFoundException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
@ -308,6 +307,17 @@ public class BackupManagerTest {
|
||||||
assertThat(AttributeValues.getLong(backup, BackupsDb.ATTR_MEDIA_COUNT, -1L)).isEqualTo(0L);
|
assertThat(AttributeValues.getLong(backup, BackupsDb.ATTR_MEDIA_COUNT, -1L)).isEqualTo(0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unknownSourceCdn() {
|
||||||
|
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||||
|
CompletableFutureTestUtil.assertFailsWithCause(SourceObjectNotFoundException.class,
|
||||||
|
backupManager.copyToBackup(
|
||||||
|
backupUser,
|
||||||
|
0, "abc", 100,
|
||||||
|
mock(MediaEncryptionParameters.class),
|
||||||
|
"def".getBytes(StandardCharsets.UTF_8)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void quotaEnforcementNoRecalculation() {
|
public void quotaEnforcementNoRecalculation() {
|
||||||
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
final AuthenticatedBackupUser backupUser = backupUser(TestRandomUtil.nextBytes(16), BackupTier.MEDIA);
|
||||||
|
|
Loading…
Reference in New Issue