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/Authoring/Configs/CorsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public record CorsConfig
/// Policy expressions are allowed.
/// </summary>
[ExpressionAllowed]
public string? TerminateUnmatchedRequest { get; init; }
public bool? TerminateUnmatchedRequest { get; init; }

/// <summary>
/// List of origins allowed to make cross-origin calls to your API.<br/>
Expand Down
62 changes: 62 additions & 0 deletions test/Test.Core/Compiling/CorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,68 @@ public void Inbound(IInboundContext context) {
""",
DisplayName = "Should compile cors policy with expose headers"
)]
[DataRow(
"""
[Document]
public class PolicyDocument : IDocument
{
public void Inbound(IInboundContext context) {
context.Cors(new CorsConfig()
{
AllowedOrigins = ["contoso.com"],
AllowedHeaders = ["accept"],
TerminateUnmatchedRequest = true,
});
}
}
""",
"""
<policies>
<inbound>
<cors terminate-unmatched-request="true">
<allowed-origins>
<origin>contoso.com</origin>
</allowed-origins>
<allowed-headers>
<header>accept</header>
</allowed-headers>
</cors>
</inbound>
</policies>
""",
DisplayName = "Should compile cors policy with terminate unmatched request explicitly enabled"
)]
[DataRow(
"""
[Document]
public class PolicyDocument : IDocument
{
public void Inbound(IInboundContext context) {
context.Cors(new CorsConfig()
{
AllowedOrigins = ["contoso.com"],
AllowedHeaders = ["accept"],
TerminateUnmatchedRequest = false,
});
}
}
""",
"""
<policies>
<inbound>
<cors terminate-unmatched-request="false">
<allowed-origins>
<origin>contoso.com</origin>
</allowed-origins>
<allowed-headers>
<header>accept</header>
</allowed-headers>
</cors>
</inbound>
</policies>
""",
DisplayName = "Should compile cors policy with terminate unmatched request disabled"
)]
public void ShouldCompileCorsPolicy(string code, string expectedXml)
{
code.CompileDocument().Should().BeSuccessful().And.DocumentEquivalentTo(expectedXml);
Expand Down
Loading