bucketwarden-server 0.1.0

BucketWarden storage server runtime.
Documentation
use super::*;

#[test]
fn replication_skips_preexisting_versions_when_existing_object_replication_is_disabled() {
    let mut runtime = BucketWarden::new(RuntimeConfig::development()).expect("runtime");
    runtime.allow("alice", "s3:*", "*");
    runtime.set_clock_epoch_seconds(10);
    runtime
        .create_bucket("alice", "archive-001")
        .expect("source");
    runtime
        .create_bucket("alice", "archive-002")
        .expect("destination");
    let existing = runtime
        .put_object(
            "alice",
            PutObjectRequest {
                bucket: "archive-001".to_string(),
                key: "records/existing.json".to_string(),
                body: b"existing".to_vec(),
                metadata: ObjectMetadata::default(),
            },
            ObjectLock::none(),
        )
        .expect("existing");

    runtime.set_clock_epoch_seconds(20);
    runtime
        .put_bucket_replication(
            "alice",
            "archive-001",
            Some("arn:aws:iam::123456789012:role/bucketwarden-replication".to_string()),
            vec![ReplicationRule {
                id: "records".to_string(),
                status: "Enabled".to_string(),
                destination_bucket: "arn:aws:s3:::archive-002".to_string(),
                prefix: Some("records/".to_string()),
                existing_object_replication: false,
                replicate_encrypted_objects: true,
                ..ReplicationRule::default()
            }],
        )
        .expect("replication config");
    runtime.set_clock_epoch_seconds(30);
    let current = runtime
        .put_object(
            "alice",
            PutObjectRequest {
                bucket: "archive-001".to_string(),
                key: "records/current.json".to_string(),
                body: b"current".to_vec(),
                metadata: ObjectMetadata::default(),
            },
            ObjectLock::none(),
        )
        .expect("current");

    let run = runtime
        .run_bucket_replication("alice", "archive-001")
        .expect("replication run");

    assert_eq!(run.replicated_object_versions, 1);
    assert!(matches!(
        runtime.get_object_version(
            "alice",
            "archive-002",
            "records/existing.json",
            &existing.version_id
        ),
        Err(RuntimeError::NoSuchKey(_)) | Err(RuntimeError::NoSuchVersion { .. })
    ));
    assert_eq!(
        runtime
            .get_object_version(
                "alice",
                "archive-002",
                "records/current.json",
                &current.version_id
            )
            .expect("replicated current")
            .body,
        b"current"
    );
}