mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-11-03 06:37:05 +01:00
Controllers no longer catch everything and return ex.Message as a 400, which leaked internal messages and made outages look like client errors. User-facing errors are now ClientExceptions; everything else is a generic 500 or a 503. S3 failover throws S3StorageUnavailableException when every endpoint fails transiently. Deleting an account checks the password first, since Identity's "Wrong password." only arrived as a WAMP runtime error. Inbox API key checks no longer turn database errors into 401s. Monograph sanitization fails closed instead of storing unsanitized content, and an unreachable WebRisk counts as safe, like an error response already did.
30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Streetwriters.Common.Services;
|
|
|
|
namespace Notesnook.API.Tests;
|
|
|
|
public class URLAnalyzerTests
|
|
{
|
|
static URLAnalyzerTests()
|
|
{
|
|
Environment.SetEnvironmentVariable("WEBRISK_API_URI", "http://webrisk.invalid/check");
|
|
}
|
|
|
|
private sealed class ThrowingHandler(Exception exception) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
=> Task.FromException<HttpResponseMessage>(exception);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Unreachable_webrisk_treats_urls_as_safe()
|
|
{
|
|
foreach (var exception in new Exception[] { new HttpRequestException("unreachable"), new TaskCanceledException("timed out") })
|
|
{
|
|
var analyzer = new URLAnalyzer(new HttpClient(new ThrowingHandler(exception)), NullLogger<URLAnalyzer>.Instance);
|
|
|
|
Assert.True(await analyzer.IsURLSafeAsync("https://example.com"));
|
|
}
|
|
}
|
|
}
|