Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more info when Cloudflare test fails #437

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/LexCore/Auth/LexAuthUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace LexCore.Auth;

public record LexAuthUser
{
//from testing done in November 2023, we started getting errors at 10,225 chars
// from testing done in November 2023, we started getting errors at 10,200 chars. See HeaderTests.CheckCloudflareHeaderSizeLimit.
public const int MaxJwtLength = 9000;
public const int MaxProjectCount = 170;
public static readonly JsonTypeInfo LexAuthUserTypeInfo =
Expand Down
27 changes: 19 additions & 8 deletions backend/Testing/ApiTests/HeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@ public HeaderTests()
[Fact]
public async Task CheckCloudflareHeaderSizeLimit()
{
//from testing done in November 2023, we started getting errors at 10,225 chars
int headerSize = 10210;
/*
From testing done in November 2023, for 300 iterations a header size of:
10,210 failed 7 times
10,200 failed 1 time
10,195 failed 0 times
*/
var headerSize = 10195;
var iterations = 10; // a slightly bigger sample set, so we're more confident that we're in the clear
var failStatusCodes = new List<HttpStatusCode>();
for (var i = 0; i < iterations; i++)
{
var response = await HttpClient.SendAsync(
new HttpRequestMessage(HttpMethod.Get, "https://staging.languagedepot.org/api/healthz")
{
Headers = { { "test", RandomString(headerSize) } }
});

var response = await HttpClient.SendAsync(
new HttpRequestMessage(HttpMethod.Get, "https://staging.languagedepot.org/api/healthz")
{
Headers = { { "test", RandomString(headerSize) } }
});
response.StatusCode.ShouldBe(HttpStatusCode.OK, $"header size: {headerSize}");
if (response.StatusCode != HttpStatusCode.OK) failStatusCodes.Add(response.StatusCode);
}
failStatusCodes.ShouldBeEmpty();
}

private string RandomString(int length)
Expand Down
Loading