#!perl
use Cassandane::Tiny;
use experimental 'signatures';

# A client-supplied Schedule-Address must not let a user schedule as an
# identity that isn't theirs.  Here cassandane writes to their own calendar
# but names other@example.com as both ORGANIZER and Schedule-Address; the
# server must ignore the override and send no iMIP REQUEST as other.
sub test_schedule_address_other_organizer
    ($self)
{
    my $service = $self->{instance}->get_service("http");
    my $CalDAV = $self->{caldav};

    my $CalendarId = $CalDAV->NewCalendar({name => 'hello'});
    $self->assert_not_null($CalendarId);

    my $uuid = "6de280c9-edff-4019-8ebd-cfebc73f8201";
    my $href = "$CalendarId/$uuid.ics";
    my $card = <<EOF;
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Cyrus//Cassandane//EN
BEGIN:VEVENT
CREATED:20260519T120000Z
UID:$uuid
DTSTART;TZID=Australia/Melbourne:20260901T153000
DTEND;TZID=Australia/Melbourne:20260901T183000
DTSTAMP:20260519T120000Z
SEQUENCE:0
SUMMARY:other invite
ORGANIZER;CN=Other:MAILTO:other\@example.com
ATTENDEE;CN=Other;PARTSTAT=ACCEPTED;RSVP=TRUE:MAILTO:other\@example.com
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:friend\@example.com
END:VEVENT
END:VCALENDAR
EOF

    $self->{instance}->getnotify;

    $CalDAV->Request('PUT', $href, $card,
        'Content-Type' => 'text/calendar',
        'Schedule-Address' => 'other@example.com');

    # The override names an address cassandane doesn't hold, so no iTIP
    # REQUEST may be sent as other.
    $self->assert_caldav_notified();
}
