#!perl
use Cassandane::Tiny;

sub test_blob_upload_repair_acl
    :min_version_3_7 :JMAPExtensions
{
    my $self = shift;
    my $jmap = $self->{jmap};
    my $admin = $self->{adminstore}->get_client();

    $jmap->Upload("hello", "application/data");

    my $binary = slurp_file(abs_path('data/mime/repair_acl.eml'));

    xlog "Assert that uploading duplicates does not fail";
    $admin->setacl("user.cassandane.#jmap", "cassandane", "lrswkcni") or die;
    my $res = $jmap->Upload($binary);
    my $blobId = $res->{blobId};
    $res = $jmap->Upload($binary, "message/rfc822");
    $self->assert_str_equals($blobId, $res->{blobId});

    xlog "Assert ACLs got repaired";
    my %acl = @{$admin->getacl("user.cassandane.#jmap")};
    $self->assert_str_equals("lrswitedn", $acl{cassandane});
}
