Merge branch 'master' into ds-103-local

This commit is contained in:
Jill Bender 2019-01-17 17:18:18 -08:00 коммит произвёл GitHub
Родитель a95a3f0b21 a663f9943d
Коммит 586476c563
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 39 добавлений и 11 удалений

Просмотреть файл

@ -457,6 +457,21 @@ namespace Services.Test
await Assert.ThrowsAsync<InvalidInputException>(async () => await this.rules.UpsertIfNotDeletedAsync(rule));
}
[Fact, Trait(Constants.TYPE, Constants.UNIT_TEST)]
public void InputValidationPassesWithValidRule()
{
// Arrange
this.ThereAreSomeRulesInStorage();
List<Rule> rulesList = this.GetSampleRulesList();
// Act & Assert
foreach (var rule in rulesList)
{
rule.Validate();
}
}
private void ThereAreNoRulessInStorage()
{
this.rulesMock.Setup(x => x.GetListAsync(null, 0, LIMIT, null, false))
@ -464,6 +479,14 @@ namespace Services.Test
}
private void ThereAreSomeRulesInStorage()
{
var sampleRules = this.GetSampleRulesList();
this.rulesMock.Setup(x => x.GetListAsync(null, 0, LIMIT, null, false))
.ReturnsAsync(sampleRules);
}
private List<Rule> GetSampleRulesList()
{
var sampleConditions = new List<Condition>
{
@ -492,7 +515,7 @@ namespace Services.Test
{
Name = "Sample 1",
Enabled = true,
Description = "Sample description 1",
Description = "Sample description 1 -- Pressure >= 298",
GroupId = "Prototyping devices",
Severity = SeverityType.Critical,
Conditions = sampleConditions,
@ -507,11 +530,22 @@ namespace Services.Test
Severity = SeverityType.Warning,
Conditions = sampleConditions,
Actions = sampleActions
},
new Rule()
{
ETag = "*",
Name = "Sample 3",
Enabled = true,
Calculation = CalculationType.Instant,
Description = "Sample description 2.",
GroupId = "Chillers",
Severity = SeverityType.Warning,
Conditions = sampleConditions,
Actions = sampleActions
}
};
this.rulesMock.Setup(x => x.GetListAsync(null, 0, LIMIT, null, false))
.ReturnsAsync(sampleRules);
return sampleRules;
}
/**

Просмотреть файл

@ -5,14 +5,12 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.Services.Helpers
{
public class InputValidator
{
private const string INVALID_CHARACTER = @"[^A-Za-z0-9:;.,_\-]";
private const string INVALID_CHARACTER = @"[^A-Za-z0-9:;.!,_\-* ]";
// Check illegal characters in input
public static void Validate(string input)
{
input = input.Trim();
if (Regex.IsMatch(input, INVALID_CHARACTER))
if (Regex.IsMatch(input.Trim(), INVALID_CHARACTER))
{
throw new InvalidInputException($"Input '{input}' contains invalid characters.");
}

Просмотреть файл

@ -46,11 +46,7 @@ namespace Microsoft.Azure.IoTSolutions.DeviceTelemetry.Services.Models
public void Validate()
{
InputValidator.Validate(this.ETag);
InputValidator.Validate(this.Id);
InputValidator.Validate(this.Name);
InputValidator.Validate(this.Description);
InputValidator.Validate(this.GroupId);
}
}