fix: handle invalid release API JSON (#280)
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Successful in 17m51s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m25s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 11m28s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Successful in 19m34s
Heimdall Gitea / CI policy (pull_request) Successful in 4s
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Successful in 17m51s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m25s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 11m28s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Successful in 19m34s
Heimdall Gitea / CI policy (pull_request) Successful in 4s
This commit is contained in:
1 parent
7869800ea5
commit
cf017b49da
3 files changed
+107
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Heimdall.Api.Controllers;
|
||||
using Xunit;
|
||||
|
||||
@@ -8,6 +9,60 @@ namespace Heimdall.Web.Tests.Controllers;
|
||||
|
||||
public sealed class UpdatesControllerRetryTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("<html><title>Proxy error</title></html>")]
|
||||
[InlineData("{not-json")]
|
||||
public async Task ReadForgejoReleaseAsync_returns_null_for_non_json_responses(string body)
|
||||
{
|
||||
var result = await ReadReleaseAsync(new StringContent(body, Encoding.UTF8, "text/html"));
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadForgejoReleaseAsync_returns_release_for_valid_json()
|
||||
{
|
||||
var result = await ReadReleaseAsync(new StringContent(
|
||||
"{\"tag_name\":\"v1.2.3\",\"body\":\"notes\"}", Encoding.UTF8, "application/json"));
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("v1.2.3", result.GetType().GetProperty("TagName")?.GetValue(result));
|
||||
Assert.Equal("notes", result.GetType().GetProperty("Body")?.GetValue(result));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadForgejoReleaseAsync_rejects_content_larger_than_limit()
|
||||
{
|
||||
using var content = new StringContent("{}", Encoding.UTF8, "application/json");
|
||||
content.Headers.ContentLength = 1_048_577;
|
||||
|
||||
var result = await ReadReleaseAsync(content);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadForgejoReleaseAsync_rejects_oversized_stream_without_content_length()
|
||||
{
|
||||
using var content = new StringContent(new string(' ', 1_048_577), Encoding.UTF8, "application/json");
|
||||
content.Headers.ContentLength = null;
|
||||
|
||||
var result = await ReadReleaseAsync(content);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
private static async Task<object?> ReadReleaseAsync(HttpContent content)
|
||||
{
|
||||
var method = typeof(UpdatesController).GetMethod("ReadForgejoReleaseAsync",
|
||||
BindingFlags.NonPublic | BindingFlags.Static);
|
||||
Assert.NotNull(method);
|
||||
var task = method.Invoke(null, [content, CancellationToken.None]);
|
||||
Assert.NotNull(task);
|
||||
await (Task)task;
|
||||
return task.GetType().GetProperty("Result")?.GetValue(task);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(HttpStatusCode.RequestTimeout, true)]
|
||||
[InlineData(HttpStatusCode.TooManyRequests, true)]
|
||||
|
||||
Reference in new issue
Block a user