small QoL improvements
This commit is contained in:
parent
bacca3f890
commit
eb05233f36
|
|
@ -110,19 +110,31 @@ public class HttpEndpointSecurityAndEdgeCasesTests(App app) : AppComponentTest(a
|
|||
// Arrange
|
||||
var client = WorkflowServer.CreateHttpWorkflowClient();
|
||||
|
||||
// Act - Test different case variations
|
||||
var response1 = await client.GetAsync("test/basic");
|
||||
var response2 = await client.GetAsync("TEST/BASIC");
|
||||
var response3 = await client.GetAsync("Test/Basic");
|
||||
|
||||
// Assert - Behavior depends on server configuration, but should be consistent
|
||||
// Most web servers are case-insensitive by default
|
||||
if (response1.StatusCode == HttpStatusCode.OK)
|
||||
// Act - Test the original route first to establish baseline
|
||||
var originalResponse = await client.GetAsync("test/basic");
|
||||
|
||||
// Only proceed with case testing if the original route works
|
||||
if (originalResponse.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
// If the original works, case variations should also work (typical behavior)
|
||||
Assert.True(response2.StatusCode == HttpStatusCode.OK || response2.StatusCode == HttpStatusCode.NotFound);
|
||||
Assert.True(response3.StatusCode == HttpStatusCode.OK || response3.StatusCode == HttpStatusCode.NotFound);
|
||||
Assert.Fail("Original route 'test/basic' should work before testing case variations");
|
||||
}
|
||||
|
||||
// Test case variations
|
||||
var uppercaseResponse = await client.GetAsync("TEST/BASIC");
|
||||
var mixedCaseResponse = await client.GetAsync("Test/Basic");
|
||||
|
||||
// Assert - ASP.NET Core routing is case-insensitive by default
|
||||
// Both case variations should work the same as the original
|
||||
Assert.Equal(HttpStatusCode.OK, uppercaseResponse.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, mixedCaseResponse.StatusCode);
|
||||
|
||||
// Verify all responses return the same content
|
||||
var originalContent = await originalResponse.Content.ReadAsStringAsync();
|
||||
var uppercaseContent = await uppercaseResponse.Content.ReadAsStringAsync();
|
||||
var mixedCaseContent = await mixedCaseResponse.Content.ReadAsStringAsync();
|
||||
|
||||
Assert.Equal(originalContent, uppercaseContent);
|
||||
Assert.Equal(originalContent, mixedCaseContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using Elsa.Http;
|
|||
using Elsa.Workflows.Activities.Flowchart.Activities;
|
||||
using Elsa.Workflows.Activities.Flowchart.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Endpoint = Elsa.Workflows.Activities.Flowchart.Models.Endpoint;
|
||||
|
||||
namespace Elsa.Workflows.ComponentTests.Scenarios.Activities.Http.Workflows;
|
||||
|
||||
|
|
@ -46,11 +47,9 @@ public class BlockedFileExtensionWorkflow : WorkflowBase
|
|||
Activities = { httpEndpoint, successResponse, errorResponse },
|
||||
Connections =
|
||||
{
|
||||
new Connection(new Elsa.Workflows.Activities.Flowchart.Models.Endpoint(httpEndpoint, "Done"), new Elsa.Workflows.Activities.Flowchart.Models.Endpoint(successResponse)),
|
||||
new Connection(new Elsa.Workflows.Activities.Flowchart.Models.Endpoint(httpEndpoint, "Invalid file extension"), new Elsa.Workflows.Activities.Flowchart.Models.Endpoint(errorResponse))
|
||||
new Connection(new Endpoint(httpEndpoint, "Done"), new Endpoint(successResponse)),
|
||||
new Connection(new Endpoint(httpEndpoint, "Invalid file extension"), new Endpoint(errorResponse))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -40,34 +40,7 @@ public class RouteParametersWorkflow : WorkflowBase
|
|||
{
|
||||
// Proper route data is available
|
||||
userId = routeData.TryGetValue("userid", out var value) ? value.ToString() ?? "unknown" : "unknown";
|
||||
orderId = routeData.TryGetValue("orderid", out var value1) ? value1.ToString() ?? "unknown" : "unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: Extract from HttpContext if route data is not populated
|
||||
try
|
||||
{
|
||||
var httpContext = context.GetRequiredService<Microsoft.AspNetCore.Http.IHttpContextAccessor>().HttpContext;
|
||||
var path = httpContext?.Request?.Path.Value ?? "";
|
||||
|
||||
// Split path and look for the users/{userId}/orders/{orderId} pattern
|
||||
var parts = path.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// Find the users pattern in the path
|
||||
for (int i = 0; i < parts.Length - 3; i++)
|
||||
{
|
||||
if (parts[i] == "users" && i + 2 < parts.Length && parts[i + 2] == "orders" && i + 3 < parts.Length)
|
||||
{
|
||||
userId = Uri.UnescapeDataString(parts[i + 1]);
|
||||
orderId = Uri.UnescapeDataString(parts[i + 3]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep defaults if parsing fails
|
||||
}
|
||||
orderId = routeData.TryGetValue("orderid", out var orderIdValue) ? orderIdValue.ToString() ?? "unknown" : "unknown";
|
||||
}
|
||||
|
||||
return $"UserId: {userId}, OrderId: {orderId}";
|
||||
|
|
@ -78,7 +51,4 @@ public class RouteParametersWorkflow : WorkflowBase
|
|||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue