-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70bdfd9
commit cebf93b
Showing
13 changed files
with
296 additions
and
149 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
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
24 changes: 24 additions & 0 deletions
24
tests/PSRule.Rules.Azure.Tests/Bicep/ExtensibilityTestCases/BicepExtensibilityTests.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,24 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Newtonsoft.Json.Linq; | ||
|
||
namespace PSRule.Rules.Azure.Bicep.ExtensibilityTestCases; | ||
|
||
public sealed class BicepExtensibilityTests : TemplateVisitorTestsBase | ||
{ | ||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/3062 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenMicrosoftGraphType_ShouldIgnoreExtensibilityResources() | ||
{ | ||
var resources = ProcessTemplate(GetSourcePath("Bicep/ExtensibilityTestCases/Tests.Bicep.1.json"), null, out _); | ||
|
||
Assert.Single(resources); | ||
|
||
var actual = resources[0]; | ||
Assert.Equal("Microsoft.Resources/deployments", actual["type"].Value<string>()); | ||
Assert.Equal("ps-rule-test-deployment", actual["name"].Value<string>()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/PSRule.Rules.Azure.Tests/Bicep/SecretTestCases/BicepSecretTests.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,29 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Linq; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace PSRule.Rules.Azure.Bicep.SecretTestCases; | ||
|
||
public sealed class BicepSecretTests : TemplateVisitorTestsBase | ||
{ | ||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/2054 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenConditionalSecretParameter_ShouldReturnSecretsPlaceholders() | ||
{ | ||
var resources = ProcessTemplate(GetSourcePath("Bicep/SecretTestCases/Tests.Bicep.1.json"), null, out _); | ||
|
||
Assert.NotNull(resources); | ||
|
||
var actual = resources.Where(r => r["name"].Value<string>() == "vault1/toSet1").FirstOrDefault(); | ||
Assert.Equal("Microsoft.KeyVault/vaults/secrets", actual["type"].Value<string>()); | ||
Assert.Equal("{{SecretReference:supersecret1}}", actual["properties"]["value"].Value<string>()); | ||
|
||
actual = resources.Where(r => r["name"].Value<string>() == "vault1/toSet2").FirstOrDefault(); | ||
Assert.Equal("Microsoft.KeyVault/vaults/secrets", actual["type"].Value<string>()); | ||
Assert.Equal("placeholder", actual["properties"]["value"].Value<string>()); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
tests/PSRule.Rules.Azure.Tests/Bicep/SymbolicNameTestCases/BicepSymbolicNameTests.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,80 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Newtonsoft.Json.Linq; | ||
using PSRule.Rules.Azure.Data.Template; | ||
|
||
namespace PSRule.Rules.Azure.Bicep.SymbolicNameTestCases; | ||
|
||
public sealed class BicepSymbolicNameTests : TemplateVisitorTestsBase | ||
{ | ||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/2922 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenReferencesUsed_ReturnsItems() | ||
{ | ||
_ = ProcessTemplate(GetSourcePath("Bicep/SymbolicNameTestCases/Tests.Bicep.1.json"), null, out var templateContext); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("items", out JObject output)); | ||
var items = output["value"].Value<JArray>(); | ||
|
||
Assert.Equal("child-0", items[0].Value<string>()); | ||
Assert.Equal("child-1", items[1].Value<string>()); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("itemsAsString", out output)); | ||
items = output["value"].Value<JArray>(); | ||
|
||
Assert.Equal("child-0", items[0].Value<string>()); | ||
Assert.Equal("child-1", items[1].Value<string>()); | ||
} | ||
|
||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/2917 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenConditionalExistingReference_IgnoresExpand() | ||
{ | ||
var resources = ProcessTemplate(GetSourcePath("Bicep/SymbolicNameTestCases/Tests.Bicep.2.json"), null, out _); | ||
|
||
Assert.Equal(3, resources.Length); | ||
|
||
var actual = resources[0]; | ||
Assert.Equal("Microsoft.Resources/deployments", actual["type"].Value<string>()); | ||
Assert.Equal("ps-rule-test-deployment", actual["name"].Value<string>()); | ||
|
||
actual = resources[1]; | ||
Assert.Equal("Microsoft.Resources/deployments", actual["type"].Value<string>()); | ||
Assert.Equal("child2", actual["name"].Value<string>()); | ||
|
||
actual = resources[2]; | ||
Assert.Equal("Microsoft.Authorization/roleAssignments", actual["type"].Value<string>()); | ||
Assert.Equal("02041802-66a9-0a85-7330-8186e16422c7", actual["name"].Value<string>()); | ||
} | ||
|
||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/3123 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenExistingReferenceNameUsesExpression_ShouldExpandExpression() | ||
{ | ||
_ = ProcessTemplate(GetSourcePath("Bicep/SymbolicNameTestCases/Tests.Bicep.3.json"), null, out _); | ||
} | ||
|
||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/3129 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenExistingReferenceNameUsesExpression_nn() | ||
{ | ||
_ = ProcessTemplate(GetSourcePath("Bicep/SymbolicNameTestCases/Tests.Bicep.4.json"), null, out var templateContext); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("ids", out JObject output)); | ||
var actual = output["value"].Value<JArray>().Values<string>(); | ||
|
||
Assert.Equal([ | ||
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/ps-rule-test-rg/providers/Microsoft.Web/sites/example1-webapp", | ||
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/ps-rule-test-rg/providers/Microsoft.Web/sites/example2-webapp" | ||
], actual); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/PSRule.Rules.Azure.Tests/Bicep/SymbolicNameTestCases/Tests.Bicep.4.bicep
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,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/3129 | ||
// Contributed by @CharlesToniolo | ||
|
||
var names = [ | ||
'example1-webapp' | ||
'example2-webapp' | ||
] | ||
|
||
resource app 'Microsoft.Web/sites@2022-09-01' existing = [ | ||
for name in names: { | ||
name: name | ||
} | ||
] | ||
|
||
output ids array = [for i in range(0, length(names)): app[i].id] |
39 changes: 39 additions & 0 deletions
39
tests/PSRule.Rules.Azure.Tests/Bicep/SymbolicNameTestCases/Tests.Bicep.4.json
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,39 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"languageVersion": "2.0", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.30.23.60470", | ||
"templateHash": "845472047423845594" | ||
} | ||
}, | ||
"variables": { | ||
"names": [ | ||
"example1-webapp", | ||
"example2-webapp" | ||
] | ||
}, | ||
"resources": { | ||
"app": { | ||
"copy": { | ||
"name": "app", | ||
"count": "[length(variables('names'))]" | ||
}, | ||
"existing": true, | ||
"type": "Microsoft.Web/sites", | ||
"apiVersion": "2022-09-01", | ||
"name": "[variables('names')[copyIndex()]]" | ||
} | ||
}, | ||
"outputs": { | ||
"ids": { | ||
"type": "array", | ||
"copy": { | ||
"count": "[length(range(0, length(variables('names'))))]", | ||
"input": "[resourceId('Microsoft.Web/sites', variables('names')[range(0, length(variables('names')))[copyIndex()]])]" | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ule.Rules.Azure.Tests/Bicep/UserDefinedFunctionTestCases/BicepUserDefinedFunctionTests.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,34 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Newtonsoft.Json.Linq; | ||
using PSRule.Rules.Azure.Data.Template; | ||
|
||
namespace PSRule.Rules.Azure.Bicep.UserDefinedFunctionTestCases; | ||
|
||
public sealed class BicepUserDefinedFunctionTests : TemplateVisitorTestsBase | ||
{ | ||
/// <summary> | ||
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/3120 | ||
/// </summary> | ||
[Fact] | ||
public void ProcessTemplate_WhenUserDefinedFunctionReferencesExportedVariables_ShouldFindVariable() | ||
{ | ||
_ = ProcessTemplate(GetSourcePath("Bicep/UserDefinedFunctionTestCases/Tests.Bicep.1.json"), null, out var templateContext); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("o1", out JObject o1)); | ||
Assert.Equal([2], o1["value"].Values<int>()); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("o2", out JObject o2)); | ||
Assert.Equal([1], o2["value"].Values<int>()); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("o3", out JObject o3)); | ||
Assert.Equal([1], o3["value"].Values<int>()); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("o4", out JObject o4)); | ||
Assert.Equal([2, 1], o4["value"].Values<int>()); | ||
|
||
Assert.True(templateContext.RootDeployment.TryOutput("o5", out JObject o5)); | ||
Assert.Equal([3], o5["value"].Values<int>()); | ||
} | ||
} |
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
Oops, something went wrong.