fix: full verification against the brief — 137 confirmed findings fixed over six passes #4
No files matched your search
@@ -42,15 +42,16 @@ public static class SequenceEndpoints
|
|||||||
sequences.MapGet("/{id:guid}/analysis/report", ReportAsync).Requires(Permissions.Read);
|
sequences.MapGet("/{id:guid}/analysis/report", ReportAsync).Requires(Permissions.Read);
|
||||||
sequences.MapGet("/{id:guid}/stats", StatsAsync).Requires(Permissions.Read);
|
sequences.MapGet("/{id:guid}/stats", StatsAsync).Requires(Permissions.Read);
|
||||||
sequences.MapGet("/{id:guid}/renders", RendersAsync).Requires(Permissions.Read);
|
sequences.MapGet("/{id:guid}/renders", RendersAsync).Requires(Permissions.Read);
|
||||||
// Renders made on a client, sent on request (BRIEF §14.5); chunks go through /uploads.
|
// Renders made on a client, sent on request (BRIEF §14.5) by the sync of an editor's copy; chunks go through /uploads.
|
||||||
|
// Edit, not Upload: render outputs count against no quota, so an upload-only account cannot add them.
|
||||||
sequences.MapPost("/{id:guid}/renders", async (HttpContext c, Caller caller, Guid id, RenderUploadRequest request, RenderUploads uploads) =>
|
sequences.MapPost("/{id:guid}/renders", async (HttpContext c, Caller caller, Guid id, RenderUploadRequest request, RenderUploads uploads) =>
|
||||||
(await uploads.StartAsync(caller, id, request, c.RequestAborted)).ToResult(c, r => Results.Json(r, ProtocolJson.Default.StartUploadResponse,
|
(await uploads.StartAsync(caller, id, request, c.RequestAborted)).ToResult(c, r => Results.Json(r, ProtocolJson.Default.StartUploadResponse,
|
||||||
statusCode: r.AlreadyExists ? StatusCodes.Status200OK : StatusCodes.Status201Created))).Requires(Permissions.Upload | Permissions.Edit);
|
statusCode: r.AlreadyExists ? StatusCodes.Status200OK : StatusCodes.Status201Created))).Requires(Permissions.Edit);
|
||||||
sequences.MapPost("/{id:guid}/renders/{uploadId:guid}/complete", async (HttpContext c, Caller caller, Guid id, Guid uploadId, RenderUploads uploads,
|
sequences.MapPost("/{id:guid}/renders/{uploadId:guid}/complete", async (HttpContext c, Caller caller, Guid id, Guid uploadId, RenderUploads uploads,
|
||||||
IHostApplicationLifetime lifetime) =>
|
IHostApplicationLifetime lifetime) =>
|
||||||
// The commit runs to the end even if the client disconnects meanwhile.
|
// The commit runs to the end even if the client disconnects meanwhile.
|
||||||
(await uploads.CompleteAsync(caller, id, uploadId, lifetime.ApplicationStopping)).ToResult(c, r => Results.Json(r, ProtocolJson.Default.RenderDto)))
|
(await uploads.CompleteAsync(caller, id, uploadId, lifetime.ApplicationStopping)).ToResult(c, r => Results.Json(r, ProtocolJson.Default.RenderDto)))
|
||||||
.Requires(Permissions.Upload | Permissions.Edit);
|
.Requires(Permissions.Edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<IResult> ListAsync(HttpContext context, TitanoDatabase db, ServerArchive archive, int? year, string? camera, string? status,
|
private static async Task<IResult> ListAsync(HttpContext context, TitanoDatabase db, ServerArchive archive, int? year, string? camera, string? status,
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Http.Features;
|
|
||||||
using Titano.Core.Model;
|
using Titano.Core.Model;
|
||||||
using Titano.Protocol;
|
using Titano.Protocol;
|
||||||
using Titano.Server.Configuration;
|
|
||||||
using Titano.Server.Security;
|
using Titano.Server.Security;
|
||||||
using Titano.Server.Storage;
|
using Titano.Server.Storage;
|
||||||
|
|
||||||
@@ -34,10 +32,12 @@ public static class UploadEndpoints
|
|||||||
statusCode: r.AlreadyExists ? StatusCodes.Status200OK : StatusCodes.Status201Created));
|
statusCode: r.AlreadyExists ? StatusCodes.Status200OK : StatusCodes.Status201Created));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<IResult> ChunkAsync(HttpContext context, Caller caller, Guid id, int index, UploadService service, ServerOptions options)
|
/// <summary>
|
||||||
|
/// Chunks are the only large request bodies; every other endpoint keeps Kestrel's small default limit. The service
|
||||||
|
/// raises it to the chunk size of this upload (fixed when it started) before it reads the body.
|
||||||
|
/// </summary>
|
||||||
|
private static async Task<IResult> ChunkAsync(HttpContext context, Caller caller, Guid id, int index, UploadService service)
|
||||||
{
|
{
|
||||||
// Chunks are the only large request bodies; every other endpoint keeps Kestrel's small default limit.
|
|
||||||
if (context.Features.Get<IHttpMaxRequestBodySizeFeature>() is { IsReadOnly: false } limit) limit.MaxRequestBodySize = options.ChunkSizeBytes;
|
|
||||||
var outcome = await service.ReceiveChunkAsync(caller, id, index, context.Request, context.RequestAborted);
|
var outcome = await service.ReceiveChunkAsync(caller, id, index, context.Request, context.RequestAborted);
|
||||||
return outcome.ToResult(context, r => Results.Json(r, ProtocolJson.Default.ChunkReceived));
|
return outcome.ToResult(context, r => Results.Json(r, ProtocolJson.Default.ChunkReceived));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Titano.Data;
|
using Titano.Data;
|
||||||
using Titano.Data.Archiving;
|
using Titano.Data.Archiving;
|
||||||
using Titano.Data.Repositories;
|
using Titano.Data.Repositories;
|
||||||
@@ -97,6 +98,8 @@ public sealed class UploadService(
|
|||||||
var expected = Math.Min(upload.ChunkSize, upload.Size - (long)index * upload.ChunkSize);
|
var expected = Math.Min(upload.ChunkSize, upload.Size - (long)index * upload.ChunkSize);
|
||||||
if (request.ContentLength is { } announced && announced != expected) return Fail<ChunkReceived>(400, "chunk_size", expected.ToString(CultureInfo.InvariantCulture));
|
if (request.ContentLength is { } announced && announced != expected) return Fail<ChunkReceived>(400, "chunk_size", expected.ToString(CultureInfo.InvariantCulture));
|
||||||
if (upload.HasChunk(index)) return new ChunkReceived(index, UploadRules.ReceivedChunks(upload));
|
if (upload.HasChunk(index)) return new ChunkReceived(index, UploadRules.ReceivedChunks(upload));
|
||||||
|
// The upload keeps the chunk size it started with: a smaller setting since a restart must not refuse its chunks (413).
|
||||||
|
if (request.HttpContext.Features.Get<IHttpMaxRequestBodySizeFeature>() is { IsReadOnly: false } limit) limit.MaxRequestBodySize = upload.ChunkSize;
|
||||||
|
|
||||||
if (_chunksInFlight.AddOrUpdate(caller.Id, 1, (_, n) => n + 1) > options.ConcurrentChunksPerUser)
|
if (_chunksInFlight.AddOrUpdate(caller.Id, 1, (_, n) => n + 1) > options.ConcurrentChunksPerUser)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -96,6 +96,55 @@ public sealed class UploadTests(TestContext context)
|
|||||||
Assert.Equal(frame.FrameId, again.FrameId);
|
Assert.Equal(frame.FrameId, again.FrameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task AnUploadKeepsItsChunkSizeWhenTheSettingShrinks()
|
||||||
|
{
|
||||||
|
await using var server = await TestServer.StartAsync(context, o => o.ChunkSizeBytes = Chunk * 2);
|
||||||
|
var (uploader, _, _) = await server.UserAsync("roof-cam", "uploader");
|
||||||
|
var data = Uploads.Photo(Chunk * 3, 14);
|
||||||
|
var start = await Uploads.StartAsync(uploader, data);
|
||||||
|
var id = Assert.NotNull(start.UploadId);
|
||||||
|
Assert.Equal(Chunk * 2, start.ChunkSize);
|
||||||
|
|
||||||
|
// An administrator lowers the chunk size; the upload resumes with the size it started with.
|
||||||
|
server.Options.ChunkSizeBytes = Chunk;
|
||||||
|
var resumed = await Uploads.StartAsync(uploader, data);
|
||||||
|
Assert.Equal((id, Chunk * 2), (resumed.UploadId!.Value, resumed.ChunkSize));
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
using var put = await Uploads.PutChunkAsync(uploader, id, i, Uploads.Chunk(data, Chunk * 2, i));
|
||||||
|
await put.ExpectAsync(HttpStatusCode.OK);
|
||||||
|
}
|
||||||
|
using var complete = await uploader.PostAsync($"/api/v1/uploads/{id}/complete", null);
|
||||||
|
await complete.ExpectAsync(HttpStatusCode.OK);
|
||||||
|
|
||||||
|
// A new upload takes the new size, and a body above it is refused.
|
||||||
|
var next = Uploads.Photo(Chunk * 2, 15);
|
||||||
|
var small = await Uploads.StartAsync(uploader, next);
|
||||||
|
Assert.Equal(Chunk, small.ChunkSize);
|
||||||
|
using var oversized = await Uploads.PutChunkAsync(uploader, small.UploadId!.Value, 0, next);
|
||||||
|
await oversized.ExpectErrorAsync(HttpStatusCode.BadRequest, "chunk_size");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task RenderUploadsNeedTheEditPermission()
|
||||||
|
{
|
||||||
|
await using var server = await TestServer.StartAsync(context, o => o.ChunkSizeBytes = Chunk);
|
||||||
|
var (uploader, _, _) = await server.UserAsync("roof-cam", "uploader");
|
||||||
|
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||||
|
var frame = await Uploads.UploadAsync(uploader, Uploads.Photo(5000, 16), sessionKey: "roof");
|
||||||
|
var output = Uploads.Photo(3000, 17);
|
||||||
|
var request = new RenderUploadRequest(Guid.CreateVersion7(), "Roof.mp4", output.Length, Uploads.Sha(output), "4K HEVC", "hevc", 3840, 2160, 30, 10, null);
|
||||||
|
|
||||||
|
// Render outputs count against no quota: an upload-only account cannot add them to any sequence.
|
||||||
|
using (var refused = await uploader.PostAsJsonAsync($"/api/v1/sequences/{frame.SequenceId}/renders", request, ProtocolJson.Default.RenderUploadRequest))
|
||||||
|
await refused.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
|
||||||
|
using (var complete = await uploader.PostAsync($"/api/v1/sequences/{frame.SequenceId}/renders/{Guid.CreateVersion7()}/complete", null))
|
||||||
|
await complete.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
|
||||||
|
using var accepted = await editor.PostAsJsonAsync($"/api/v1/sequences/{frame.SequenceId}/renders", request, ProtocolJson.Default.RenderUploadRequest);
|
||||||
|
await accepted.ExpectAsync(HttpStatusCode.Created);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TheProtocolClientUploadsAndDownloadsLikeTheUploader()
|
public async Task TheProtocolClientUploadsAndDownloadsLikeTheUploader()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user