Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AppInspector.CLI/preferences/tagreportgroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"searchPattern": "^AI\\..*$",
"displayName": "AI",
"detectedIcon": "fa-solid fa-robot"
},
{
"searchPattern": "^WebApp\\.API\\..*$",
"displayName": "Exposed web API",
"detectedIcon": "fas fa-plug"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions AppInspector.RulesEngine/Resources/languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
{
"name": "kotlin",
"extensions": [
".kt",
".kts"
],
"type": "code"
Expand Down
10 changes: 10 additions & 0 deletions AppInspector.Tests/Languages/LanguagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public void DetectLanguageAsFileNameLanguage()
Assert.Equal("package.json", language.Name);
}

[Theory]
[InlineData("Application.kt")]
[InlineData("build.gradle.kts")]
public void DetectKotlinExtensions(string filename)
{
Microsoft.ApplicationInspector.RulesEngine.Languages languages = new(_factory);
Assert.True(languages.FromFileNameOut(filename, out var language));
Assert.Equal("kotlin", language.Name);
}

[InlineData(null, false)] // No way to determine language
[InlineData("", false)] // No way to determine language
[InlineData("validfilename.json", false)] //This test uses the .z test comments and languages from this file.
Expand Down
26 changes: 22 additions & 4 deletions AppInspector.Tests/RuleProcessor/ExpressionGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,28 @@ public class ExpressionGenerationTests
{
private readonly Microsoft.ApplicationInspector.RulesEngine.Languages _languages = new();

private static string GeneratedExpression(int patternClauses, int conditionClauses)
private static string GeneratedExpression(ConvertedOatRule oatRule)
{
var expression = "(" + string.Join(" OR ", Enumerable.Range(0, patternClauses)) + ")";
for (var i = 0; i < conditionClauses; i++) expression += $" AND c{i}";
var patternClauses = oatRule.Clauses.Count(x => x is not WithinClause);
var conditions = oatRule.Clauses.OfType<WithinClause>().ToList();
var patternExpressions = Enumerable.Range(0, patternClauses)
.Select(i =>
{
var expression = i.ToString();
var patternConditions = conditions.Where(x => x.OwnerPatternIndex == i).Select(x => x.Label);
foreach (var label in patternConditions) expression += $" AND {label}";
return expression.Contains(" AND ") ? $"({expression})" : expression;
})
.ToList();

var patternBody = string.Join(" OR ", patternExpressions);
var expression = patternBody.StartsWith('(') ? patternBody : $"({patternBody})";

foreach (var label in conditions.Where(x => x.OwnerPatternIndex is null).Select(x => x.Label))
{
expression += $" AND {label}";
}

return expression;
}

Expand Down Expand Up @@ -47,7 +65,7 @@ public void DefaultRules_GenerateUnchangedExpressions()
// Every shipped pattern must produce a clause, otherwise indices and labels would shift.
Assert.Equal(oatRule.AppInspectorRule.Patterns.Length, patternClauses);

var expected = GeneratedExpression(patternClauses, conditionClauses);
var expected = GeneratedExpression(oatRule);

if (oatRule.Expression != expected)
{
Expand Down
Loading
Loading