refactor(storage): scope exports by owner
CI and Deploy / test (pull_request) Successful in 5m24s
CI and Deploy / deploy (pull_request) Has been skipped

This commit is contained in:
cesnimda
2026-08-15 18:19:59 +02:00
parent 0d487123af
commit cdcc7163fa
17 changed files with 123 additions and 38 deletions
@@ -138,9 +138,11 @@ public sealed class BackgroundWorkerTenantTests
Mock.Of<IStartupReadiness>());
Assert.Equal(new BackgroundWorkerRunResult(true, 2, 2, 0), await worker.RunOnceAsync(default));
var files = Directory.GetFiles(Path.Combine(root, "exports"), "*.json");
var files = Directory.GetFiles(Path.Combine(root, "exports"), "*.json", SearchOption.AllDirectories);
Assert.Equal(2, files.Length);
Assert.DoesNotContain(files, path => path.Contains("user-1", StringComparison.Ordinal) || path.Contains("user-2", StringComparison.Ordinal));
Assert.Equal(2, files.Select(path => Directory.GetParent(path)!.Name).Distinct(StringComparer.Ordinal).Count());
Assert.All(files, path => Assert.Matches("^[0-9a-f]{64}$", Directory.GetParent(path)!.Name));
var owners = new List<string?>();
foreach (var path in files)
{
@@ -159,7 +161,7 @@ public sealed class BackgroundWorkerTenantTests
}
owners.Sort(StringComparer.Ordinal);
Assert.Equal(new[] { "user-1", "user-2" }, owners);
Assert.Empty(Directory.GetFiles(Path.Combine(root, "exports"), "*.tmp"));
Assert.Empty(Directory.GetFiles(Path.Combine(root, "exports"), "*.tmp", SearchOption.AllDirectories));
}
finally
{
@@ -15,11 +15,14 @@ public sealed class CvExportRetentionTests
{
var root = Path.Combine(Path.GetTempPath(), $"jobtracker-export-retention-{Guid.NewGuid():N}");
var exportsRoot = Path.Combine(root, "CvExports");
var old = Path.Combine(exportsRoot, "20260101");
var keep = Path.Combine(exportsRoot, "20260731");
var owner = AppPaths.GetOwnerStorageKey("user-1");
var old = Path.Combine(exportsRoot, owner, "20260101");
var keep = Path.Combine(exportsRoot, owner, "20260731");
var legacyOld = Path.Combine(exportsRoot, "20260101");
var unrelated = Path.Combine(exportsRoot, "manual");
Directory.CreateDirectory(old);
Directory.CreateDirectory(keep);
Directory.CreateDirectory(legacyOld);
Directory.CreateDirectory(unrelated);
try
@@ -34,6 +37,7 @@ public sealed class CvExportRetentionTests
Assert.False(Directory.Exists(old));
Assert.True(Directory.Exists(keep));
Assert.False(Directory.Exists(legacyOld));
Assert.True(Directory.Exists(unrelated));
}
finally
@@ -597,7 +597,7 @@ public sealed class JobApplicationsApplicationPackageTests
{
public TailoredCvRenderResult? LastRenderResult { get; private set; }
public Task<CvPdfArtifact> ExportAsync(TailoredCvRenderResult renderResult, CancellationToken cancellationToken)
public Task<CvPdfArtifact> ExportAsync(string ownerUserId, TailoredCvRenderResult renderResult, CancellationToken cancellationToken)
{
LastRenderResult = renderResult;
return Task.FromResult(new CvPdfArtifact("preview.pdf", "/tmp/preview.pdf", new byte[] { 1, 2, 3 }));
@@ -31,7 +31,7 @@ public sealed class PublicCvControllerTests
variants.Setup(x => x.GetPublicOwnerAsync("public-slug", It.IsAny<CancellationToken>())).ReturnsAsync(user.Id);
variants.Setup(x => x.RenderPublicAsync("public-slug", It.IsAny<CvRenderPerson>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((render, user.Id));
pdf.Setup(x => x.ExportAsync(It.IsAny<TailoredCvRenderResult>(), It.IsAny<CancellationToken>()))
pdf.Setup(x => x.ExportAsync(It.IsAny<string>(), It.IsAny<TailoredCvRenderResult>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new CvPdfArtifact("ada-cv.pdf", "unused", [1, 2, 3]));
var controller = new PublicCvController(TestHostFactory.CreateUserManager(user).Object, variants.Object, pdf.Object);
@@ -42,6 +42,7 @@ public sealed class PublicCvControllerTests
Assert.Equal("ada-cv.pdf", result.FileDownloadName);
Assert.Equal([1, 2, 3], result.FileContents);
pdf.Verify(x => x.ExportAsync(
user.Id,
It.Is<TailoredCvRenderResult>(value => value.TemplateId == "modern" && value.Html == "<html>CV</html>"),
It.IsAny<CancellationToken>()), Times.Once);
}