Skip to content

Commit 65c0039

Browse files
authored
Merge pull request #11779 from umbraco/v9/feature/AB15639-umbracoApplicationUrl-healthcheck
V9: Add a health check for umbraco application url
2 parents 0ba51f8 + cc8ea0e commit 65c0039

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

src/Umbraco.Core/Constants-HealthChecks.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Umbraco.Cms.Core
1+
namespace Umbraco.Cms.Core
22
{
33
/// <summary>
44
/// Defines constants.
@@ -20,15 +20,16 @@ public static class LiveEnvironment
2020

2121
public const string CompilationDebugCheck = "https://umbra.co/healthchecks-compilation-debug";
2222
}
23+
2324
public static class Configuration
2425
{
2526
public const string MacroErrorsCheck = "https://umbra.co/healthchecks-macro-errors";
2627
public const string TrySkipIisCustomErrorsCheck = "https://umbra.co/healthchecks-skip-iis-custom-errors";
2728
public const string NotificationEmailCheck = "https://umbra.co/healthchecks-notification-email";
2829
}
30+
2931
public static class FolderAndFilePermissionsCheck
3032
{
31-
3233
public const string FileWriting = "https://umbra.co/healthchecks-file-writing";
3334
public const string FolderCreation = "https://umbra.co/healthchecks-folder-creation";
3435
public const string FileWritingForPackages = "https://umbra.co/healthchecks-file-writing-for-packages";
@@ -37,7 +38,7 @@ public static class FolderAndFilePermissionsCheck
3738

3839
public static class Security
3940
{
40-
41+
public const string UmbracoApplicationUrlCheck = "https://umbra.co/healthchecks-umbraco-application-url";
4142
public const string ClickJackingCheck = "https://umbra.co/healthchecks-click-jacking";
4243
public const string HstsCheck = "https://umbra.co/healthchecks-hsts";
4344
public const string NoSniffCheck = "https://umbra.co/healthchecks-no-sniff";
@@ -46,7 +47,6 @@ public static class Security
4647

4748
public static class HttpsCheck
4849
{
49-
5050
public const string CheckIfCurrentSchemeIsHttps = "https://umbra.co/healthchecks-https-request";
5151
public const string CheckHttpsConfigurationSetting = "https://umbra.co/healthchecks-https-config";
5252
public const string CheckForValidCertificate = "https://umbra.co/healthchecks-valid-certificate";
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Umbraco.
2+
// See LICENSE for more details.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Microsoft.Extensions.Options;
8+
using Umbraco.Cms.Core.Configuration.Models;
9+
using Umbraco.Cms.Core.Services;
10+
using Umbraco.Extensions;
11+
12+
namespace Umbraco.Cms.Core.HealthChecks.Checks.Security
13+
{
14+
[HealthCheck(
15+
"6708CA45-E96E-40B8-A40A-0607C1CA7F28",
16+
"Application URL Configuration",
17+
Description = "Checks if the Umbraco application URL is configured for your site.",
18+
Group = "Security")]
19+
public class UmbracoApplicationUrlCheck : HealthCheck
20+
{
21+
private readonly ILocalizedTextService _textService;
22+
private readonly IOptionsMonitor<WebRoutingSettings> _webRoutingSettings;
23+
24+
public UmbracoApplicationUrlCheck(ILocalizedTextService textService, IOptionsMonitor<WebRoutingSettings> webRoutingSettings)
25+
{
26+
_textService = textService;
27+
_webRoutingSettings = webRoutingSettings;
28+
}
29+
30+
/// <summary>
31+
/// Executes the action and returns its status
32+
/// </summary>
33+
public override HealthCheckStatus ExecuteAction(HealthCheckAction action) => throw new InvalidOperationException("UmbracoApplicationUrlCheck has no executable actions");
34+
35+
/// <summary>
36+
/// Get the status for this health check
37+
/// </summary>
38+
public override Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
39+
Task.FromResult(CheckUmbracoApplicationUrl().Yield());
40+
41+
private HealthCheckStatus CheckUmbracoApplicationUrl()
42+
{
43+
var url = _webRoutingSettings.CurrentValue.UmbracoApplicationUrl;
44+
45+
string resultMessage;
46+
StatusResultType resultType;
47+
var success = false;
48+
49+
if (url.IsNullOrWhiteSpace())
50+
{
51+
resultMessage = _textService.Localize("healthcheck", "umbracoApplicationUrlCheckResultFalse");
52+
resultType = StatusResultType.Warning;
53+
}
54+
else
55+
{
56+
resultMessage = _textService.Localize("healthcheck", "umbracoApplicationUrlCheckResultTrue", new[] { url });
57+
resultType = StatusResultType.Success;
58+
success = true;
59+
}
60+
61+
return new HealthCheckStatus(resultMessage)
62+
{
63+
ResultType = resultType,
64+
ReadMoreLink = success ? null : Constants.HealthChecks.DocumentationLinks.Security.UmbracoApplicationUrlCheck
65+
};
66+
}
67+
}
68+
}

src/Umbraco.Web.UI/umbraco/config/lang/en.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,8 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
22902290
<!-- The following keys get these tokens passed in:
22912291
0: Comma delimitted list of failed folder paths
22922292
-->
2293+
<key alias="umbracoApplicationUrlCheckResultTrue"><![CDATA[The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is set to <strong>%0%</strong>.]]></key>
2294+
<key alias="umbracoApplicationUrlCheckResultFalse">The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is not set.</key>
22932295
<key alias="clickJackingCheckHeaderFound">
22942296
<![CDATA[The header or meta-tag <strong>X-Frame-Options</strong> used to control whether a site can be IFRAMEd by another was found.]]></key>
22952297
<key alias="clickJackingCheckHeaderNotFound">

src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,8 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
23722372
<!-- The following keys get these tokens passed in:
23732373
0: Comma delimitted list of failed folder paths
23742374
-->
2375+
<key alias="umbracoApplicationUrlCheckResultTrue"><![CDATA[The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is set to <strong>%0%</strong>.]]></key>
2376+
<key alias="umbracoApplicationUrlCheckResultFalse">The appSetting 'Umbraco:CMS:WebRouting:UmbracoApplicationUrl' is not set.</key>
23752377
<key alias="clickJackingCheckHeaderFound">
23762378
<![CDATA[The header or meta-tag <strong>X-Frame-Options</strong> used to control whether a site can be IFRAMEd by another was found.]]></key>
23772379
<key alias="clickJackingCheckHeaderNotFound">

0 commit comments

Comments
 (0)