Skip to content
Open
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 src/Host/FSH.Starter.Api/appsettings.Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"AllowAll": false,
"AllowedOrigins": [],
"AllowedHeaders": [ "content-type", "authorization" ],
"AllowedMethods": [ "GET", "POST", "PUT", "DELETE" ]
"AllowedMethods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ]
},
"JwtOptions": {
"Issuer": "fsh.local",
Expand Down
2 changes: 1 addition & 1 deletion src/Host/FSH.Starter.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"http://localhost:5174"
],
"AllowedHeaders": [ "content-type", "authorization" ],
"AllowedMethods": [ "GET", "POST", "PUT", "DELETE" ]
"AllowedMethods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ]
},
"JwtOptions": {
"Issuer": "fsh.local",
Expand Down
9 changes: 9 additions & 0 deletions src/Tests/Framework.Tests/Framework.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@
<ProjectReference Include="..\..\BuildingBlocks\Web\Web.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\Host\FSH.Starter.Api\appsettings.json"
Link="HostConfiguration\appsettings.json"
CopyToOutputDirectory="PreserveNewest" />
<None Include="..\..\Host\FSH.Starter.Api\appsettings.Production.json"
Link="HostConfiguration\appsettings.Production.json"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Tests/Framework.Tests/Web/CorsConfigurationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Text.Json;

namespace Framework.Tests.Web;

public sealed class CorsConfigurationTests
{
[Theory]
[InlineData("appsettings.json")]
[InlineData("appsettings.Production.json")]
public void AllowedMethods_Should_IncludePatch_When_RestrictedCorsIsConfigured(string fileName)
{
// Arrange
string path = Path.Combine(AppContext.BaseDirectory, "HostConfiguration", fileName);

// Act
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(path));
JsonElement corsOptions = document.RootElement.GetProperty("CorsOptions");
string[] allowedMethods = corsOptions
.GetProperty("AllowedMethods")
.EnumerateArray()
.Select(method => method.GetString())
.OfType<string>()
.ToArray();

// Assert
corsOptions.GetProperty("AllowAll").GetBoolean().ShouldBeFalse();
allowedMethods.ShouldContain("PATCH");
}
}