mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(s3): preserve archived null versions (#6104)
* fix(s3): preserve archived null versions * fix(s3): address null version archive review Preserve locked null versions under new versions and markers while checking protection before suspended cleanup. Avoid locking never-versioned body reads, reject reserved service keys, and recover original null bodies and metadata after failed publication. Remove obsolete marker bodies and retry reads that race marker creation. Refresh promoted null generations so archival and configuration rollback cannot hide a body replacement. * fix(s3): serialize null version metadata updates with promotion Hold the bucket monitor while resolving, validating and persisting retention, legal hold and ACL changes so promotion cannot discard an acknowledged update. Cover the race with a two-thread regression and preserve numbered-version references during demotion. * fix(analysis): protect null history after bucket configuration rollback Apply archived-null protection and cleanup in every non-enabled mutation path so restoring an unversioned bucket configuration cannot erase locks or leave stale history. Cover replacement, deletion and protected annotations in memory and disk modes. * fix(analysis): assert preservation immediately after each denied operation Check current and archived bytes before another request can repair corruption, use a distinct copy source, and compare replacement metadata with the listed null entry. * fix(analysis): compare listed null history with replacement metadata Assert the null listing identifies the latest replacement and its ETag so stale history cannot satisfy the count-only check. * fix(analysis): qualify missing null version documentation Describe keys that have no null version without excluding keys that gain one after versioning is suspended. * fix(s3): retain archived null history until replacement publication succeeds Keep the archived body, metadata and annotations when a non-enabled replacement metadata write throws, including after configuration rollback. Clean history after successful publication under the bucket monitor and cover failures before and after publication in memory and disk modes. * fix(s3): restore the current pointer after archived null publication failures Recover the prior current body and metadata when a non-enabled PUT with archived null history fails publication. Handle numbered versions, promoted null versions and markers with a fresh read generation, and keep archive annotations publicly associated with their original version. All 199 focused tests pass. * test(s3): prove reads retry across failed publication recovery Observe replacement bytes during a publication fault and require latest and explicit-null reads to retry against the restored promoted null version. Both new cases and all 27 archive/read tests pass. * docs(s3): use repository punctuation style Replace existing em dash punctuation in the touched S3 service documentation as required by the repository documentation rules. * fix(analysis): assert canonical cleanup when failed publication restores a marker Check memory payloads and the disk canonical path before retrying, so the marker-before-publication cells detect orphaned replacement bodies as well as metadata restoration. All 27 archive/read cases pass.
This commit is contained in:
12 files changed
+1885
-235
No files matched your search
+15
-17
@@ -93,11 +93,9 @@ specific object version through the four `?annotation` operations. Notes on the
|
||||
A request that names `versionId=null`, the id ListObjectVersions reports for an object written
|
||||
while versioning was off or suspended, acts on that null version only: GetObject, HeadObject,
|
||||
GetObjectAttributes, the object ACL, tagging, retention, legal hold, annotations and a copy source.
|
||||
A key whose current version was written with versioning on has no null version, so such a request
|
||||
answers as for any missing version: `404 NoSuchVersion`, or `404 NoSuchKey` for the annotation
|
||||
operations. S3 keeps a null version that a later
|
||||
versioned write replaces as a noncurrent version; Floci does not keep it, so after such a write the
|
||||
key has no null version.
|
||||
A key with no null version answers as for any missing version: `404 NoSuchVersion`, or `404 NoSuchKey` for the annotation operations. If
|
||||
the key already has a null version, a later versioned write or delete marker keeps it as a
|
||||
noncurrent version. Deleting newer versions can make that null version current again.
|
||||
|
||||
## Lifecycle Expiration
|
||||
|
||||
@@ -189,14 +187,14 @@ Floci chooses the execution engine automatically based on the input format and w
|
||||
|
||||
| Condition | Engine | Notes |
|
||||
|---|---|---|
|
||||
| Input is Parquet | floci-duck (required) | DuckDB's `read_parquet` — sidecar must be available |
|
||||
| Input is Parquet | floci-duck (required) | DuckDB's `read_parquet`: sidecar must be available |
|
||||
| Input is CSV with `FileHeaderInfo=USE` and floci-duck is running | floci-duck | Full DuckDB SQL: all operators, LIKE, BETWEEN, IN, IS NULL, AND/OR/NOT |
|
||||
| Input is JSON and floci-duck is running | floci-duck | `read_json_auto` — supports JSON Lines and JSON arrays |
|
||||
| Input is JSON and floci-duck is running | floci-duck | `read_json_auto`: supports JSON Lines and JSON arrays |
|
||||
| Input is CSV with `FileHeaderInfo=NONE` or `IGNORE`, or floci-duck is not running | Java evaluator | Supports SELECT *, column projection, simple WHERE with =, !=, <, >, <=, >=, LIKE, BETWEEN, IN, IS NULL, AND/OR/NOT, LIMIT |
|
||||
|
||||
The floci-duck sidecar starts lazily on the **first Athena query**. Until then, `isAvailable()` returns false and S3 Select falls back to the Java evaluator for CSV and JSON. Once the sidecar is running, subsequent S3 Select calls route through DuckDB automatically.
|
||||
|
||||
If floci-duck is not running and the object is Parquet, S3 Select returns an error — Parquet decoding requires DuckDB.
|
||||
If floci-duck is not running and the object is Parquet, S3 Select returns an error: Parquet decoding requires DuckDB.
|
||||
|
||||
The Java evaluator reads the object a record at a time and writes the result in `Records` events as
|
||||
it goes, stopping once a `LIMIT` is reached, so neither the object nor the result is held in memory.
|
||||
@@ -233,9 +231,9 @@ S3 Select supports cross-format output: a CSV object can produce JSON output and
|
||||
|
||||
| Input | Output | Format |
|
||||
|---|---|---|
|
||||
| CSV | CSV | Default — comma-separated values |
|
||||
| CSV | CSV | Default: comma-separated values |
|
||||
| CSV | JSON | One JSON object per row: `{"col1":"val1","col2":"val2"}` |
|
||||
| JSON | JSON | Default — one JSON object per line |
|
||||
| JSON | JSON | Default: one JSON object per line |
|
||||
| JSON | CSV | Comma-separated values, values quoted when they contain commas or newlines |
|
||||
|
||||
### Example
|
||||
@@ -320,7 +318,7 @@ the original caller, and `DeleteBucket` remains scoped to that caller's account.
|
||||
By default S3 buckets are isolated per account (see [Multi-Account Isolation](../configuration/multi-account.md)),
|
||||
so two accounts can each hold a bucket with the same name. Set
|
||||
`FLOCI_SERVICES_S3_GLOBAL_BUCKET_NAMESPACE=true` to make bucket and object resolution span every
|
||||
account's partition — a bucket created in one account then resolves cross-account, matching real S3
|
||||
account's partition: a bucket created in one account then resolves cross-account, matching real S3
|
||||
where bucket names are globally unique. Enable this when a workload (for example an LZA log-archive or
|
||||
CDK asset bucket) is created in one account and read from another.
|
||||
|
||||
@@ -335,7 +333,7 @@ Floci-managed staging buckets for Lambda packages, Spectrum, Firehose conversion
|
||||
account scoped even when the global namespace is enabled. Their existing names and object paths are
|
||||
preserved; the internal creation path does not change public `CreateBucket` collision handling.
|
||||
|
||||
**Why the flag exists, and what it trades away.** Floci partitions every resource by the caller's account, which is the right model for services whose names are account-scoped in AWS. S3 bucket names are not: they are unique across all accounts, a bucket lives in exactly one owning account, and whether another account may touch it is decided by policy rather than by the name being unreachable. A hard per-account partition therefore lets two accounts hold different buckets under one name — a state AWS cannot reach — and makes a legitimate cross-account call fail with `NoSuchBucket` instead of being authorized or denied on its merits. With the flag on, a caller that names another account's bucket resolves it and only IAM and bucket-policy evaluation stand between the caller and the object: AWS-faithful, but stricter than the implicit isolation Floci gives you elsewhere — **provided both `FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED` (identity-policy checks, applied before the request reaches S3) and `FLOCI_SERVICES_S3_ENFORCE_AUTH` (the S3-specific flag that gates bucket-policy evaluation itself, in `S3Service.authorizeS3Read`/`authorizeS3Write`) are also `true`**. Both default to `false`, and bucket-policy evaluation in particular is a no-op while `FLOCI_SERVICES_S3_ENFORCE_AUTH` is off — regardless of the IAM flag — so in the default configuration enabling the global namespace does not trade per-account isolation for a policy-gated boundary — it removes the only isolation Floci gives S3 for that bucket and replaces it with nothing. Mutations are written back to the bucket's owning account rather than forked into the caller's, and `ListBuckets` stays caller-scoped while `ListObjects` and `ListObjectsV2` list the named bucket's owner-scoped objects, so the flag never reassigns ownership or leaks a bucket inventory. It is off by default — turn it on when emulating a multi-account estate whose real behaviour depends on the global namespace, and leave it off when the per-account partition is the isolation you are relying on. Account-scoped S3 state, notably the account-level Block Public Access configuration, is never widened by this flag. Note also that retrofitting a global namespace onto state that was previously partitioned per account means that if two accounts already hold a bucket under the same name — a state real AWS can't reach, but Floci's prior per-account isolation could — resolution picks whichever account's copy the backend happens to iterate to first; this is unlikely to be reachable on a fresh LZA-driven account structure, but is worth knowing if you enable the flag on an estate with pre-existing same-name buckets.
|
||||
**Why the flag exists, and what it trades away.** Floci partitions every resource by the caller's account, which is the right model for services whose names are account-scoped in AWS. S3 bucket names are not: they are unique across all accounts, a bucket lives in exactly one owning account, and whether another account may touch it is decided by policy rather than by the name being unreachable. A hard per-account partition therefore lets two accounts hold different buckets under one name (a state AWS cannot reach), and makes a legitimate cross-account call fail with `NoSuchBucket` instead of being authorized or denied on its merits. With the flag on, a caller that names another account's bucket resolves it and only IAM and bucket-policy evaluation stand between the caller and the object: AWS-faithful, but stricter than the implicit isolation Floci gives you elsewhere, **provided both `FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED` (identity-policy checks, applied before the request reaches S3) and `FLOCI_SERVICES_S3_ENFORCE_AUTH` (the S3-specific flag that gates bucket-policy evaluation itself, in `S3Service.authorizeS3Read`/`authorizeS3Write`) are also `true`**. Both default to `false`, and bucket-policy evaluation in particular is a no-op while `FLOCI_SERVICES_S3_ENFORCE_AUTH` is off, regardless of the IAM flag, so in the default configuration enabling the global namespace does not trade per-account isolation for a policy-gated boundary, it removes the only isolation Floci gives S3 for that bucket and replaces it with nothing. Mutations are written back to the bucket's owning account rather than forked into the caller's, and `ListBuckets` stays caller-scoped while `ListObjects` and `ListObjectsV2` list the named bucket's owner-scoped objects, so the flag never reassigns ownership or leaks a bucket inventory. It is off by default, turn it on when emulating a multi-account estate whose real behaviour depends on the global namespace, and leave it off when the per-account partition is the isolation you are relying on. Account-scoped S3 state, notably the account-level Block Public Access configuration, is never widened by this flag. Note also that retrofitting a global namespace onto state that was previously partitioned per account means that if two accounts already hold a bucket under the same name (a state real AWS can't reach, but Floci's prior per-account isolation could), resolution picks whichever account's copy the backend happens to iterate to first; this is unlikely to be reachable on a fresh LZA-driven account structure, but is worth knowing if you enable the flag on an estate with pre-existing same-name buckets.
|
||||
|
||||
## Signature Verification
|
||||
|
||||
@@ -471,7 +469,7 @@ A single public statement makes the whole policy public. As on AWS, `RestrictPub
|
||||
|
||||
### Account-level operations
|
||||
|
||||
The s3control `PutPublicAccessBlock`, `GetPublicAccessBlock` and `DeletePublicAccessBlock` operations are keyed by the `x-amz-account-id` header, stored per account, and persisted like the rest of S3's state so a restart does not silently drop the control. As in AWS, the header must name the caller's own account; a mismatch returns `AccessDenied` (403). Floci keeps one deliberate exception: the configured default (management) account may act on any account, because Floci's launched Lambdas run on placeholder credentials that resolve to the management account instead of assuming a role in the target account — which is how LZA's `Custom::PutPublicAccessBlock` resource reaches this API.
|
||||
The s3control `PutPublicAccessBlock`, `GetPublicAccessBlock` and `DeletePublicAccessBlock` operations are keyed by the `x-amz-account-id` header, stored per account, and persisted like the rest of S3's state so a restart does not silently drop the control. As in AWS, the header must name the caller's own account; a mismatch returns `AccessDenied` (403). Floci keeps one deliberate exception: the configured default (management) account may act on any account, because Floci's launched Lambdas run on placeholder credentials that resolve to the management account instead of assuming a role in the target account, which is how LZA's `Custom::PutPublicAccessBlock` resource reaches this API.
|
||||
|
||||
## Not Implemented
|
||||
|
||||
@@ -630,7 +628,7 @@ Virtual-hosted style puts the bucket name in the hostname:
|
||||
http://my-bucket.s3.localhost.floci.io:4566/my-key
|
||||
```
|
||||
|
||||
Floci supports this natively — no `forcePathStyle` needed. The following wildcard DNS domains resolve to `127.0.0.1` via public DNS, so virtual-hosted requests reach Floci on the host machine automatically:
|
||||
Floci supports this natively, no `forcePathStyle` needed. The following wildcard DNS domains resolve to `127.0.0.1` via public DNS, so virtual-hosted requests reach Floci on the host machine automatically:
|
||||
|
||||
| Domain pattern | Resolves to |
|
||||
|---|---|
|
||||
@@ -639,7 +637,7 @@ Floci supports this natively — no `forcePathStyle` needed. The following wildc
|
||||
| `*.localhost.localstack.cloud` | `127.0.0.1` |
|
||||
| `*.s3.localhost.localstack.cloud` | `127.0.0.1` |
|
||||
|
||||
Plain `http://localhost:4566` also works without `forcePathStyle` — the SDK sends `Host: my-bucket.localhost:4566` and Floci's filter extracts the bucket name from that header.
|
||||
Plain `http://localhost:4566` also works without `forcePathStyle`, the SDK sends `Host: my-bucket.localhost:4566` and Floci's filter extracts the bucket name from that header.
|
||||
|
||||
Configure the SDK endpoint to one of the base domains (no `forcePathStyle`):
|
||||
|
||||
@@ -660,7 +658,7 @@ Configure the SDK endpoint to one of the base domains (no `forcePathStyle`):
|
||||
```javascript
|
||||
const s3 = new S3Client({
|
||||
endpoint: "http://s3.localhost.floci.io:4566",
|
||||
// no forcePathStyle — SDK uses virtual-hosted style by default
|
||||
// no forcePathStyle, SDK uses virtual-hosted style by default
|
||||
});
|
||||
// SDK sends requests to: my-bucket.s3.localhost.floci.io:4566
|
||||
```
|
||||
@@ -674,7 +672,7 @@ Configure the SDK endpoint to one of the base domains (no `forcePathStyle`):
|
||||
|
||||
#### Virtual-Hosted Style Inside Docker
|
||||
|
||||
Inside Docker containers, `127.0.0.1` resolves to the container itself — not Floci. Floci's **embedded DNS server** handles this automatically: it resolves `*.localhost.floci.io`, `*.s3.localhost.floci.io`, `*.localhost.localstack.cloud`, and `*.s3.localhost.localstack.cloud` to Floci's container IP on the Docker network.
|
||||
Inside Docker containers, `127.0.0.1` resolves to the container itself, not Floci. Floci's **embedded DNS server** handles this automatically: it resolves `*.localhost.floci.io`, `*.s3.localhost.floci.io`, `*.localhost.localstack.cloud`, and `*.s3.localhost.localstack.cloud` to Floci's container IP on the Docker network.
|
||||
|
||||
To use virtual-hosted style from a test container, point its DNS at Floci and set the endpoint to Floci's service hostname:
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -54,8 +54,8 @@ public class S3Object {
|
||||
private String dataGeneration;
|
||||
|
||||
// Internal-only s3.object.sequencer of the write that stored this instance, assigned under the
|
||||
// bucket lock so concurrent writes to one key get values in the order they were stored.
|
||||
@JsonIgnore
|
||||
// bucket lock so concurrent writes to one key get values in the order they were stored. Unlike
|
||||
// dataGeneration, this is persisted because version promotion needs the order after restart.
|
||||
private String eventSequencer;
|
||||
|
||||
public S3Object() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
|
||||
@@ -126,6 +127,24 @@ class S3LifecycleServiceTest {
|
||||
assertThat(versionIds("a.txt"), contains(v3.getVersionId(), v2.getVersionId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noncurrentExpirationDeletesAnArchivedNullVersionWithoutChangingTheCurrentVersion() {
|
||||
put("a.txt");
|
||||
s3Service.putBucketVersioning(BUCKET, "Enabled");
|
||||
S3Object current = put("a.txt");
|
||||
lifecycle(rule("Enabled", "<Filter></Filter>",
|
||||
"<NoncurrentVersionExpiration><NoncurrentDays>1</NoncurrentDays>"
|
||||
+ "</NoncurrentVersionExpiration>"));
|
||||
|
||||
s3Service.applyLifecycleExpiration(Instant.now().plus(Duration.ofDays(3)));
|
||||
|
||||
assertThat(versionIds("a.txt"), contains(current.getVersionId()));
|
||||
assertEquals("data", new String(s3Service.getObject(BUCKET, "a.txt").getData(), StandardCharsets.UTF_8));
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> s3Service.getObject(BUCKET, "a.txt", "null"));
|
||||
assertEquals("NoSuchVersion", missing.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNoncurrentVersionUnderALegalHoldIsKept() {
|
||||
s3Service.putBucketVersioning(BUCKET, "Enabled");
|
||||
|
||||
@@ -3,20 +3,25 @@ package io.github.hectorvent.floci.services.s3;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.s3.model.CopyObjectOptions;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* A request naming {@code versionId=null} in disk-storage mode, where the null version's bytes are
|
||||
@@ -44,6 +49,9 @@ class S3NullVersionDiskTest {
|
||||
try (S3Service.ObjectRead read = s3Service.openObject("bucket", "old.txt", "null")) {
|
||||
assertArrayEquals(bytes("null version"), read.body().readAllBytes());
|
||||
}
|
||||
try (InputStream stream = s3Service.openObjectStream("bucket", "old.txt", "null")) {
|
||||
assertArrayEquals(bytes("null version"), stream.readAllBytes());
|
||||
}
|
||||
|
||||
s3Service.copyObject("bucket", "old.txt", "bucket", "copy.txt", "null", new CopyObjectOptions());
|
||||
|
||||
@@ -61,6 +69,86 @@ class S3NullVersionDiskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anArchivedNullVersionUsesTheVersionedFileAndCanBePromoted() throws IOException {
|
||||
String currentVersionId = s3Service.putObject(
|
||||
"bucket", "old.txt", bytes("versioned replacement"), "text/plain", Map.of()).getVersionId();
|
||||
Path archived = tempDir.resolve("s3").resolve(".accounts").resolve("000000000000")
|
||||
.resolve(".versions").resolve("bucket").resolve("old.txt").resolve("null.s3data");
|
||||
|
||||
assertTrue(Files.exists(archived));
|
||||
assertArrayEquals(bytes("null version"), Files.readAllBytes(archived));
|
||||
try (S3Service.ObjectRead read = s3Service.openObject("bucket", "old.txt", "null")) {
|
||||
assertArrayEquals(bytes("null version"), read.body().readAllBytes());
|
||||
}
|
||||
s3Service.copyObject("bucket", "old.txt", "bucket", "archived-copy.txt", "null",
|
||||
new CopyObjectOptions());
|
||||
assertArrayEquals(bytes("null version"), s3Service.getObject("bucket", "archived-copy.txt").getData());
|
||||
|
||||
s3Service.deleteObject("bucket", "old.txt", currentVersionId);
|
||||
|
||||
assertArrayEquals(bytes("null version"), s3Service.getObject("bucket", "old.txt").getData());
|
||||
assertEquals(1, s3Service.listObjectVersions("bucket", "old.txt", 1000, null).versions().size());
|
||||
s3Service.deleteObject("bucket", "old.txt", "null");
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> s3Service.getObject("bucket", "old.txt"));
|
||||
assertEquals("NoSuchKey", missing.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivedNullReadsRetryWhenASuspendedPutReplacesTheHistoryFile() throws IOException {
|
||||
ArchivedNullReplacementStore objectStore = new ArchivedNullReplacementStore();
|
||||
S3Service service = new S3Service(
|
||||
new InMemoryStorage<>(), objectStore, tempDir.resolve("racing-s3"), false);
|
||||
service.createBucket("racing-bucket", "us-east-1");
|
||||
List<String> keys = List.of("get.txt", "stream.txt", "copy.txt");
|
||||
for (String key : keys) {
|
||||
service.putObject("racing-bucket", key, bytes("original"), "text/plain", Map.of());
|
||||
}
|
||||
service.putBucketVersioning("racing-bucket", "Enabled");
|
||||
for (String key : keys) {
|
||||
service.putObject("racing-bucket", key, bytes("numbered"), "text/plain", Map.of());
|
||||
}
|
||||
service.putBucketVersioning("racing-bucket", "Suspended");
|
||||
|
||||
objectStore.arm(service, "get.txt");
|
||||
assertArrayEquals(bytes("replacement"),
|
||||
service.getObject("racing-bucket", "get.txt", "null").getData());
|
||||
|
||||
objectStore.arm(service, "stream.txt");
|
||||
try (S3Service.ObjectRead read = service.openObject("racing-bucket", "stream.txt", "null")) {
|
||||
assertArrayEquals(bytes("replacement"), read.body().readAllBytes());
|
||||
}
|
||||
|
||||
objectStore.arm(service, "copy.txt");
|
||||
service.copyObject("racing-bucket", "copy.txt", "racing-bucket", "copied.txt", "null",
|
||||
new CopyObjectOptions());
|
||||
assertArrayEquals(bytes("replacement"), service.getObject("racing-bucket", "copied.txt").getData());
|
||||
}
|
||||
|
||||
private static final class ArchivedNullReplacementStore extends InMemoryStorage<String, S3Object> {
|
||||
private S3Service service;
|
||||
private String armedKey;
|
||||
|
||||
private void arm(S3Service service, String key) {
|
||||
this.service = service;
|
||||
armedKey = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
Optional<S3Object> result = super.get(key);
|
||||
String target = "racing-bucket/\0null-version/" + armedKey;
|
||||
if (armedKey != null && target.equals(key)) {
|
||||
String replacing = armedKey;
|
||||
armedKey = null;
|
||||
service.putObject("racing-bucket", replacing,
|
||||
bytes("replacement"), "text/plain", Map.of());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] bytes(String text) {
|
||||
return text.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.s3.model.Bucket;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class S3NullVersionLockPromotionTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"legal-hold", "retention", "acl"})
|
||||
void promotionCannotDropAnAcknowledgedMetadataUpdate(String operation) throws Exception {
|
||||
InMemoryStorage<String, Bucket> buckets = new InMemoryStorage<>();
|
||||
PromotionStore objects = new PromotionStore();
|
||||
S3Service service = new S3Service(buckets, objects, tempDir, true);
|
||||
service.createBucket("bucket", "us-east-1");
|
||||
service.putBucketOwnershipControls("bucket",
|
||||
"<OwnershipControls><Rule><ObjectOwnership>BucketOwnerPreferred</ObjectOwnership></Rule></OwnershipControls>");
|
||||
service.putObject("bucket", "key", "original".getBytes(StandardCharsets.UTF_8), "text/plain", Map.of());
|
||||
service.setBucketObjectLockEnabled("bucket");
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
String numbered = service.putObject("bucket", "key", "numbered".getBytes(StandardCharsets.UTF_8),
|
||||
"text/plain", Map.of()).getVersionId();
|
||||
objects.arm(buckets.get("bucket").orElseThrow(), () -> service.deleteObject("bucket", "key", numbered));
|
||||
|
||||
switch (operation) {
|
||||
case "legal-hold" -> service.putObjectLegalHold("bucket", "key", "null", "ON");
|
||||
case "retention" -> service.putObjectRetention("bucket", "key", "null", "COMPLIANCE",
|
||||
Instant.now().plusSeconds(3600), false);
|
||||
case "acl" -> service.putObjectAcl("bucket", "key", "null", "", "public-read",
|
||||
null, null, null, null, null);
|
||||
default -> throw new IllegalArgumentException(operation);
|
||||
}
|
||||
objects.promotion.get(5, TimeUnit.SECONDS);
|
||||
|
||||
assertNull(service.getObject("bucket", "key").getVersionId());
|
||||
if ("acl".equals(operation)) {
|
||||
assertTrue(service.getObjectAcl("bucket", "key", "null").contains("AllUsers"));
|
||||
} else {
|
||||
if ("legal-hold".equals(operation)) {
|
||||
assertEquals("ON", service.getObjectLegalHold("bucket", "key", "null").getLegalHoldStatus());
|
||||
} else {
|
||||
assertEquals("COMPLIANCE", service.getObjectRetention("bucket", "key", "null").getObjectLockMode());
|
||||
}
|
||||
assertEquals("AccessDenied", assertThrows(AwsException.class,
|
||||
() -> service.deleteObject("bucket", "key", "null", true)).getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PromotionStore extends InMemoryStorage<String, S3Object> {
|
||||
private Bucket bucket;
|
||||
private Runnable promote;
|
||||
private FutureTask<Void> promotion;
|
||||
|
||||
private void arm(Bucket bucket, Runnable promote) {
|
||||
this.bucket = bucket;
|
||||
this.promote = promote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
Optional<S3Object> object = super.get(key);
|
||||
if (promote != null && "bucket/\0null-version/key".equals(key)) {
|
||||
Runnable action = promote;
|
||||
promote = null;
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
promotion = new FutureTask<>(() -> {
|
||||
started.countDown();
|
||||
action.run();
|
||||
return null;
|
||||
});
|
||||
Thread.ofPlatform().start(promotion);
|
||||
try {
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS));
|
||||
if (!Thread.holdsLock(bucket)) {
|
||||
// Expose a stale target if resolution is outside the monitor. With the
|
||||
// monitor held, promotion follows the acknowledged metadata update.
|
||||
promotion.get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException(e);
|
||||
} catch (ExecutionException | TimeoutException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,559 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.s3.model.Bucket;
|
||||
import io.github.hectorvent.floci.services.s3.model.CopyObjectOptions;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class S3NullVersionReviewTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void rollbackThenPutListsTheReplacementNull(boolean memory) {
|
||||
S3Service service = rolledBackService(memory);
|
||||
S3Object replacement = service.putObject("bucket", "key", bytes("replacement"), "text/plain", Map.of());
|
||||
assertArrayEquals(bytes("replacement"), service.getObject("bucket", "key", "null").getData());
|
||||
List<S3Object> versions = service.listObjectVersions("bucket", "key", 100, null).versions();
|
||||
assertEquals(1, versions.size());
|
||||
assertEquals(replacement.getETag(), versions.getFirst().getETag(),
|
||||
"listing must describe the retrievable null version");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void rollbackThenDeleteDoesNotResurrectNull(boolean memory) {
|
||||
S3Service service = rolledBackService(memory);
|
||||
service.deleteObject("bucket", "key");
|
||||
assertAll(
|
||||
() -> assertTrue(service.listObjectVersions("bucket", "key", 100, null).versions().isEmpty(),
|
||||
"plain DELETE must remove the only null version"),
|
||||
() -> assertFalse(service.objectExists("bucket", "key")),
|
||||
() -> assertEquals("NoSuchVersion", assertThrows(AwsException.class,
|
||||
() -> service.getObject("bucket", "key", "null")).getErrorCode()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void rollbackCannotEraseAnnotationsOfLockedArchivedNull(boolean memory) {
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), new InMemoryStorage<>(), tempDir, memory);
|
||||
service.createBucket("bucket", "us-east-1");
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
service.putObjectAnnotation("bucket", "key", "note", null, bytes("annotation"), null, null);
|
||||
service.setBucketObjectLockEnabled("bucket");
|
||||
service.putObjectLegalHold("bucket", "key", "null", "ON");
|
||||
String configuration = service.snapshotBucketConfiguration("bucket");
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of());
|
||||
service.restoreBucketConfiguration("bucket", configuration);
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals("AccessDenied", assertThrows(AwsException.class,
|
||||
() -> service.putObject("bucket", "key", bytes("replacement"), "text/plain", Map.of())).getErrorCode()),
|
||||
() -> assertEquals("AccessDenied", assertThrows(AwsException.class,
|
||||
() -> service.deleteObject("bucket", "key")).getErrorCode()),
|
||||
() -> assertArrayEquals(bytes("annotation"), service.readObjectAnnotationPayload(
|
||||
service.getObjectAnnotation("bucket", "key", "note", "null"))),
|
||||
() -> assertArrayEquals(bytes("numbered"), service.getObject("bucket", "key").getData()));
|
||||
}
|
||||
|
||||
private S3Service rolledBackService(boolean memory) {
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), new InMemoryStorage<>(), tempDir, memory);
|
||||
service.createBucket("bucket", "us-east-1");
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
String configuration = service.snapshotBucketConfiguration("bucket");
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
String version = service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of()).getVersionId();
|
||||
service.deleteObject("bucket", "key", version);
|
||||
service.restoreBucketConfiguration("bucket", configuration);
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void neverVersionedBodyReadsDoNotHoldTheBucketMonitor(boolean explicitNull) throws Exception {
|
||||
InMemoryStorage<String, Bucket> buckets = new InMemoryStorage<>();
|
||||
S3Service service = new S3Service(buckets, new InMemoryStorage<>(), tempDir, true);
|
||||
service.createBucket("bucket", "us-east-1");
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
Bucket bucket = buckets.get("bucket").orElseThrow();
|
||||
AtomicInteger reads = new AtomicInteger();
|
||||
|
||||
readSnapshot(service, explicitNull, ignored -> {
|
||||
assertFalse(Thread.holdsLock(bucket), "body reads must allow independent writes in never-versioned buckets");
|
||||
reads.incrementAndGet();
|
||||
return "body";
|
||||
});
|
||||
|
||||
assertEquals(1, reads.get());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void aReadSpanningFirstEnableAndRollbackRetriesThePromotedNull(boolean explicitNull) throws Exception {
|
||||
S3Service service = service(true, new InMemoryStorage<>());
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
String snapshot = service.snapshotBucketConfiguration("bucket");
|
||||
AtomicInteger reads = new AtomicInteger();
|
||||
|
||||
Object result = readSnapshot(service, explicitNull, ignored -> {
|
||||
if (reads.getAndIncrement() == 0) {
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
String version = service.putObject("bucket", "key", bytes("replacement"), "text/plain", Map.of())
|
||||
.getVersionId();
|
||||
service.deleteObject("bucket", "key", version);
|
||||
service.restoreBucketConfiguration("bucket", snapshot);
|
||||
return "replacement";
|
||||
}
|
||||
return "original";
|
||||
});
|
||||
|
||||
Method body = result.getClass().getDeclaredMethod("body");
|
||||
body.setAccessible(true);
|
||||
assertEquals("original", body.invoke(result));
|
||||
assertEquals(2, reads.get());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void suspendedWritesAndDeletesPreserveLockedArchivedNulls(boolean memory) {
|
||||
for (String lock : List.of("ON", "COMPLIANCE", "GOVERNANCE")) {
|
||||
S3Service service = service(memory, new InMemoryStorage<>());
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of());
|
||||
String source = service.putObject("bucket", "source", bytes("copy source"), "text/plain", Map.of())
|
||||
.getVersionId();
|
||||
service.setBucketObjectLockEnabled("bucket");
|
||||
if ("ON".equals(lock)) {
|
||||
service.putObjectLegalHold("bucket", "key", "null", "ON");
|
||||
} else {
|
||||
service.putObjectRetention("bucket", "key", "null", lock, Instant.now().plusSeconds(3600), false);
|
||||
}
|
||||
service.putBucketVersioning("bucket", "Suspended");
|
||||
|
||||
assertDenied(() -> service.putObject("bucket", "key", bytes("replacement"), "text/plain", Map.of()));
|
||||
assertPreservedBodies(service);
|
||||
assertDenied(() -> service.copyObject("bucket", "source", "bucket", "key", source, new CopyObjectOptions()));
|
||||
assertPreservedBodies(service);
|
||||
assertDenied(() -> service.deleteObject("bucket", "key", null, false));
|
||||
assertPreservedBodies(service);
|
||||
if ("GOVERNANCE".equals(lock)) {
|
||||
service.deleteObject("bucket", "key", null, true);
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> service.getObject("bucket", "key", "null"));
|
||||
assertEquals("NoSuchVersion", missing.getErrorCode());
|
||||
} else {
|
||||
assertDenied(() -> service.deleteObject("bucket", "key", null, true));
|
||||
assertPreservedBodies(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void assertPreservedBodies(S3Service service) {
|
||||
assertArrayEquals(bytes("numbered"), service.getObject("bucket", "key").getData());
|
||||
assertArrayEquals(bytes("original"), service.getObject("bucket", "key", "null").getData());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void reservedKeysCannotReadOrMutateArchivedMetadata(boolean memory) throws IOException {
|
||||
S3Service service = service(memory, new InMemoryStorage<>());
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of());
|
||||
String reserved = "\0null-version/key";
|
||||
List<Runnable> requests = List.of(
|
||||
() -> service.putObject("bucket", reserved, bytes("bad"), "text/plain", Map.of()),
|
||||
() -> service.getObject("bucket", reserved),
|
||||
() -> service.getObject("bucket", reserved, "null"),
|
||||
() -> service.headObject("bucket", reserved),
|
||||
() -> service.deleteObject("bucket", reserved),
|
||||
() -> service.deleteObject("bucket", reserved, "null"),
|
||||
() -> service.putObjectTagging("bucket", reserved, Map.of("bad", "tag")),
|
||||
() -> service.copyObject("bucket", "key", "bucket", reserved),
|
||||
() -> service.initiateMultipartUpload("bucket", reserved, "text/plain"),
|
||||
() -> service.putObjectFromStream("bucket", reserved, new ByteArrayInputStream(bytes("bad")),
|
||||
"text/plain", Map.of()));
|
||||
for (Runnable request : requests) {
|
||||
AwsException error = assertThrows(AwsException.class, request::run);
|
||||
assertEquals("InvalidArgument", error.getErrorCode());
|
||||
}
|
||||
assertArrayEquals(bytes("original"), service.getObject("bucket", "key", "null").getData());
|
||||
assertEquals(2, service.listObjectVersions("bucket", null, 1000, null).versions().size());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void readsSpanningFailedPublicationRetryTheRestoredCurrentVersion(boolean explicitNull) throws Exception {
|
||||
PublicationFailureStore objects = new PublicationFailureStore();
|
||||
S3Service service = service(true, objects);
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
String snapshot = service.snapshotBucketConfiguration("bucket");
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
String numbered = service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of())
|
||||
.getVersionId();
|
||||
service.deleteObject("bucket", "key", numbered);
|
||||
service.restoreBucketConfiguration("bucket", snapshot);
|
||||
AtomicInteger reads = new AtomicInteger();
|
||||
AtomicReference<String> observed = new AtomicReference<>();
|
||||
objects.remaining = 1;
|
||||
objects.afterPut = true;
|
||||
objects.beforeFailure = () -> observed.set(
|
||||
new String(service.getObject("bucket", "key").getData(), StandardCharsets.UTF_8));
|
||||
|
||||
Object result = readSnapshot(service, explicitNull, ignored -> {
|
||||
if (reads.getAndIncrement() == 0) {
|
||||
assertThrows(IllegalStateException.class, () -> service.putObject(
|
||||
"bucket", "key", bytes("replacement"), "text/plain", Map.of()));
|
||||
return observed.get();
|
||||
}
|
||||
return new String(service.getObject("bucket", "key").getData(), StandardCharsets.UTF_8);
|
||||
});
|
||||
|
||||
Method body = result.getClass().getDeclaredMethod("body");
|
||||
body.setAccessible(true);
|
||||
assertEquals("replacement", observed.get());
|
||||
assertEquals("original", body.invoke(result));
|
||||
assertEquals(2, reads.get());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void failedNonEnabledPublicationRetainsArchivedNullHistory(boolean memory) throws Exception {
|
||||
for (String current : List.of("numbered", "promoted", "marker")) {
|
||||
for (boolean rollback : List.of(true, false)) {
|
||||
for (boolean afterPut : List.of(false, true)) {
|
||||
PublicationFailureStore objects = new PublicationFailureStore();
|
||||
S3Service service = service(memory, objects);
|
||||
S3Object original = service.putObject("bucket", "key", bytes("original"),
|
||||
"text/plain", Map.of("original", "metadata"));
|
||||
service.putObjectAnnotation("bucket", "key", "note", null, bytes("annotation"), null, null);
|
||||
service.putObjectTagging("bucket", "key", Map.of("original", "tag"));
|
||||
String snapshot = service.snapshotBucketConfiguration("bucket");
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
String numbered = service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of())
|
||||
.getVersionId();
|
||||
if ("promoted".equals(current)) {
|
||||
service.deleteObject("bucket", "key", numbered);
|
||||
} else if ("marker".equals(current)) {
|
||||
service.deleteObject("bucket", "key");
|
||||
}
|
||||
if (rollback) {
|
||||
service.restoreBucketConfiguration("bucket", snapshot);
|
||||
} else {
|
||||
service.putBucketVersioning("bucket", "Suspended");
|
||||
}
|
||||
objects.remaining = 1;
|
||||
objects.afterPut = afterPut;
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> service.putObject(
|
||||
"bucket", "key", bytes("replacement"), "text/plain", Map.of()));
|
||||
|
||||
S3Object retained = service.getObject("bucket", "key", "null");
|
||||
assertArrayEquals(bytes("original"), retained.getData());
|
||||
assertEquals(original.getETag(), retained.getETag());
|
||||
assertEquals(Map.of("original", "metadata"), retained.getMetadata());
|
||||
assertEquals(Map.of("original", "tag"), service.getObjectTagging("bucket", "key", "null"));
|
||||
assertArrayEquals(bytes("annotation"), service.readObjectAnnotationPayload(
|
||||
service.getObjectAnnotation("bucket", "key", "note", "null")));
|
||||
if ("marker".equals(current)) {
|
||||
assertEquals("NoSuchKey", assertThrows(AwsException.class,
|
||||
() -> service.getObject("bucket", "key")).getErrorCode());
|
||||
if (memory) {
|
||||
assertFalse(memoryBodies(service).values().stream()
|
||||
.anyMatch(body -> body instanceof byte[] payload
|
||||
&& Arrays.equals(payload, bytes("replacement"))),
|
||||
"failed marker replacement must not retain canonical bytes");
|
||||
} else {
|
||||
assertFalse(Files.exists(tempDir.resolve("s3/.accounts/000000000000/bucket/key.s3data")),
|
||||
"failed marker replacement must remove the canonical body");
|
||||
}
|
||||
} else {
|
||||
String previous = "promoted".equals(current) ? "original" : "numbered";
|
||||
assertArrayEquals(bytes(previous), service.getObject("bucket", "key").getData());
|
||||
}
|
||||
|
||||
service.putObject("bucket", "key", bytes("retry"), "text/plain", Map.of());
|
||||
assertArrayEquals(bytes("retry"), service.getObject("bucket", "key", "null").getData());
|
||||
assertFalse(objects.get("bucket/\0null-version/key").isPresent());
|
||||
assertEquals("NoSuchAnnotation", assertThrows(AwsException.class,
|
||||
() -> service.getObjectAnnotation("bucket", "key", "note", "null")).getErrorCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void failedNullReplacementRestoresBodyMetadataAndLockAtEachPublication(boolean memory) throws Exception {
|
||||
for (boolean marker : List.of(false, true)) {
|
||||
for (boolean afterPut : List.of(false, true)) {
|
||||
for (int failAt = 1; failAt <= 3; failAt++) {
|
||||
PublicationFailureStore objects = new PublicationFailureStore();
|
||||
S3Service service = service(memory, objects);
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of("original", "metadata"));
|
||||
service.putObjectAnnotation("bucket", "key", "note", null, bytes("annotation"), null, null);
|
||||
service.setBucketObjectLockEnabled("bucket");
|
||||
service.putObjectLegalHold("bucket", "key", "null", "ON");
|
||||
service.putObjectTagging("bucket", "key", Map.of("original", "tag"));
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
objects.remaining = failAt;
|
||||
objects.afterPut = afterPut;
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
if (marker) {
|
||||
service.deleteObject("bucket", "key");
|
||||
} else {
|
||||
service.putObject("bucket", "key", bytes("replacement"), "text/plain", Map.of());
|
||||
}
|
||||
});
|
||||
|
||||
S3Object original = service.getObject("bucket", "key");
|
||||
assertArrayEquals(bytes("original"), original.getData());
|
||||
assertEquals(Map.of("original", "metadata"), original.getMetadata());
|
||||
assertEquals("ON", original.getLegalHoldStatus());
|
||||
assertArrayEquals(bytes("annotation"), service.readObjectAnnotationPayload(
|
||||
service.getObjectAnnotation("bucket", "key", "note", "null")));
|
||||
assertEquals(Map.of("original", "tag"), service.getObjectTagging("bucket", "key", "null"));
|
||||
assertEquals(1, service.listObjectVersions("bucket", null, 1000, null).versions().size());
|
||||
assertFalse(objects.get("bucket/\0null-version/key").isPresent());
|
||||
if (!memory) {
|
||||
try (Stream<Path> files = Files.walk(tempDir.resolve("s3"))) {
|
||||
assertEquals(1, files.filter(Files::isRegularFile)
|
||||
.filter(file -> file.toString().endsWith(".s3data")).count());
|
||||
}
|
||||
}
|
||||
if (memory) {
|
||||
assertEquals(1, memoryBodies(service).size());
|
||||
}
|
||||
service.putObjectLegalHold("bucket", "key", "null", "OFF");
|
||||
service.deleteObject("bucket", "key", "null");
|
||||
if (!memory) {
|
||||
try (Stream<Path> files = Files.walk(tempDir.resolve("s3"))) {
|
||||
assertEquals(0, files.filter(Files::isRegularFile).count());
|
||||
}
|
||||
} else {
|
||||
assertEquals(0, memoryBodies(service).size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedStreamBodyWriteRemovesUnpublishedNullLink() throws IOException {
|
||||
MissingStagedBodyStore objects = new MissingStagedBodyStore(tempDir.resolve("s3"));
|
||||
S3Service service = service(false, objects);
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
objects.armed = true;
|
||||
|
||||
assertThrows(UncheckedIOException.class, () -> service.putObjectFromStream("bucket", "key",
|
||||
new ByteArrayInputStream(bytes("replacement")), "text/plain", Map.of()));
|
||||
|
||||
assertArrayEquals(bytes("original"), service.getObject("bucket", "key").getData());
|
||||
service.deleteObject("bucket", "key", "null");
|
||||
try (Stream<Path> files = Files.walk(tempDir.resolve("s3"))) {
|
||||
assertEquals(0, files.filter(Files::isRegularFile).count());
|
||||
}
|
||||
service.putObject("bucket", "key", bytes("retry"), "text/plain", Map.of());
|
||||
assertArrayEquals(bytes("retry"), service.getObject("bucket", "key").getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingNullHistoryUnderAMarkerRemovesAllBodyFiles() throws IOException {
|
||||
S3Service service = service(false, new InMemoryStorage<>());
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
String marker = service.deleteObject("bucket", "key").getVersionId();
|
||||
Path canonical = tempDir.resolve("s3/.accounts/000000000000/bucket/key.s3data");
|
||||
assertFalse(Files.exists(canonical));
|
||||
assertArrayEquals(bytes("original"), service.getObject("bucket", "key", "null").getData());
|
||||
|
||||
service.deleteObject("bucket", "key", "null");
|
||||
|
||||
assertTrue(service.listObjectVersions("bucket", "key", 1000, null).versions().stream()
|
||||
.anyMatch(version -> marker.equals(version.getVersionId()) && version.isDeleteMarker()));
|
||||
try (Stream<Path> files = Files.walk(tempDir.resolve("s3"))) {
|
||||
assertEquals(0, files.filter(Files::isRegularFile).count());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"get", "open", "copy"})
|
||||
void readsRetryWhenADeleteMarkerUnlinksTheCanonicalBody(String operation) {
|
||||
DeleteDuringReadStore objects = new DeleteDuringReadStore();
|
||||
S3Service service = service(false, objects);
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of());
|
||||
objects.service = service;
|
||||
objects.remaining = "copy".equals(operation) ? 2 : 1;
|
||||
|
||||
AwsException missing = assertThrows(AwsException.class, () -> {
|
||||
switch (operation) {
|
||||
case "get" -> service.getObject("bucket", "key");
|
||||
case "open" -> {
|
||||
try (S3Service.ObjectRead ignored = service.openObject("bucket", "key", null)) {
|
||||
fail("the concurrent marker must make the key absent");
|
||||
}
|
||||
}
|
||||
case "copy" -> service.copyObject("bucket", "key", "bucket", "destination");
|
||||
default -> throw new IllegalArgumentException(operation);
|
||||
}
|
||||
});
|
||||
assertEquals("NoSuchKey", missing.getErrorCode());
|
||||
assertEquals(0, objects.remaining);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unchangedMissingCanonicalBodyRemainsAStorageError() throws IOException {
|
||||
S3Service service = service(false, new InMemoryStorage<>());
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of());
|
||||
Files.delete(tempDir.resolve("s3/.accounts/000000000000/bucket/key.s3data"));
|
||||
assertThrows(UncheckedIOException.class, () -> service.getObject("bucket", "key"));
|
||||
assertThrows(UncheckedIOException.class, () -> service.openObject("bucket", "key", null));
|
||||
assertThrows(UncheckedIOException.class, () -> service.copyObject("bucket", "key", "bucket", "destination"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledMarkersNeverOverrideGovernanceButSuspendedArchivedBypassFailsClosed() {
|
||||
S3Service service = service(true, new InMemoryStorage<>());
|
||||
service.putObject("bucket", "key", bytes("original"), "text/plain", Map.of());
|
||||
service.setBucketObjectLockEnabled("bucket");
|
||||
service.putObjectRetention("bucket", "key", "null", "GOVERNANCE", Instant.now().plusSeconds(3600), false);
|
||||
service.putBucketVersioning("bucket", "Enabled");
|
||||
assertFalse(service.deleteOverridesGovernanceRetention("bucket", "key", null));
|
||||
service.putObject("bucket", "key", bytes("numbered"), "text/plain", Map.of());
|
||||
service.putBucketVersioning("bucket", "Suspended");
|
||||
boolean overrides = service.deleteOverridesGovernanceRetention("bucket", "key", null);
|
||||
assertFalse(overrides);
|
||||
for (boolean s3Enforced : List.of(false, true)) {
|
||||
boolean bypass = S3Controller.effectiveBypass(true, overrides, s3Enforced, false);
|
||||
assertFalse(bypass);
|
||||
assertDenied(() -> service.deleteObject("bucket", "key", null, bypass));
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<?, ?> memoryBodies(S3Service service) throws Exception {
|
||||
Field bodies = S3Service.class.getDeclaredField("memoryDataStore");
|
||||
bodies.setAccessible(true);
|
||||
return (Map<?, ?>) bodies.get(service);
|
||||
}
|
||||
|
||||
private static final class DeleteDuringReadStore extends InMemoryStorage<String, S3Object> {
|
||||
private S3Service service;
|
||||
private int remaining;
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
Optional<S3Object> object = super.get(key);
|
||||
if ("bucket/key".equals(key) && remaining > 0 && --remaining == 0) {
|
||||
service.deleteObject("bucket", "key");
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
private S3Service service(boolean memory, InMemoryStorage<String, S3Object> objects) {
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), objects, tempDir.resolve("s3"), memory);
|
||||
service.createBucket("bucket", "us-east-1");
|
||||
return service;
|
||||
}
|
||||
|
||||
private static Object readSnapshot(S3Service service, boolean explicitNull, Function<Object, String> reader)
|
||||
throws Exception {
|
||||
Method method = explicitNull
|
||||
? S3Service.class.getDeclaredMethod("readNullVersionSnapshot", String.class, String.class,
|
||||
Function.class, Consumer.class)
|
||||
: S3Service.class.getDeclaredMethod("readLatestSnapshot", String.class, String.class, String.class,
|
||||
Function.class, Consumer.class);
|
||||
method.setAccessible(true);
|
||||
Consumer<String> discard = ignored -> { };
|
||||
return explicitNull ? method.invoke(service, "bucket", "key", reader, discard)
|
||||
: method.invoke(service, "bucket", "key", null, reader, discard);
|
||||
}
|
||||
|
||||
private static void assertDenied(Runnable request) {
|
||||
assertEquals("AccessDenied", assertThrows(AwsException.class, request::run).getErrorCode());
|
||||
}
|
||||
|
||||
private static byte[] bytes(String text) {
|
||||
return text.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static final class PublicationFailureStore extends InMemoryStorage<String, S3Object> {
|
||||
private int remaining;
|
||||
private boolean afterPut;
|
||||
private Runnable beforeFailure;
|
||||
|
||||
@Override
|
||||
public void put(String key, S3Object value) {
|
||||
boolean fail = remaining > 0 && --remaining == 0;
|
||||
if (fail && !afterPut) {
|
||||
throw new IllegalStateException("injected metadata publication failure");
|
||||
}
|
||||
super.put(key, value);
|
||||
if (fail) {
|
||||
if (beforeFailure != null) {
|
||||
beforeFailure.run();
|
||||
}
|
||||
throw new IllegalStateException("injected failure after metadata publication");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MissingStagedBodyStore extends InMemoryStorage<String, S3Object> {
|
||||
private final Path root;
|
||||
private boolean armed;
|
||||
|
||||
private MissingStagedBodyStore(Path root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
if (armed && "bucket/key".equals(key)) {
|
||||
armed = false;
|
||||
try (Stream<Path> staged = Files.walk(root.resolve(".multipart"))) {
|
||||
for (Path file : staged.filter(Files::isRegularFile).toList()) {
|
||||
Files.delete(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
return super.get(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.ServiceConfigAccess;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.s3.model.S3Object;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
@@ -13,6 +14,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
@@ -135,6 +138,35 @@ class S3ObjectIndexJournalTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTagUpdateOnAnArchivedNullVersionIsReplayedFromTheJournal() throws IOException {
|
||||
Path directory = root.resolve("live");
|
||||
Path afterCrash = root.resolve("after-crash");
|
||||
StorageFactory first = newFactory(directory);
|
||||
try {
|
||||
S3Service s3 = newService(first, directory);
|
||||
s3.createBucket(VERSIONED_BUCKET, REGION);
|
||||
s3.putObject(VERSIONED_BUCKET, key(0), body(0), "text/plain", Map.of());
|
||||
s3.putBucketVersioning(VERSIONED_BUCKET, "Enabled");
|
||||
s3.putObject(VERSIONED_BUCKET, key(0), body(1), "text/plain", Map.of());
|
||||
s3.putObjectTagging(VERSIONED_BUCKET, key(0), "null", Map.of("stage", "archived"));
|
||||
copyAsLeftByAKill(directory, afterCrash);
|
||||
} finally {
|
||||
first.shutdownAll();
|
||||
}
|
||||
|
||||
StorageFactory second = newFactory(afterCrash);
|
||||
try {
|
||||
S3Service reopened = newService(second, afterCrash);
|
||||
assertEquals(Map.of("stage", "archived"),
|
||||
reopened.getObjectTagging(VERSIONED_BUCKET, key(0), "null"));
|
||||
assertArrayEquals(body(1), reopened.getObject(VERSIONED_BUCKET, key(0)).getData());
|
||||
assertArrayEquals(body(0), reopened.getObject(VERSIONED_BUCKET, key(0), "null").getData());
|
||||
} finally {
|
||||
second.shutdownAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLegalHoldSetByVersionIdOnTheCurrentVersionIsReplayedUnderTheLatestKeyToo() throws IOException {
|
||||
Path directory = root.resolve("live");
|
||||
@@ -161,6 +193,54 @@ class S3ObjectIndexJournalTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivedNullPromotionOrderSurvivesJournalReplay() throws IOException {
|
||||
Path directory = root.resolve("live");
|
||||
Path afterCrash = root.resolve("after-crash");
|
||||
StorageFactory first = newFactory(directory);
|
||||
try {
|
||||
S3Service s3 = newService(first, directory);
|
||||
s3.createBucket(VERSIONED_BUCKET, REGION);
|
||||
s3.putBucketVersioning(VERSIONED_BUCKET, "Enabled");
|
||||
s3.putObject(VERSIONED_BUCKET, key(0),
|
||||
"older numbered".getBytes(StandardCharsets.UTF_8), "text/plain", Map.of());
|
||||
s3.putBucketVersioning(VERSIONED_BUCKET, "Suspended");
|
||||
s3.putObject(VERSIONED_BUCKET, key(0),
|
||||
"newer null".getBytes(StandardCharsets.UTF_8), "text/plain", Map.of());
|
||||
copyAsLeftByAKill(directory, afterCrash);
|
||||
} finally {
|
||||
first.shutdownAll();
|
||||
}
|
||||
|
||||
StorageFactory second = newFactory(afterCrash);
|
||||
try {
|
||||
S3Service reopened = newService(second, afterCrash);
|
||||
List<S3Object> restored = reopened.listObjectVersions(
|
||||
VERSIONED_BUCKET, key(0), 100, null).versions();
|
||||
S3Object older = restored.stream()
|
||||
.filter(version -> version.getVersionId() != null)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
S3Object newerNull = restored.stream()
|
||||
.filter(version -> version.getVersionId() == null)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertTrue(older.getEventSequencer() != null && newerNull.getEventSequencer() != null,
|
||||
"initial PUT records must persist their write order before archival");
|
||||
Instant tied = Instant.parse("2026-10-21T00:00:00Z");
|
||||
older.setLastModified(tied);
|
||||
newerNull.setLastModified(tied);
|
||||
reopened.putBucketVersioning(VERSIONED_BUCKET, "Enabled");
|
||||
String currentVersionId = reopened.putObject(VERSIONED_BUCKET, key(0),
|
||||
"current".getBytes(StandardCharsets.UTF_8), "text/plain", Map.of()).getVersionId();
|
||||
reopened.deleteObject(VERSIONED_BUCKET, key(0), currentVersionId);
|
||||
assertArrayEquals("newer null".getBytes(StandardCharsets.UTF_8),
|
||||
reopened.getObject(VERSIONED_BUCKET, key(0)).getData());
|
||||
} finally {
|
||||
second.shutdownAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The storage directory as a process killed now would leave it, with no shutdown compaction.
|
||||
* Replaying a copy keeps the restarted factory from sharing the journal with the live writer.
|
||||
|
||||
+20
-10
@@ -125,17 +125,27 @@ class S3ObjectLockVersionedWriteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void writesOverLockedPreVersioningObjectAreStillDenied() {
|
||||
s3Service.createBucket("pre-versioning-bucket", "us-east-1");
|
||||
s3Service.setBucketObjectLockEnabled("pre-versioning-bucket");
|
||||
s3Service.putObject("pre-versioning-bucket", "held.txt", BODY, "text/plain", null,
|
||||
new PutObjectOptions().withLegalHoldStatus("ON"));
|
||||
s3Service.putBucketVersioning("pre-versioning-bucket", "Enabled");
|
||||
void writesOverLockedPreVersioningObjectsPreserveTheNullVersion() {
|
||||
String bucket = "pre-versioning-bucket";
|
||||
s3Service.createBucket(bucket, "us-east-1");
|
||||
s3Service.setBucketObjectLockEnabled(bucket);
|
||||
for (String key : List.of("put", "copy", "marker", "multipart")) {
|
||||
s3Service.putObject(bucket, key, BODY, "text/plain", null,
|
||||
new PutObjectOptions().withLegalHoldStatus("ON"));
|
||||
}
|
||||
s3Service.putBucketVersioning(bucket, "Enabled");
|
||||
|
||||
assertAccessDenied(() -> s3Service.putObject("pre-versioning-bucket", "held.txt", BODY, "text/plain", null));
|
||||
assertAccessDenied(() -> s3Service.copyObject(BUCKET, "source.txt", "pre-versioning-bucket", "held.txt"));
|
||||
assertAccessDenied(() -> s3Service.deleteObject("pre-versioning-bucket", "held.txt", null, false));
|
||||
assertEquals("ON", s3Service.getObject("pre-versioning-bucket", "held.txt").getLegalHoldStatus());
|
||||
assertNotNull(s3Service.putObject(bucket, "put", BODY, "text/plain", null).getVersionId());
|
||||
assertNotNull(s3Service.copyObject(BUCKET, "source.txt", bucket, "copy").getVersionId());
|
||||
assertTrue(s3Service.deleteObject(bucket, "marker", null, false).isDeleteMarker());
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload(bucket, "multipart", "text/plain");
|
||||
s3Service.uploadPart(bucket, "multipart", upload.getUploadId(), 1, BODY);
|
||||
assertNotNull(s3Service.completeMultipartUpload(bucket, "multipart", upload.getUploadId(),
|
||||
List.of(1), null, null).getVersionId());
|
||||
for (String key : List.of("put", "copy", "marker", "multipart")) {
|
||||
assertEquals("ON", s3Service.getObject(bucket, key, "null").getLegalHoldStatus());
|
||||
assertAccessDenied(() -> s3Service.deleteObject(bucket, key, "null", true));
|
||||
}
|
||||
}
|
||||
|
||||
private S3Object putLegalHold(String key) {
|
||||
|
||||
@@ -468,15 +468,26 @@ class S3ServiceAnnotationsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteMarkerOnPreVersioningObjectRemovesItsAnnotations() throws Exception {
|
||||
void deleteMarkerOnPreVersioningObjectPreservesItsAnnotationsUntilPermanentDeletion() throws Exception {
|
||||
putAnnotation("pre-versioning", "payload");
|
||||
s3Service.putBucketVersioning(BUCKET, "Enabled");
|
||||
s3Service.deleteObject(BUCKET, "docs/readme.txt");
|
||||
S3Object marker = s3Service.deleteObject(BUCKET, "docs/readme.txt");
|
||||
|
||||
// The annotations are gone, including the payload files on disk.
|
||||
ObjectAnnotation annotation = s3Service.getObjectAnnotation(
|
||||
BUCKET, "docs/readme.txt", "pre-versioning", "null");
|
||||
assertEquals("payload", new String(
|
||||
s3Service.readObjectAnnotationPayload(annotation), StandardCharsets.UTF_8));
|
||||
try (Stream<Path> stream = Files.walk(tempDir.resolve("s3").resolve(".accounts")
|
||||
.resolve("000000000000").resolve(".annotations"))) {
|
||||
List<java.nio.file.Path> files = stream.filter(Files::isRegularFile).toList();
|
||||
List<Path> files = stream.filter(Files::isRegularFile).toList();
|
||||
assertEquals(1, files.size());
|
||||
}
|
||||
|
||||
s3Service.deleteObject(BUCKET, "docs/readme.txt", marker.getVersionId());
|
||||
s3Service.deleteObject(BUCKET, "docs/readme.txt", "null");
|
||||
try (Stream<Path> stream = Files.walk(tempDir.resolve("s3").resolve(".accounts")
|
||||
.resolve("000000000000").resolve(".annotations"))) {
|
||||
List<Path> files = stream.filter(Files::isRegularFile).toList();
|
||||
assertTrue(files.isEmpty(), "annotation payload files should be removed, found: " + files);
|
||||
}
|
||||
}
|
||||
@@ -589,4 +600,4 @@ class S3ServiceAnnotationsTest {
|
||||
AwsException exception = assertThrows(AwsException.class, action::run);
|
||||
assertEquals(errorCode, exception.getErrorCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
+109
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -650,12 +651,15 @@ class S3VersioningIntegrationTest {
|
||||
String legalHold = "<LegalHold><Status>OFF</Status></LegalHold>";
|
||||
|
||||
String old = "/" + bucket + "/old";
|
||||
given().body("replacement").when().put(old).then().statusCode(200);
|
||||
given().queryParam("versionId", "null").body(retention).when().put(old + "?retention").then().statusCode(200);
|
||||
given().queryParam("versionId", "null").when().get(old + "?retention")
|
||||
.then().statusCode(200).body(containsString("<Mode>GOVERNANCE</Mode>"));
|
||||
given().queryParam("versionId", "null").body(legalHold).when().put(old + "?legal-hold").then().statusCode(200);
|
||||
given().queryParam("versionId", "null").when().get(old + "?legal-hold")
|
||||
.then().statusCode(200).body(containsString("<Status>OFF</Status>"));
|
||||
given().queryParam("versionId", "null").when().delete(old)
|
||||
.then().statusCode(403).body(containsString("<Code>AccessDenied</Code>"));
|
||||
|
||||
String added = "/" + bucket + "/new";
|
||||
Matcher<String> noSuchVersion = containsString("<Code>NoSuchVersion</Code>");
|
||||
@@ -672,13 +676,118 @@ class S3VersioningIntegrationTest {
|
||||
.when().delete(old).then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
void aVersionedOverwritePreservesAndPromotesTheNullVersion() {
|
||||
String bucket = "versioned-archived-null-test";
|
||||
String key = "/" + bucket + "/key";
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
given().body("null body").when().put(key).then().statusCode(200);
|
||||
given().queryParam("annotationName", "labels").body("kept")
|
||||
.when().put(key + "?annotation").then().statusCode(200);
|
||||
given().body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when().put("/" + bucket + "?versioning").then().statusCode(200);
|
||||
String currentVersion = given().body("versioned body").when().put(key)
|
||||
.then().statusCode(200).extract().header("x-amz-version-id");
|
||||
|
||||
String versions = given().when().get("/" + bucket + "?versions&prefix=key")
|
||||
.then().statusCode(200).extract().asString();
|
||||
assertEquals(1, occurrences(versions, "<VersionId>null</VersionId>"));
|
||||
assertEquals(1, occurrences(versions, "<VersionId>" + currentVersion + "</VersionId>"));
|
||||
given().queryParam("versionId", "null").when().get(key)
|
||||
.then().statusCode(200).body(equalTo("null body"));
|
||||
given().queryParam("versionId", "null").queryParam("annotationName", "labels")
|
||||
.when().get(key + "?annotation").then().statusCode(200).body(equalTo("kept"));
|
||||
given().header("x-amz-copy-source", "/" + bucket + "/key?versionId=null")
|
||||
.when().put("/" + bucket + "/copy").then().statusCode(200);
|
||||
given().when().get("/" + bucket + "/copy").then().statusCode(200).body(equalTo("null body"));
|
||||
|
||||
given().when().delete(key + "?versionId=" + currentVersion).then().statusCode(204);
|
||||
given().when().get(key).then().statusCode(200).body(equalTo("null body"));
|
||||
versions = given().when().get("/" + bucket + "?versions&prefix=key")
|
||||
.then().statusCode(200).extract().asString();
|
||||
assertEquals(1, occurrences(versions, "<VersionId>null</VersionId>"));
|
||||
assertEquals(1, occurrences(versions, "<IsLatest>true</IsLatest>"));
|
||||
|
||||
given().when().delete(key + "?versionId=null").then().statusCode(204);
|
||||
given().when().get(key).then().statusCode(404);
|
||||
given().queryParam("versionId", "null").queryParam("annotationName", "labels")
|
||||
.when().get(key + "?annotation").then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(27)
|
||||
void aDeleteMarkerPreservesTheCurrentNullVersion() {
|
||||
String bucket = "versioned-null-marker-test";
|
||||
String key = "/" + bucket + "/key";
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
given().body("null body").when().put(key).then().statusCode(200);
|
||||
given().queryParam("annotationName", "labels").body("kept")
|
||||
.when().put(key + "?annotation").then().statusCode(200);
|
||||
given().body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when().put("/" + bucket + "?versioning").then().statusCode(200);
|
||||
|
||||
String markerId = given().when().delete(key)
|
||||
.then().statusCode(204).extract().header("x-amz-version-id");
|
||||
given().when().get(key).then().statusCode(404);
|
||||
given().queryParam("versionId", "null").when().get(key)
|
||||
.then().statusCode(200).body(equalTo("null body"));
|
||||
given().queryParam("versionId", "null").queryParam("annotationName", "labels")
|
||||
.when().get(key + "?annotation").then().statusCode(200).body(equalTo("kept"));
|
||||
|
||||
given().when().delete(key + "?versionId=" + markerId).then().statusCode(204);
|
||||
given().when().get(key).then().statusCode(200).body(equalTo("null body"));
|
||||
String versions = given().when().get("/" + bucket + "?versions&prefix=key")
|
||||
.then().statusCode(200).extract().asString();
|
||||
assertEquals(1, occurrences(versions, "<VersionId>null</VersionId>"));
|
||||
}
|
||||
|
||||
private static String tagging(String value) {
|
||||
return "<Tagging><TagSet><Tag><Key>version</Key><Value>" + value + "</Value></Tag></TagSet></Tagging>";
|
||||
}
|
||||
|
||||
private static int occurrences(String value, String needle) {
|
||||
return value.split(Pattern.quote(needle), -1).length - 1;
|
||||
}
|
||||
|
||||
private static Matcher<String> deleteMarkerRefused(String method) {
|
||||
return allOf(containsString("<Code>MethodNotAllowed</Code>"),
|
||||
containsString("<Method>" + method + "</Method>"),
|
||||
containsString("<ResourceType>DeleteMarker</ResourceType>"));
|
||||
}
|
||||
@Test
|
||||
@Order(28)
|
||||
void versionedWritesAndMarkersPreserveComplianceLockedNullVersions() {
|
||||
String bucket = "versioned-locked-null-preservation";
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
for (String key : List.of("put", "copy", "marker")) {
|
||||
given().body("original").when().put("/" + bucket + "/" + key).then().statusCode(200);
|
||||
}
|
||||
given().body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when().put("/" + bucket + "?versioning").then().statusCode(200);
|
||||
given().body("<ObjectLockConfiguration><ObjectLockEnabled>Enabled</ObjectLockEnabled></ObjectLockConfiguration>")
|
||||
.when().put("/" + bucket + "?object-lock").then().statusCode(200);
|
||||
for (String key : List.of("put", "copy", "marker")) {
|
||||
given().queryParam("versionId", "null")
|
||||
.body("<Retention><Mode>COMPLIANCE</Mode><RetainUntilDate>2031-01-01T00:00:00Z</RetainUntilDate></Retention>")
|
||||
.when().put("/" + bucket + "/" + key + "?retention").then().statusCode(200);
|
||||
}
|
||||
|
||||
given().body("replacement").when().put("/" + bucket + "/put").then().statusCode(200);
|
||||
given().header("x-amz-copy-source", "/" + bucket + "/put")
|
||||
.when().put("/" + bucket + "/copy").then().statusCode(200);
|
||||
given().when().delete("/" + bucket + "/marker").then().statusCode(204)
|
||||
.header("x-amz-delete-marker", "true");
|
||||
|
||||
for (String key : List.of("put", "copy", "marker")) {
|
||||
String path = "/" + bucket + "/" + key;
|
||||
given().queryParam("versionId", "null").when().get(path)
|
||||
.then().statusCode(200).body(equalTo("original"));
|
||||
given().queryParam("versionId", "null").when().get(path + "?retention")
|
||||
.then().statusCode(200).body(containsString("<Mode>COMPLIANCE</Mode>"));
|
||||
given().queryParam("versionId", "null").header("x-amz-bypass-governance-retention", "true")
|
||||
.when().delete(path).then().statusCode(403).body(containsString("<Code>AccessDenied</Code>"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,9 +13,11 @@ import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -45,6 +47,216 @@ class S3VersioningServiceTest {
|
||||
assertEquals("Suspended", s3Service.getBucketVersioning("versioned-bucket"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void suspendedPutReplacesAnArchivedNullVersionWithoutLeavingADuplicate() {
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"original null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"versioned".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Suspended");
|
||||
|
||||
S3Object replacement = s3Service.putObject("versioned-bucket", "key",
|
||||
"replacement null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
List<S3Object> versions = s3Service.listObjectVersions("versioned-bucket", "key", 100, null).versions();
|
||||
assertEquals(1, versions.stream().filter(version -> version.getVersionId() == null).count());
|
||||
S3Object listedNull = versions.stream().filter(version -> version.getVersionId() == null).findFirst().orElseThrow();
|
||||
assertTrue(listedNull.isLatest());
|
||||
assertEquals(replacement.getETag(), listedNull.getETag());
|
||||
assertEquals("replacement null", new String(
|
||||
s3Service.getObject("versioned-bucket", "key", "null").getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void suspendedDeleteRemovesAnArchivedNullVersion() {
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"original null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"versioned".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Suspended");
|
||||
|
||||
s3Service.deleteObject("versioned-bucket", "key");
|
||||
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> s3Service.getObject("versioned-bucket", "key", "null"));
|
||||
assertEquals("NoSuchVersion", missing.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAnAbsentNullVersionDoesNotDeleteAKeyThatLooksLikeItsHistoryEntry() {
|
||||
s3Service.putObject("versioned-bucket", "key#v#null",
|
||||
"tricky".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
assertNull(s3Service.deleteObject("versioned-bucket", "key", "null"));
|
||||
assertEquals("tricky", new String(
|
||||
s3Service.getObject("versioned-bucket", "key#v#null").getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivingANullVersionDoesNotOverwriteAKeyThatLooksLikeItsLegacyHistoryEntry() {
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"null version".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putObject("versioned-bucket", "key#v#null",
|
||||
"tricky".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
|
||||
S3Object replacement = s3Service.putObject("versioned-bucket", "key",
|
||||
"replacement".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
assertEquals("tricky", new String(
|
||||
s3Service.getObject("versioned-bucket", "key#v#null").getData(), StandardCharsets.UTF_8));
|
||||
assertEquals("null version", new String(
|
||||
s3Service.getObject("versioned-bucket", "key", "null").getData(), StandardCharsets.UTF_8));
|
||||
|
||||
s3Service.deleteObject("versioned-bucket", "key", replacement.getVersionId());
|
||||
|
||||
assertEquals("null version", new String(
|
||||
s3Service.getObject("versioned-bucket", "key").getData(), StandardCharsets.UTF_8));
|
||||
assertEquals("null version", new String(
|
||||
s3Service.getObject("versioned-bucket", "key", "null").getData(), StandardCharsets.UTF_8));
|
||||
assertEquals("tricky", new String(
|
||||
s3Service.getObject("versioned-bucket", "key#v#null").getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivedNullVersionIsNotListedAsAnOrdinaryObject() {
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"null version".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
s3Service.putObject("versioned-bucket", "key",
|
||||
"replacement".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
List<S3Object> objects = s3Service.listObjects("versioned-bucket", null, null, 100);
|
||||
|
||||
assertEquals(1, objects.size());
|
||||
assertEquals("key", objects.get(0).getKey());
|
||||
assertNotNull(objects.get(0).getVersionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivedNullVersionWithLegacyMarkerInKeyIsListedOnce() {
|
||||
String key = "key#v#part";
|
||||
s3Service.putObject("versioned-bucket", key,
|
||||
"null version".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
S3Object current = s3Service.putObject("versioned-bucket", key,
|
||||
"replacement".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
List<S3Object> versions = s3Service.listObjectVersions(
|
||||
"versioned-bucket", key, 100, null).versions();
|
||||
|
||||
assertEquals(1, versions.stream().filter(version -> version.getVersionId() == null).count());
|
||||
|
||||
s3Service.deleteObject("versioned-bucket", key, current.getVersionId());
|
||||
|
||||
versions = s3Service.listObjectVersions("versioned-bucket", key, 100, null).versions();
|
||||
assertEquals(1, versions.size());
|
||||
assertNull(versions.getFirst().getVersionId());
|
||||
assertTrue(versions.getFirst().isLatest());
|
||||
}
|
||||
|
||||
@Test
|
||||
void staleMetadataUpdateDoesNotOverwriteAReplacementArchivedNullVersion() {
|
||||
MetadataReplacementStore objectStore = new MetadataReplacementStore();
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), objectStore, tempDir, true);
|
||||
service.createBucket("versioned-bucket", "us-east-1");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"old".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"numbered".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
objectStore.arm(service);
|
||||
|
||||
service.putObjectTagging("versioned-bucket", "key", "null", Map.of("stale", "tag"));
|
||||
|
||||
S3Object nullVersion = service.getObject("versioned-bucket", "key", "null");
|
||||
assertEquals("replacement", new String(nullVersion.getData(), StandardCharsets.UTF_8));
|
||||
assertEquals("replacement".length(), nullVersion.getSize());
|
||||
assertTrue(service.getObjectTagging("versioned-bucket", "key", "null").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void currentNullSnapshotSurvivesArchiveAndPromotionDuringTheRead() {
|
||||
SnapshotAbaStore objectStore = new SnapshotAbaStore();
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), objectStore, tempDir, true);
|
||||
service.createBucket("versioned-bucket", "us-east-1");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"original".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
objectStore.arm(service);
|
||||
|
||||
S3Object nullVersion = service.getObject("versioned-bucket", "key", "null");
|
||||
|
||||
assertEquals("original", new String(nullVersion.getData(), StandardCharsets.UTF_8));
|
||||
assertEquals("original", new String(
|
||||
service.getObject("versioned-bucket", "key").getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void latestNullSnapshotSurvivesArchiveAndPromotionDuringTheRead() {
|
||||
SnapshotAbaStore objectStore = new SnapshotAbaStore();
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), objectStore, tempDir, true);
|
||||
service.createBucket("versioned-bucket", "us-east-1");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"original".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
objectStore.arm(service);
|
||||
|
||||
S3Object latest = service.getObject("versioned-bucket", "key");
|
||||
|
||||
assertEquals("original", new String(latest.getData(), StandardCharsets.UTF_8));
|
||||
assertEquals("original", new String(
|
||||
service.getObject("versioned-bucket", "key").getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void delayedMetadataUpdateDemotesTheNullHistoryEntryItTargets() {
|
||||
MetadataArchiveStore objectStore = new MetadataArchiveStore();
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), objectStore, tempDir, true);
|
||||
service.createBucket("versioned-bucket", "us-east-1");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"original".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
objectStore.arm(service);
|
||||
|
||||
service.putObjectTagging("versioned-bucket", "key", "null", Map.of("kept", "tag"));
|
||||
|
||||
List<S3Object> versions = service.listObjectVersions("versioned-bucket", "key", 100, null).versions();
|
||||
assertEquals(1, versions.stream().filter(S3Object::isLatest).count());
|
||||
assertFalse(versions.stream()
|
||||
.filter(version -> version.getVersionId() == null)
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.isLatest());
|
||||
assertEquals(Map.of("kept", "tag"), service.getObjectTagging("versioned-bucket", "key", "null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivedNullKeepsItsSequencerForSameMillisecondPromotionOrder() {
|
||||
InMemoryStorage<String, S3Object> objectStore = new InMemoryStorage<>();
|
||||
S3Service service = new S3Service(new InMemoryStorage<>(), objectStore, tempDir, true);
|
||||
service.createBucket("versioned-bucket", "us-east-1");
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
S3Object older = service.putObject("versioned-bucket", "key",
|
||||
"older numbered".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
service.putBucketVersioning("versioned-bucket", "Suspended");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"newer null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
Instant tied = Instant.parse("2026-10-21T00:00:00Z");
|
||||
objectStore.get("versioned-bucket/key#v#" + older.getVersionId()).orElseThrow().setLastModified(tied);
|
||||
objectStore.get("versioned-bucket/key").orElseThrow().setLastModified(tied);
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
S3Object current = service.putObject("versioned-bucket", "key",
|
||||
"current".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
service.deleteObject("versioned-bucket", "key", current.getVersionId());
|
||||
|
||||
assertEquals("newer null", new String(
|
||||
service.getObject("versioned-bucket", "key").getData(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void versioningNotEnabledByDefault() {
|
||||
assertNull(s3Service.getBucketVersioning("versioned-bucket"));
|
||||
@@ -526,4 +738,80 @@ class S3VersioningServiceTest {
|
||||
assertDoesNotThrow(() -> s3Service.deleteBucket("versioned-bucket"));
|
||||
}
|
||||
|
||||
private static final class MetadataReplacementStore extends InMemoryStorage<String, S3Object> {
|
||||
private S3Service service;
|
||||
private boolean armed;
|
||||
|
||||
private void arm(S3Service service) {
|
||||
this.service = service;
|
||||
armed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
Optional<S3Object> result = super.get(key);
|
||||
if (armed && key.indexOf('\0') >= 0) {
|
||||
armed = false;
|
||||
service.putBucketVersioning("versioned-bucket", "Suspended");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"replacement".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"latest".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MetadataArchiveStore extends InMemoryStorage<String, S3Object> {
|
||||
private S3Service service;
|
||||
private boolean armed;
|
||||
|
||||
private void arm(S3Service service) {
|
||||
this.service = service;
|
||||
armed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
Optional<S3Object> result = super.get(key);
|
||||
if (armed && "versioned-bucket/key".equals(key)) {
|
||||
armed = false;
|
||||
service.putObject("versioned-bucket", "key",
|
||||
"replacement".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class SnapshotAbaStore extends InMemoryStorage<String, S3Object> {
|
||||
private S3Service service;
|
||||
private int stage = -1;
|
||||
private String replacementVersionId;
|
||||
|
||||
private void arm(S3Service service) {
|
||||
this.service = service;
|
||||
stage = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S3Object> get(String key) {
|
||||
if (!"versioned-bucket/key".equals(key) || stage < 0 || stage > 1) {
|
||||
return super.get(key);
|
||||
}
|
||||
if (stage == 0) {
|
||||
Optional<S3Object> original = super.get(key);
|
||||
stage = -1;
|
||||
replacementVersionId = service.putObject("versioned-bucket", "key",
|
||||
"replacement".getBytes(StandardCharsets.UTF_8), "text/plain", null).getVersionId();
|
||||
stage = 1;
|
||||
return original;
|
||||
}
|
||||
stage = -1;
|
||||
service.deleteObject("versioned-bucket", "key", replacementVersionId);
|
||||
stage = 2;
|
||||
return super.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user