-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from Sitecore/rc/1.11.0
Rc/1.11.0
- Loading branch information
Showing
22 changed files
with
441 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...itecore9Installer.Tests/Validation/Validators/PrerequisitesDownloadLinksValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using AutoFixture; | ||
using NSubstitute; | ||
using SIM.Sitecore9Installer.Tasks; | ||
using SIM.Sitecore9Installer.Validation; | ||
using SIM.Sitecore9Installer.Validation.Validators; | ||
using Xunit; | ||
|
||
namespace SIM.Sitecore9Installer.Tests.Validation.Validators | ||
{ | ||
public class PrerequisitesDownloadLinksValidatorTests | ||
{ | ||
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."; | ||
|
||
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}"; | ||
|
||
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}'."; | ||
|
||
[Theory] | ||
[InlineData("Prerequisites", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 1, KnownIssueMessage)] | ||
[InlineData("Global", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 0, "")] | ||
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/D/5/E/D5EEF288-A277-45C8-855B-8E2CB7E25B96/x64/msodbcsql.msi", 0, "")] | ||
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/test", 1, InvalidLinkMessage)] | ||
[InlineData("Prerequisites", "SQLODBCDriversx64", "test", 0, "")] | ||
[InlineData("Prerequisites", "DotNetHostingDownload", "https://download.microsoft.com/download/6/E/B/6EBD972D-2E2F-41EB-9668-F73F5FDDC09C/dotnet-hosting-2.1.3-win.exe", 0, "")] | ||
[InlineData("Prerequisites", "DotNetHostingDownload", "test", 1, InvalidValueMessage)] | ||
public void EvaluateTests(string taskName, string paramName, string paramValue, int warningsCount, string message) | ||
{ | ||
// Arrange | ||
var fixture = new Fixture(); | ||
GlobalParameters globals = new GlobalParameters(); | ||
Task prerequisitesTask = Substitute.For<Task>(taskName, fixture.Create<int>(), null, null, new Dictionary<string, string>()); | ||
InstallParam downloadLinkParam = new InstallParam(paramName, paramValue, false, InstallParamType.String); | ||
List<InstallParam> paramList = new List<InstallParam> | ||
{ | ||
downloadLinkParam | ||
}; | ||
LocalParameters locals = new LocalParameters(paramList, globals); | ||
prerequisitesTask.LocalParams.Returns(locals); | ||
|
||
PrerequisitesDownloadLinksValidator validator = Substitute.ForPartsOf<PrerequisitesDownloadLinksValidator>(); | ||
validator.Data["ParamNamePostfix"] = "Download"; | ||
validator.Data["ParamValuePrefixes"] = "http://|https://"; | ||
List<string> paramValuePrefixes = validator.Data["ParamValuePrefixes"].Split('|').ToList(); | ||
|
||
// Act | ||
IEnumerable<ValidationResult> result = validator.Evaluate(new Task[] {prerequisitesTask}); | ||
IEnumerable<ValidationResult> warnings = result.Where(r => r.State == ValidatorState.Warning); | ||
|
||
// Assert | ||
Assert.Equal(warnings.Count(), warningsCount); | ||
if (message == KnownIssueMessage || message == InvalidLinkMessage) | ||
{ | ||
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, validator.KnownIssueLink); | ||
} | ||
else | ||
{ | ||
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, string.Join("' or '", paramValuePrefixes)); | ||
} | ||
} | ||
|
||
private void ValidateMessage(IEnumerable<ValidationResult> warnings, string message, string taskName, string paramName, string paramValue, string paramChangeable) | ||
{ | ||
if (!string.IsNullOrEmpty(message)) | ||
{ | ||
message = string.Format(message, taskName, paramName, paramValue, paramChangeable); | ||
Assert.Contains(warnings, warning => warning.Message.Equals(message)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/SIM.Sitecore9Installer/Validation/Validators/PrerequisitesDownloadLinksValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using SIM.Sitecore9Installer.Tasks; | ||
|
||
namespace SIM.Sitecore9Installer.Validation.Validators | ||
{ | ||
public class PrerequisitesDownloadLinksValidator : BaseValidator | ||
{ | ||
public override string SuccessMessage => "Prerequisites download links are valid."; | ||
|
||
protected virtual string TaskName => "Prerequisites"; | ||
|
||
// 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 | ||
public virtual string WebPlatformDownload => "WebPlatformDownload"; | ||
|
||
public virtual string KnownIssueLink => "https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer"; | ||
|
||
protected override IEnumerable<ValidationResult> GetErrorsForTask(Task task, IEnumerable<InstallParam> paramsToValidate) | ||
{ | ||
string paramNamePostfix = string.Empty; | ||
if (this.Data.ContainsKey("ParamNamePostfix")) | ||
{ | ||
paramNamePostfix = this.Data["ParamNamePostfix"]; | ||
} | ||
|
||
List<string> paramValuePrefixes = new List<string>(); | ||
if (this.Data.ContainsKey("ParamValuePrefixes")) | ||
{ | ||
paramValuePrefixes = this.Data["ParamValuePrefixes"].Split('|').ToList(); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(paramNamePostfix) && paramValuePrefixes.Count > 0) | ||
{ | ||
if (task.Name.Equals(TaskName, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
foreach (InstallParam installParam in paramsToValidate) | ||
{ | ||
if (paramValuePrefixes.Any(paramValuePrefix => installParam.Value.StartsWith(paramValuePrefix, StringComparison.InvariantCultureIgnoreCase))) | ||
{ | ||
if (!this.IsDownloadLinkValid(installParam.Value)) | ||
{ | ||
if (installParam.Name == this.WebPlatformDownload) | ||
{ | ||
yield return new ValidationResult(ValidatorState.Warning, | ||
$"{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.", | ||
null); | ||
} | ||
else | ||
{ | ||
yield return new ValidationResult(ValidatorState.Warning, | ||
$"{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}", | ||
null); | ||
} | ||
} | ||
} | ||
else if (installParam.Name.EndsWith(paramNamePostfix, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
yield return new ValidationResult(ValidatorState.Warning, | ||
$"{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)}'.", | ||
null); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private bool IsDownloadLinkValid(string link) | ||
{ | ||
using (HttpClient authClient = new HttpClient()) | ||
{ | ||
try | ||
{ | ||
var response = authClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, new Uri(link))).Result; | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
return true; | ||
} | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/SIM.Tool.Windows/LogFileFolder/LogFileFolderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using SIM.Instances; | ||
|
||
namespace SIM.Tool.Windows.LogFileFolder | ||
{ | ||
public static class LogFileFolderFactory | ||
{ | ||
public static LogFileFolderResolver GetResolver(Instance instance) | ||
{ | ||
if (instance.Type == Instance.InstanceType.SitecoreMember) | ||
{ | ||
return new SitecoreMembersLogFileFolderResolver(instance); | ||
} | ||
|
||
return new SitecoreDefaultLogFileFolderResolver(instance); | ||
} | ||
|
||
public static LogFileFolderResolver GetDefaultResolver(Instance instance) | ||
{ | ||
return new SitecoreDefaultLogFileFolderResolver(instance); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace SIM.Tool.Windows.LogFileFolder | ||
{ | ||
public abstract class LogFileFolderResolver | ||
{ | ||
public abstract string GetLogFolder(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/SIM.Tool.Windows/LogFileFolder/SitecoreDefaultLogFileFolderResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.IO; | ||
using SIM.Extensions; | ||
using SIM.Instances; | ||
|
||
namespace SIM.Tool.Windows.LogFileFolder | ||
{ | ||
public class SitecoreDefaultLogFileFolderResolver : LogFileFolderResolver | ||
{ | ||
private readonly Instance _instance; | ||
|
||
public SitecoreDefaultLogFileFolderResolver(Instance instance) | ||
{ | ||
this._instance = instance; | ||
} | ||
|
||
public override string GetLogFolder() | ||
{ | ||
var dataFolderPath = _instance.DataFolderPath; | ||
|
||
FileSystem.FileSystem.Local.Directory.AssertExists(dataFolderPath, "The data folder ({0}) of the {1} instance doesn't exist".FormatWith(dataFolderPath, _instance.Name)); | ||
|
||
return Path.Combine(dataFolderPath, "logs"); | ||
} | ||
} | ||
} |
Oops, something went wrong.