Skip to content

Commit eb91f4f

Browse files
authoredMar 20, 2025··
Make preview check for delivery API content case insensitive. (#18731)

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎src/Umbraco.Cms.Api.Delivery/Services/RequestPreviewService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Http;
1+
using Microsoft.AspNetCore.Http;
22
using Umbraco.Cms.Core.DeliveryApi;
33

44
namespace Umbraco.Cms.Api.Delivery.Services;
@@ -11,5 +11,5 @@ public RequestPreviewService(IHttpContextAccessor httpContextAccessor)
1111
}
1212

1313
/// <inheritdoc />
14-
public bool IsPreview() => GetHeaderValue("Preview") == "true";
14+
public bool IsPreview() => string.Equals(GetHeaderValue("Preview"), "true", StringComparison.OrdinalIgnoreCase);
1515
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Moq;
3+
using NUnit.Framework;
4+
using Umbraco.Cms.Api.Delivery.Services;
5+
6+
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Cms.Api.Delivery.Services;
7+
8+
[TestFixture]
9+
public class RequestPreviewServiceTests
10+
{
11+
[TestCase(null, false)]
12+
[TestCase("", false)]
13+
[TestCase("false", false)]
14+
[TestCase("true", true)]
15+
[TestCase("True", true)]
16+
public void IsPreview_Returns_Expected_Result(string? headerValue, bool expected)
17+
{
18+
var httpContext = new DefaultHttpContext();
19+
httpContext.Request.Headers["Preview"] = headerValue;
20+
21+
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
22+
httpContextAccessorMock
23+
.Setup(x => x.HttpContext)
24+
.Returns(httpContext);
25+
var sut = new RequestPreviewService(httpContextAccessorMock.Object);
26+
27+
var result = sut.IsPreview();
28+
29+
Assert.AreEqual(expected, result);
30+
}
31+
}

0 commit comments

Comments
 (0)
Please sign in to comment.