🎉 Init
This commit is contained in:
@@ -59,6 +59,31 @@ public class MultipartUploadTest
|
||||
assertEquals("hello world", new String(get.body(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initiateWithTaggingAppliesTagsToCompletedObject() throws Exception
|
||||
{
|
||||
createBucket();
|
||||
|
||||
HttpResponse<String> initiate = sendForString("POST", baseUri.resolve(BUCKET + "/" + KEY + "?uploads="),
|
||||
new byte[0], "text/plain", "x-amz-tagging", "job=nightly-backup&env=staging");
|
||||
assertEquals(200, initiate.statusCode());
|
||||
String uploadId = extract(initiate.body(), "UploadId");
|
||||
|
||||
String etag = uploadPart(uploadId, 1, "hello world");
|
||||
|
||||
String completeBody = "<CompleteMultipartUpload>"
|
||||
+ "<Part><PartNumber>1</PartNumber><ETag>\"" + etag + "\"</ETag></Part>"
|
||||
+ "</CompleteMultipartUpload>";
|
||||
HttpResponse<String> complete = sendForString("POST", baseUri.resolve(BUCKET + "/" + KEY + "?uploadId=" + uploadId),
|
||||
completeBody.getBytes(StandardCharsets.UTF_8), null);
|
||||
assertEquals(200, complete.statusCode());
|
||||
|
||||
HttpResponse<String> tagging = sendForString("GET", baseUri.resolve(BUCKET + "/" + KEY + "?tagging="), new byte[0], null);
|
||||
assertEquals(200, tagging.statusCode());
|
||||
assertTrue(tagging.body().contains("<Key>job</Key>\n <Value>nightly-backup</Value>"),
|
||||
"missing tag in tagging response: " + tagging.body());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abortDiscardsStagedParts() throws Exception
|
||||
{
|
||||
@@ -132,6 +157,20 @@ public class MultipartUploadTest
|
||||
return client.send(builder.build(), HttpResponse.BodyHandlers.ofString());
|
||||
}
|
||||
|
||||
private HttpResponse<String> sendForString(String method, URI uri, byte[] body, String contentType,
|
||||
String headerName, String headerValue) throws Exception
|
||||
{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
|
||||
.method(method, HttpRequest.BodyPublishers.ofByteArray(body))
|
||||
.header(headerName, headerValue);
|
||||
if (contentType != null)
|
||||
{
|
||||
builder.header("Content-Type", contentType);
|
||||
}
|
||||
SigV4TestSigner.sign(builder, method, uri, ACCESS_KEY, SECRET_KEY, body);
|
||||
return client.send(builder.build(), HttpResponse.BodyHandlers.ofString());
|
||||
}
|
||||
|
||||
private HttpResponse<byte[]> sendForBytes(String method, URI uri) throws Exception
|
||||
{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package dev.dinauer.r9t.core.object;
|
||||
|
||||
import dev.dinauer.r9t.core.auth.SigV4TestSigner;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
public class ObjectTaggingUploadTest
|
||||
{
|
||||
private static final String BUCKET = "tagging-upload-test-bucket";
|
||||
private static final String KEY = "tagging-upload-test.txt";
|
||||
private static final String ACCESS_KEY = "testkey";
|
||||
private static final String SECRET_KEY = "testsecret";
|
||||
|
||||
@TestHTTPResource
|
||||
URI baseUri;
|
||||
|
||||
private final HttpClient client = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
|
||||
|
||||
@Test
|
||||
public void uploadWithTagging() throws Exception
|
||||
{
|
||||
HttpResponse<Void> createBucket = send("PUT", baseUri.resolve(BUCKET), new byte[0], null, null);
|
||||
assertEquals(200, createBucket.statusCode());
|
||||
|
||||
byte[] content = "hello tagging test".getBytes(StandardCharsets.UTF_8);
|
||||
HttpResponse<Void> put = send("PUT", baseUri.resolve(BUCKET + "/" + KEY), content, "text/plain",
|
||||
"project=r9t&owner=andreas");
|
||||
assertEquals(200, put.statusCode());
|
||||
assertTrue(put.headers().firstValue("ETag").isPresent());
|
||||
|
||||
HttpResponse<byte[]> tagging = sendForBytes("GET", baseUri.resolve(BUCKET + "/" + KEY + "?tagging="));
|
||||
assertEquals(200, tagging.statusCode());
|
||||
String xml = new String(tagging.body(), StandardCharsets.UTF_8);
|
||||
assertTrue(xml.contains("<Key>project</Key>"));
|
||||
assertTrue(xml.contains("<Value>r9t</Value>"));
|
||||
assertTrue(xml.contains("<Key>owner</Key>"));
|
||||
assertTrue(xml.contains("<Value>andreas</Value>"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanup() throws Exception
|
||||
{
|
||||
send("DELETE", baseUri.resolve(BUCKET + "/" + KEY), new byte[0], null, null);
|
||||
send("DELETE", baseUri.resolve(BUCKET), new byte[0], null, null);
|
||||
}
|
||||
|
||||
private HttpResponse<Void> send(String method, URI uri, byte[] body, String contentType, String tagging) throws Exception
|
||||
{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
|
||||
.method(method, HttpRequest.BodyPublishers.ofByteArray(body));
|
||||
if (contentType != null)
|
||||
{
|
||||
builder.header("Content-Type", contentType);
|
||||
}
|
||||
if (tagging != null)
|
||||
{
|
||||
builder.header("x-amz-tagging", tagging);
|
||||
}
|
||||
SigV4TestSigner.sign(builder, method, uri, ACCESS_KEY, SECRET_KEY, body);
|
||||
return client.send(builder.build(), HttpResponse.BodyHandlers.discarding());
|
||||
}
|
||||
|
||||
private HttpResponse<byte[]> sendForBytes(String method, URI uri) throws Exception
|
||||
{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
|
||||
.method(method, HttpRequest.BodyPublishers.ofByteArray(new byte[0]));
|
||||
SigV4TestSigner.sign(builder, method, uri, ACCESS_KEY, SECRET_KEY, new byte[0]);
|
||||
return client.send(builder.build(), HttpResponse.BodyHandlers.ofByteArray());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
config_ordinal=1000
|
||||
|
||||
dev.dinauer.r9t.workdir=target/test-r9t
|
||||
dev.dinauer.r9t.credentials.access-key=testkey
|
||||
dev.dinauer.r9t.credentials.secret-key=testsecret
|
||||
|
||||
Reference in New Issue
Block a user