SecretScrubber removes passwords, tokens, keys, cookies, authorisation headers, URL credentials and private-key blocks from text and JSON; DiagnosticsArchive zips reports, settings, failed jobs and log tails through it. The desktop bundle (Settings > Advanced, About) now adds the codec and encoder inventory, the settings and recent failed jobs; the server serves the same as GET /api/v1/server/diagnostics (ManageArchive, audited), linked from admin > Logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
66 lines
3.0 KiB
C#
66 lines
3.0 KiB
C#
using System.IO;
|
|
using System.IO.Compression;
|
|
using Titano.App.Infrastructure;
|
|
using Titano.App.Settings;
|
|
using Titano.Core.Video;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.App.Tests.Windows;
|
|
|
|
/// <summary>The desktop diagnostics bundle: every entry present, the saved server token and passwords never inside.</summary>
|
|
[WindowsOnly]
|
|
public sealed class DiagnosticsBundleTests(TestContext context)
|
|
{
|
|
private const string Token = "AQAAANCMnd8BFdERjHoAwE-saved-token";
|
|
|
|
[Test]
|
|
public async Task TheBundleCarriesReportsAndLogsButNoSecrets()
|
|
{
|
|
var environment = AppEnvironment.ForCapture();
|
|
try
|
|
{
|
|
var settings = new AppSettings { Language = "en", ServerUrl = "https://nas.local:8443", ServerUsername = "alice", ProtectedToken = Token };
|
|
var services = new AppServices(environment, settings, () => { }, new NoDialogs()) { Encoders = new OneEncoder() };
|
|
await File.WriteAllTextAsync(Path.Combine(environment.LogDirectory, "titano-20261002.log"), $"signed in with password={Token}\n");
|
|
|
|
var path = await DiagnosticsBundle.CreateAsync(services, context.CreateTempDirectory(), ["Self-test H.264 Test: passed"]);
|
|
|
|
using var zip = ZipFile.OpenRead(path);
|
|
var texts = zip.Entries.ToDictionary(e => e.FullName, e =>
|
|
{
|
|
using var reader = new StreamReader(e.Open());
|
|
return reader.ReadToEnd();
|
|
});
|
|
Assert.SequenceEqual(new[] { "codecs.txt", "environment.txt", "jobs-failed.json", "logs/titano-20261002.log", "settings.json" },
|
|
texts.Keys.Order(StringComparer.Ordinal));
|
|
foreach (var (name, text) in texts) Assert.False(text.Contains(Token, StringComparison.Ordinal), $"{name} leaks the token");
|
|
Assert.Contains("Self-test H.264 Test: passed", texts["environment.txt"]);
|
|
Assert.Contains("Test encoder", texts["codecs.txt"]);
|
|
Assert.Contains("\"ServerUsername\": \"alice\"", texts["settings.json"]);
|
|
Assert.Contains("\"ProtectedToken\": \"[removed]\"", texts["settings.json"]);
|
|
}
|
|
finally
|
|
{
|
|
environment.DeleteCaptureData();
|
|
}
|
|
}
|
|
|
|
private sealed class OneEncoder : IEncoderInventory
|
|
{
|
|
public string? Adapter() => "Test adapter";
|
|
|
|
public IReadOnlyList<EncoderRow> Detect() =>
|
|
[new EncoderRow("H.264", "Test encoder", null, EncoderSource.MediaFoundation, true, false, 4096, 2304, VideoCodec.H264)];
|
|
|
|
public Task<SelfTestResult> SelfTestAsync(EncoderRow row, CancellationToken ct) => Task.FromResult(new SelfTestResult(true, 100, null));
|
|
}
|
|
|
|
private sealed class NoDialogs : IAppDialogs
|
|
{
|
|
public string? PickFolder(string title, string? initialFolder = null) => null;
|
|
public string? PickJsonFile(string title) => null;
|
|
public bool Confirm(ConfirmRequest request) => false;
|
|
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
|
|
}
|
|
}
|