feat: sync guard - Blockieren alter Clients beim sync
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,19 @@ public sealed class SyncStatusViewModelTests
|
||||
Assert.False(fired);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InkompatibleSyncVersion_ZeigtKlareUpdateMeldung()
|
||||
{
|
||||
using var temp = new TempSyncEngine(new IncompatibleVersionStubHandler());
|
||||
var vm = new SyncStatusViewModel(temp.Engine);
|
||||
|
||||
await temp.Engine.SyncNowAsync();
|
||||
|
||||
Assert.True(vm.IsIncompatibleVersion);
|
||||
Assert.Equal("Update erforderlich", vm.StatusText);
|
||||
Assert.Contains("Bitte aktualisiere die LehrerApp", SyncStatusViewModel.IncompatibleVersionMessage);
|
||||
}
|
||||
|
||||
private sealed class PullEventStubHandler : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
@@ -100,6 +113,17 @@ public sealed class SyncStatusViewModelTests
|
||||
});
|
||||
}
|
||||
|
||||
private sealed class IncompatibleVersionStubHandler : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new HttpResponseMessage(HttpStatusCode.UpgradeRequired);
|
||||
response.Headers.Add(SyncProtocol.VersionHeaderName, "2");
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TempSyncEngine : IDisposable
|
||||
{
|
||||
private readonly string _queuePath = Path.Combine(
|
||||
|
||||
Reference in New Issue
Block a user