Convert attachment descriptors to records
This commit is contained in:
parent
1083d8bde0
commit
dd27e3b0c8
|
@ -7,87 +7,17 @@ package org.whispersystems.textsecuregcm.entities;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class AttachmentDescriptorV2 {
|
||||
public record AttachmentDescriptorV2(long attachmentId,
|
||||
String key,
|
||||
String credential,
|
||||
String acl,
|
||||
String algorithm,
|
||||
String date,
|
||||
String policy,
|
||||
String signature) {
|
||||
|
||||
@JsonProperty
|
||||
private String key;
|
||||
|
||||
@JsonProperty
|
||||
private String credential;
|
||||
|
||||
@JsonProperty
|
||||
private String acl;
|
||||
|
||||
@JsonProperty
|
||||
private String algorithm;
|
||||
|
||||
@JsonProperty
|
||||
private String date;
|
||||
|
||||
@JsonProperty
|
||||
private String policy;
|
||||
|
||||
@JsonProperty
|
||||
private String signature;
|
||||
|
||||
@JsonProperty
|
||||
private long attachmentId;
|
||||
|
||||
@JsonProperty
|
||||
private String attachmentIdString;
|
||||
|
||||
public AttachmentDescriptorV2() {}
|
||||
|
||||
public AttachmentDescriptorV2(long attachmentId,
|
||||
String key, String credential,
|
||||
String acl, String algorithm,
|
||||
String date, String policy,
|
||||
String signature)
|
||||
{
|
||||
this.attachmentId = attachmentId;
|
||||
this.attachmentIdString = String.valueOf(attachmentId);
|
||||
this.key = key;
|
||||
this.credential = credential;
|
||||
this.acl = acl;
|
||||
this.algorithm = algorithm;
|
||||
this.date = date;
|
||||
this.policy = policy;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getCredential() {
|
||||
return credential;
|
||||
}
|
||||
|
||||
public String getAcl() {
|
||||
return acl;
|
||||
}
|
||||
|
||||
public String getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public long getAttachmentId() {
|
||||
return attachmentId;
|
||||
}
|
||||
|
||||
public String getAttachmentIdString() {
|
||||
return attachmentIdString;
|
||||
public String attachmentIdString() {
|
||||
return String.valueOf(attachmentId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,47 +5,7 @@
|
|||
|
||||
package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AttachmentDescriptorV3 {
|
||||
|
||||
@JsonProperty
|
||||
private int cdn;
|
||||
|
||||
@JsonProperty
|
||||
private String key;
|
||||
|
||||
@JsonProperty
|
||||
private Map<String, String> headers;
|
||||
|
||||
@JsonProperty
|
||||
private String signedUploadLocation;
|
||||
|
||||
public AttachmentDescriptorV3() {
|
||||
}
|
||||
|
||||
public AttachmentDescriptorV3(int cdn, String key, Map<String, String> headers, String signedUploadLocation) {
|
||||
this.cdn = cdn;
|
||||
this.key = key;
|
||||
this.headers = headers;
|
||||
this.signedUploadLocation = signedUploadLocation;
|
||||
}
|
||||
|
||||
public int getCdn() {
|
||||
return cdn;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getSignedUploadLocation() {
|
||||
return signedUploadLocation;
|
||||
}
|
||||
public record AttachmentDescriptorV3(int cdn, String key, Map<String, String> headers, String signedUploadLocation) {
|
||||
}
|
||||
|
|
|
@ -95,15 +95,15 @@ class AttachmentControllerTest {
|
|||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.get(AttachmentDescriptorV3.class);
|
||||
|
||||
assertThat(descriptor.getKey()).isNotBlank();
|
||||
assertThat(descriptor.getCdn()).isEqualTo(2);
|
||||
assertThat(descriptor.getHeaders()).hasSize(3);
|
||||
assertThat(descriptor.getHeaders()).extractingByKey("host").isEqualTo("some-cdn.signal.org");
|
||||
assertThat(descriptor.getHeaders()).extractingByKey("x-goog-resumable").isEqualTo("start");
|
||||
assertThat(descriptor.getHeaders()).extractingByKey("x-goog-content-length-range").isEqualTo("1,1000");
|
||||
assertThat(descriptor.getSignedUploadLocation()).isNotEmpty();
|
||||
assertThat(descriptor.getSignedUploadLocation()).contains("X-Goog-Signature");
|
||||
assertThat(descriptor.getSignedUploadLocation()).is(new Condition<>(x -> {
|
||||
assertThat(descriptor.key()).isNotBlank();
|
||||
assertThat(descriptor.cdn()).isEqualTo(2);
|
||||
assertThat(descriptor.headers()).hasSize(3);
|
||||
assertThat(descriptor.headers()).extractingByKey("host").isEqualTo("some-cdn.signal.org");
|
||||
assertThat(descriptor.headers()).extractingByKey("x-goog-resumable").isEqualTo("start");
|
||||
assertThat(descriptor.headers()).extractingByKey("x-goog-content-length-range").isEqualTo("1,1000");
|
||||
assertThat(descriptor.signedUploadLocation()).isNotEmpty();
|
||||
assertThat(descriptor.signedUploadLocation()).contains("X-Goog-Signature");
|
||||
assertThat(descriptor.signedUploadLocation()).is(new Condition<>(x -> {
|
||||
try {
|
||||
new URL(x);
|
||||
} catch (MalformedURLException e) {
|
||||
|
@ -114,7 +114,7 @@ class AttachmentControllerTest {
|
|||
|
||||
final URL signedUploadLocation;
|
||||
try {
|
||||
signedUploadLocation = new URL(descriptor.getSignedUploadLocation());
|
||||
signedUploadLocation = new URL(descriptor.signedUploadLocation());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
@ -162,24 +162,24 @@ class AttachmentControllerTest {
|
|||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.get(AttachmentDescriptorV2.class);
|
||||
|
||||
assertThat(descriptor.getKey()).isEqualTo(descriptor.getAttachmentIdString());
|
||||
assertThat(descriptor.getAcl()).isEqualTo("private");
|
||||
assertThat(descriptor.getAlgorithm()).isEqualTo("AWS4-HMAC-SHA256");
|
||||
assertThat(descriptor.getAttachmentId()).isGreaterThan(0);
|
||||
assertThat(String.valueOf(descriptor.getAttachmentId())).isEqualTo(descriptor.getAttachmentIdString());
|
||||
assertThat(descriptor.key()).isEqualTo(descriptor.attachmentIdString());
|
||||
assertThat(descriptor.acl()).isEqualTo("private");
|
||||
assertThat(descriptor.algorithm()).isEqualTo("AWS4-HMAC-SHA256");
|
||||
assertThat(descriptor.attachmentId()).isGreaterThan(0);
|
||||
assertThat(String.valueOf(descriptor.attachmentId())).isEqualTo(descriptor.attachmentIdString());
|
||||
|
||||
String[] credentialParts = descriptor.getCredential().split("/");
|
||||
String[] credentialParts = descriptor.credential().split("/");
|
||||
|
||||
assertThat(credentialParts[0]).isEqualTo("accessKey");
|
||||
assertThat(credentialParts[2]).isEqualTo("us-east-1");
|
||||
assertThat(credentialParts[3]).isEqualTo("s3");
|
||||
assertThat(credentialParts[4]).isEqualTo("aws4_request");
|
||||
|
||||
assertThat(descriptor.getDate()).isNotBlank();
|
||||
assertThat(descriptor.getPolicy()).isNotBlank();
|
||||
assertThat(descriptor.getSignature()).isNotBlank();
|
||||
assertThat(descriptor.date()).isNotBlank();
|
||||
assertThat(descriptor.policy()).isNotBlank();
|
||||
assertThat(descriptor.signature()).isNotBlank();
|
||||
|
||||
assertThat(new String(Base64.getDecoder().decode(descriptor.getPolicy()))).contains("[\"content-length-range\", 1, 104857600]");
|
||||
assertThat(new String(Base64.getDecoder().decode(descriptor.policy()))).contains("[\"content-length-range\", 1, 104857600]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue