iCal-Ereignisse mit LAST-MODIFIED statt fehlendem DTSTAMP lesen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m3s

This commit is contained in:
Lars committed 2026-10-29 15:53:55 +01:00
1 parent 386e2cf0a9
commit 2ae48e77fa
4 files changed
+64 -4

No files matched your search

@@ -177,6 +177,7 @@ public function test_repeated_import_and_identical_duplicate_uids_are_idempotent
public static function invalidFeedProvider(): array
{
$valid = self::feed(self::event('external-1'));
$fallback = str_replace('DTSTAMP:20261101T090000Z', 'LAST-MODIFIED:20261101T090000Z', $valid);
return [
'not calendar' => ['<html>Login</html>'],
@@ -186,6 +187,16 @@ public static function invalidFeedProvider(): array
'invalid date' => [str_replace('20261107', '20261131', $valid)],
'missing UID' => [str_replace("UID:external-1\r\n", '', $valid)],
'missing stamp' => [str_replace("DTSTAMP:20261101T090000Z\r\n", '', $valid)],
'empty fallback stamp' => [str_replace('LAST-MODIFIED:20261101T090000Z', 'LAST-MODIFIED:', $fallback)],
'non UTC fallback stamp' => [str_replace('LAST-MODIFIED:20261101T090000Z', 'LAST-MODIFIED:20261101T090000', $fallback)],
'invalid fallback date' => [str_replace('LAST-MODIFIED:20261101T090000Z', 'LAST-MODIFIED:20260230T090000Z', $fallback)],
'invalid present stamp with valid fallback' => [str_replace('DTSTAMP:20261101T090000Z', "DTSTAMP:invalid\r\nLAST-MODIFIED:20261101T090000Z", $valid)],
'empty present stamp with valid fallback' => [str_replace('DTSTAMP:20261101T090000Z', "DTSTAMP:\r\nLAST-MODIFIED:20261101T090000Z", $valid)],
'duplicate fallback stamp' => [str_replace('LAST-MODIFIED:20261101T090000Z', "LAST-MODIFIED:20261101T090000Z\r\nLAST-MODIFIED:20261101T100000Z", $fallback)],
'duplicate primary stamp' => [str_replace('DTSTAMP:20261101T090000Z', "DTSTAMP:20261101T090000Z\r\nDTSTAMP:20261101T100000Z", $valid)],
'created is not a fallback' => [str_replace('DTSTAMP:20261101T090000Z', 'CREATED:20261101T090000Z', $valid)],
'calendar metadata is not an event fallback' => [str_replace("DTSTAMP:20261101T090000Z\r\n", '', str_replace('VERSION:2.0', "VERSION:2.0\r\nLAST-MODIFIED:20261101T090000Z", $valid))],
'fallback does not relax date validation' => [str_replace('20261107', '20261131', $fallback)],
'recurrence' => [str_replace('UID:external-1', "UID:external-1\r\nRRULE:FREQ=DAILY;COUNT=3", $valid)],
'different dates for same UID' => [self::feed(self::event('same').self::event('same', '20261114', '20261117'))],
'different value types' => [str_replace('DTEND;VALUE=DATE:20261110', 'DTEND:20261110T100000Z', $valid)],
@@ -193,6 +204,44 @@ public static function invalidFeedProvider(): array
];
}
public function test_valid_last_modified_can_replace_missing_dtstamp_without_rewriting_originals_or_identity(): void
{
$property = $this->property();
$channel = $this->channel($property);
$body = self::feed(
"BEGIN:VEVENT\r\nUID:without-stamp\r\nSTATUS:1\r\nDTSTART:20261110T120000Z\r\nDTEND:20261124T115959Z\r\nLAST-MODIFIED:20261029T152031Z\r\nSUMMARY:Belegt\r\nEND:VEVENT\r\n".
"BEGIN:VEVENT\r\nUID:summer-time\r\nSTATUS:1\r\nDTSTART:20270328T130000Z\r\nDTEND:20270404T115959Z\r\nLAST-MODIFIED:20261029T152031Z\r\nSUMMARY:Belegt\r\nEND:VEVENT\r\n"
);
$document = app(ICalParser::class)->parseDocument($body);
$this->assertCount(2, $document['events']);
$this->assertArrayNotHasKey('DTSTAMP', $document['events'][0]['properties']);
$this->assertSame('20261029T152031Z', $document['events'][0]['properties']['LAST-MODIFIED'][0]['value']);
$this->assertStringNotContainsString('DTSTAMP:', $document['events'][0]['raw']);
Http::preventStrayRequests();
Http::fake(['https://portal.example/*' => Http::sequence()->push($body)->push($body)
->push(str_replace('20261124T115959Z', '20261125T115959Z', $body))]);
Mail::fake();
$first = app(SyncChannel::class)->handle($channel);
$ids = $channel->blockedPeriods()->orderBy('id')->pluck('id')->all();
$second = app(SyncChannel::class)->handle($channel);
$third = app(SyncChannel::class)->handle($channel);
$this->assertTrue($first->successful);
$this->assertTrue($second->successful);
$this->assertTrue($third->successful);
$this->assertSame([2, 0, 1], [$first->added, $second->added, $third->changed]);
$this->assertSame($ids, $channel->blockedPeriods()->orderBy('id')->pluck('id')->all());
$ordinary = $channel->blockedPeriods()->where('external_uid', 'without-stamp')->sole();
$summerTime = $channel->blockedPeriods()->where('external_uid', 'summer-time')->sole();
$this->assertSame(['2026-11-10', '2026-11-25'], [$ordinary->starts_on->toDateString(), $ordinary->ends_on->toDateString()]);
$this->assertSame(['2027-03-28', '2027-04-04'], [$summerTime->starts_on->toDateString(), $summerTime->ends_on->toDateString()]);
$this->assertSame('unknown', $ordinary->occupationKind()->value);
$this->assertArrayNotHasKey('DTSTAMP', $ordinary->ical_properties);
$this->assertSame('1', $ordinary->ical_properties['STATUS'][0]['value']);
Http::assertSentCount(3);
}
#[DataProvider('invalidFeedProvider')]
public function test_invalid_snapshot_never_changes_existing_blocks(string $body): void
{