feat: sync guard - Blockieren alter Clients beim sync

This commit is contained in:
2026-08-20 23:54:04 +02:00
parent 7b883555bf
commit 59bd8abb45
19 changed files with 369 additions and 26 deletions
@@ -0,0 +1,33 @@
using System.Net;
using LehrerApp.Desktop.Services;
using LehrerApp.Sync;
using Xunit;
namespace LehrerApp.Desktop.Tests;
public sealed class SyncAuthServiceProtocolTests
{
[Fact]
public async Task TestConnectionAsync_InkompatibleVersion_WirdNichtAlsOfflineGemeldet()
{
HttpRequestMessage? sent = null;
var service = new SyncAuthService(new HttpClient(new Handler(request =>
{
sent = request;
return new HttpResponseMessage(HttpStatusCode.UpgradeRequired);
})));
var result = await service.TestConnectionAsync("https://sync.example.invalid", "token");
Assert.Equal(SyncConnectionTestResult.IncompatibleVersion, result);
Assert.Equal(SyncProtocol.CurrentVersion,
sent!.Headers.GetValues(SyncProtocol.VersionHeaderName).Single());
}
private sealed class Handler(Func<HttpRequestMessage, HttpResponseMessage> response) : HttpMessageHandler
{
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) =>
Task.FromResult(response(request));
}
}