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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user