Skip to content

Commit a214c1b

Browse files
Merge pull request #603 from Sitecore/feature/595-Outdated_link_to_WebPlatformDownload_installer_in_Prerequisites.json_file
Feature/595 outdated link to web platform download installer in prerequisites.json file
2 parents 733c425 + d0cc051 commit a214c1b

File tree

5 files changed

+180
-4
lines changed

5 files changed

+180
-4
lines changed

src/SIM.Sitecore9Installer.Tests/SIM.Sitecore9Installer.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="Validation\Validators\LicenseFileValidatorTests.cs" />
9393
<Compile Include="Validation\Validators\NugetToolPresenceValidatorTests.cs" />
9494
<Compile Include="Validation\Validators\PathExistsValidatorTests.cs" />
95+
<Compile Include="Validation\Validators\PrerequisitesDownloadLinksValidatorTests.cs" />
9596
<Compile Include="Validation\Validators\SolrServiceValidatorTests.cs" />
9697
<Compile Include="Validation\Validators\SqlPefixValidatorTests.cs" />
9798
<Compile Include="Validation\Validators\SqlVersionValidatorTests.cs" />
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using AutoFixture;
4+
using NSubstitute;
5+
using SIM.Sitecore9Installer.Tasks;
6+
using SIM.Sitecore9Installer.Validation;
7+
using SIM.Sitecore9Installer.Validation.Validators;
8+
using Xunit;
9+
10+
namespace SIM.Sitecore9Installer.Tests.Validation.Validators
11+
{
12+
public class PrerequisitesDownloadLinksValidatorTests
13+
{
14+
private const string KnownIssueMessage = "{0}: the '{1}' parameter contains the following link that is not accessible:\n\n{2}\n\nThis behavior looks to be related to the following known issue:\n\n{3}\n\nPlease try to apply the solution mentioned there.";
15+
16+
private const string InvalidLinkMessage = "{0}: the '{1}' parameter contains the following link that is not accessible:\n\n{2}\n\nPlease check the Internet connection and the link accessibility in a browser.\n\nThis behavior may also occur due to similar symptoms described in the following known issue:\n\n{3}";
17+
18+
private const string InvalidValueMessage = "{0}: the '{1}' parameter contains the following invalid value:\n\n{2}\n\nIt should contain download link that starts with '{3}'.";
19+
20+
[Theory]
21+
[InlineData("Prerequisites", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 1, KnownIssueMessage)]
22+
[InlineData("Global", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 0, "")]
23+
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/D/5/E/D5EEF288-A277-45C8-855B-8E2CB7E25B96/x64/msodbcsql.msi", 0, "")]
24+
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/test", 1, InvalidLinkMessage)]
25+
[InlineData("Prerequisites", "SQLODBCDriversx64", "test", 0, "")]
26+
[InlineData("Prerequisites", "DotNetHostingDownload", "https://download.microsoft.com/download/6/E/B/6EBD972D-2E2F-41EB-9668-F73F5FDDC09C/dotnet-hosting-2.1.3-win.exe", 0, "")]
27+
[InlineData("Prerequisites", "DotNetHostingDownload", "test", 1, InvalidValueMessage)]
28+
public void EvaluateTests(string taskName, string paramName, string paramValue, int warningsCount, string message)
29+
{
30+
// Arrange
31+
var fixture = new Fixture();
32+
GlobalParameters globals = new GlobalParameters();
33+
Task prerequisitesTask = Substitute.For<Task>(taskName, fixture.Create<int>(), null, null, new Dictionary<string, string>());
34+
InstallParam downloadLinkParam = new InstallParam(paramName, paramValue, false, InstallParamType.String);
35+
List<InstallParam> paramList = new List<InstallParam>
36+
{
37+
downloadLinkParam
38+
};
39+
LocalParameters locals = new LocalParameters(paramList, globals);
40+
prerequisitesTask.LocalParams.Returns(locals);
41+
42+
PrerequisitesDownloadLinksValidator validator = Substitute.ForPartsOf<PrerequisitesDownloadLinksValidator>();
43+
validator.Data["ParamNamePostfix"] = "Download";
44+
validator.Data["ParamValuePrefixes"] = "http://|https://";
45+
List<string> paramValuePrefixes = validator.Data["ParamValuePrefixes"].Split('|').ToList();
46+
47+
// Act
48+
IEnumerable<ValidationResult> result = validator.Evaluate(new Task[] {prerequisitesTask});
49+
IEnumerable<ValidationResult> warnings = result.Where(r => r.State == ValidatorState.Warning);
50+
51+
// Assert
52+
Assert.Equal(warnings.Count(), warningsCount);
53+
if (message == KnownIssueMessage || message == InvalidLinkMessage)
54+
{
55+
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, validator.KnownIssueLink);
56+
}
57+
else
58+
{
59+
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, string.Join("' or '", paramValuePrefixes));
60+
}
61+
}
62+
63+
private void ValidateMessage(IEnumerable<ValidationResult> warnings, string message, string taskName, string paramName, string paramValue, string paramChangeable)
64+
{
65+
if (!string.IsNullOrEmpty(message))
66+
{
67+
message = string.Format(message, taskName, paramName, paramValue, paramChangeable);
68+
Assert.Contains(warnings, warning => warning.Message.Equals(message));
69+
}
70+
}
71+
}
72+
}

src/SIM.Sitecore9Installer/SIM.Sitecore9Installer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
<Compile Include="Validation\Validators\AppPoolSiteValidator.cs" />
129129
<Compile Include="Validation\Validators\CmDdsPatchSiteNameValidator.cs" />
130130
<Compile Include="Validation\Validators\PathExistsValidator.cs" />
131+
<Compile Include="Validation\Validators\PrerequisitesDownloadLinksValidator.cs" />
131132
<Compile Include="Validation\Validators\SolrVersionValidator.cs" />
132133
<Compile Include="Validation\Validators\SolrServiceValidator.cs" />
133134
<Compile Include="Validation\Validators\SqlPefixValidator.cs" />
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net.Http;
5+
using SIM.Sitecore9Installer.Tasks;
6+
7+
namespace SIM.Sitecore9Installer.Validation.Validators
8+
{
9+
public class PrerequisitesDownloadLinksValidator : BaseValidator
10+
{
11+
public override string SuccessMessage => "Prerequisites download links are valid.";
12+
13+
protected virtual string TaskName => "Prerequisites";
14+
15+
// parameter to validate the following known issue: https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer
16+
public virtual string WebPlatformDownload => "WebPlatformDownload";
17+
18+
public virtual string KnownIssueLink => "https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer";
19+
20+
protected override IEnumerable<ValidationResult> GetErrorsForTask(Task task, IEnumerable<InstallParam> paramsToValidate)
21+
{
22+
string paramNamePostfix = string.Empty;
23+
if (this.Data.ContainsKey("ParamNamePostfix"))
24+
{
25+
paramNamePostfix = this.Data["ParamNamePostfix"];
26+
}
27+
28+
List<string> paramValuePrefixes = new List<string>();
29+
if (this.Data.ContainsKey("ParamValuePrefixes"))
30+
{
31+
paramValuePrefixes = this.Data["ParamValuePrefixes"].Split('|').ToList();
32+
}
33+
34+
if (!string.IsNullOrEmpty(paramNamePostfix) && paramValuePrefixes.Count > 0)
35+
{
36+
if (task.Name.Equals(TaskName, StringComparison.InvariantCultureIgnoreCase))
37+
{
38+
foreach (InstallParam installParam in paramsToValidate)
39+
{
40+
if (paramValuePrefixes.Any(paramValuePrefix => installParam.Value.StartsWith(paramValuePrefix, StringComparison.InvariantCultureIgnoreCase)))
41+
{
42+
if (!this.IsDownloadLinkValid(installParam.Value))
43+
{
44+
if (installParam.Name == this.WebPlatformDownload)
45+
{
46+
yield return new ValidationResult(ValidatorState.Warning,
47+
$"{TaskName}: the '{installParam.Name}' parameter contains the following link that is not accessible:\n\n{installParam.Value}\n\nThis behavior looks to be related to the following known issue:\n\n{KnownIssueLink}\n\nPlease try to apply the solution mentioned there.",
48+
null);
49+
}
50+
else
51+
{
52+
yield return new ValidationResult(ValidatorState.Warning,
53+
$"{TaskName}: the '{installParam.Name}' parameter contains the following link that is not accessible:\n\n{installParam.Value}\n\nPlease check the Internet connection and the link accessibility in a browser.\n\nThis behavior may also occur due to similar symptoms described in the following known issue:\n\n{KnownIssueLink}",
54+
null);
55+
}
56+
}
57+
}
58+
else if (installParam.Name.EndsWith(paramNamePostfix, StringComparison.InvariantCultureIgnoreCase))
59+
{
60+
yield return new ValidationResult(ValidatorState.Warning,
61+
$"{TaskName}: the '{installParam.Name}' parameter contains the following invalid value:\n\n{installParam.Value}\n\nIt should contain download link that starts with '{string.Join("' or '", paramValuePrefixes)}'.",
62+
null);
63+
}
64+
}
65+
}
66+
}
67+
}
68+
69+
private bool IsDownloadLinkValid(string link)
70+
{
71+
using (HttpClient authClient = new HttpClient())
72+
{
73+
try
74+
{
75+
var response = authClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, new Uri(link))).Result;
76+
if (response.IsSuccessStatusCode)
77+
{
78+
return true;
79+
}
80+
}
81+
catch
82+
{
83+
return false;
84+
}
85+
}
86+
87+
return false;
88+
}
89+
}
90+
}

src/SIM.Tool/GlobalParamsConfig/Validators.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@
202202
"Data": {
203203
"LicenseFileVariable": "LicenseFile"
204204
}
205+
},
206+
{
207+
"Name": "PrerequisitesDownloadLinksValidator",
208+
"Type": "SIM.Sitecore9Installer.Validation.Validators.PrerequisitesDownloadLinksValidator",
209+
"Data": {
210+
"ParamNamePostfix": "Download",
211+
"ParamValuePrefixes": "http://|https://"
212+
}
205213
}
206214
],
207215
"ValidatorLists": {
@@ -241,22 +249,26 @@
241249
"Sitecore_9.1": [
242250
"9.1_SqlCompatibilityValidator",
243251
"9.1_SolrVersionValidator",
244-
"CmIdentityServerSiteNameValidator"
252+
"CmIdentityServerSiteNameValidator",
253+
"PrerequisitesDownloadLinksValidator"
245254
],
246255
"Sitecore_9.2": [
247256
"9.2_SqlCompatibilityValidator",
248257
"9.2_SolrVersionValidator",
249-
"CmIdentityServerSiteNameValidator"
258+
"CmIdentityServerSiteNameValidator",
259+
"PrerequisitesDownloadLinksValidator"
250260
],
251261
"Sitecore_9.3": [
252262
"9.3_SqlCompatibilityValidator",
253263
"9.3_SolrVersionValidator",
254-
"CmIdentityServerSiteNameValidator"
264+
"CmIdentityServerSiteNameValidator",
265+
"PrerequisitesDownloadLinksValidator"
255266
],
256267
"Sitecore_10.0": [
257268
"9.3_SqlCompatibilityValidator",
258269
"10.0_SolrVersionValidator",
259-
"CmIdentityServerSiteNameValidator"
270+
"CmIdentityServerSiteNameValidator",
271+
"PrerequisitesDownloadLinksValidator"
260272
]
261273
}
262274
}

0 commit comments

Comments
 (0)