diff --git a/docs/CHANGELOG-v3.md b/docs/CHANGELOG-v3.md
index 1bb9720560..e7ce3288f7 100644
--- a/docs/CHANGELOG-v3.md
+++ b/docs/CHANGELOG-v3.md
@@ -37,6 +37,9 @@ What's changed since pre-release v3.0.0-B0203:
- The `Execution.Break` option can be set to `Never`, `OnError`, `OnWarning`, or `OnInformation`.
- If a rule fails with a severity level equal or higher than the configured level the pipeline will break.
- General improvements:
+ - **Breaking change**: Improve scope handling for correctly handling cases with multiple module by @BernieWhite.
+ - As a result of this change the `binding` property can no longer be used within baselines.
+ - Use module configuration or workspace options instead.
- Added support for native logging within emitters by @BernieWhite.
[#1837](https://github.com/microsoft/PSRule/issues/1837)
- Engineering:
diff --git a/docs/concepts/PSRule/en-US/about_PSRule_Baseline.md b/docs/concepts/PSRule/en-US/about_PSRule_Baseline.md
index ae4e97347f..266a6dc8d5 100644
--- a/docs/concepts/PSRule/en-US/about_PSRule_Baseline.md
+++ b/docs/concepts/PSRule/en-US/about_PSRule_Baseline.md
@@ -13,13 +13,6 @@ A baseline includes a set of rule and configuration options that are used for ev
The following baseline options can be configured:
-- [Binding.Field](about_PSRule_Options.md#bindingfield)
-- [Binding.IgnoreCase](about_PSRule_Options.md#bindingignorecase)
-- [Binding.NameSeparator](about_PSRule_Options.md#bindingnameseparator)
-- [Binding.PreferTargetInfo](about_PSRule_Options.md#bindingprefertargetinfo)
-- [Binding.TargetName](about_PSRule_Options.md#bindingtargetname)
-- [Binding.TargetType](about_PSRule_Options.md#bindingtargettype)
-- [Binding.UseQualifiedName](about_PSRule_Options.md#bindingusequalifiedname)
- [Configuration](about_PSRule_Options.md#configuration)
- [Rule.Include](about_PSRule_Options.md#ruleinclude)
- [Rule.IncludeLocal](about_PSRule_Options.md#ruleincludelocal)
@@ -55,7 +48,6 @@ metadata:
annotations: { }
spec:
# One or more baseline options
- binding: { }
rule: { }
configuration: { }
```
@@ -70,16 +62,6 @@ kind: Baseline
metadata:
name: Baseline1
spec:
- binding:
- field:
- id:
- - ResourceId
- targetName:
- - Name
- - ResourceName
- - ResourceGroupName
- targetType:
- - ResourceType
rule:
include:
- Rule1
@@ -96,13 +78,6 @@ kind: Baseline
metadata:
name: Baseline2
spec:
- binding:
- targetName:
- - Name
- - ResourceName
- - ResourceGroupName
- targetType:
- - ResourceType
rule:
include:
- Rule1
@@ -125,7 +100,6 @@ To define a JSON baseline spec use the following structure:
"annotations": {}
},
"spec": {
- "binding": {},
"rule": {},
"configuration": {}
}
@@ -145,21 +119,6 @@ For example:
"name": "Baseline1"
},
"spec": {
- "binding": {
- "field": {
- "id": [
- "ResourceId"
- ]
- },
- "targetName": [
- "Name",
- "ResourceName",
- "ResourceGroupName"
- ],
- "targetType": [
- "ResourceType"
- ]
- },
"rule": {
"include": [
"Rule1",
@@ -182,16 +141,6 @@ For example:
"name": "Baseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "Name",
- "ResourceName",
- "ResourceGroupName"
- ],
- "targetType": [
- "ResourceType"
- ]
- },
"rule": {
"include": [
"Rule1",
@@ -276,11 +225,6 @@ kind: Baseline
metadata:
name: TestBaseline1
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - kind
rule:
include:
- 'WithBaseline'
@@ -294,11 +238,6 @@ kind: Baseline
metadata:
name: TestBaseline2
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - kind
rule:
include:
- 'WithBaseline'
@@ -320,14 +259,6 @@ spec:
"name": "TestBaseline1"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "kind"
- ]
- },
"rule": {
"include": [
"WithBaseline"
@@ -346,14 +277,6 @@ spec:
"name": "TestBaseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "kind"
- ]
- },
"rule": {
"include": [
"WithBaseline"
@@ -376,4 +299,3 @@ An online version of this document is available at https://microsoft.github.io/P
- Options
- PSRule
- Baseline
-- Binding
diff --git a/docs/concepts/PSRule/en-US/about_PSRule_Options.md b/docs/concepts/PSRule/en-US/about_PSRule_Options.md
index af6db68f5a..0aabf41c42 100644
--- a/docs/concepts/PSRule/en-US/about_PSRule_Options.md
+++ b/docs/concepts/PSRule/en-US/about_PSRule_Options.md
@@ -14,6 +14,13 @@ This topic describes what options are available, when to and how to use them.
The following workspace options are available for use:
- [Baseline.Group](#baselinegroup)
+- [Binding.Field](#bindingfield)
+- [Binding.IgnoreCase](#bindingignorecase)
+- [Binding.NameSeparator](#bindingnameseparator)
+- [Binding.PreferTargetInfo](#bindingprefertargetinfo)
+- [Binding.TargetName](#bindingtargetname)
+- [Binding.TargetType](#bindingtargettype)
+- [Binding.UseQualifiedName](#bindingusequalifiedname)
- [Convention.Include](#conventioninclude)
- [Execution.AliasReference](#executionaliasreference)
- [Execution.Break](#executionbreak)
@@ -60,13 +67,6 @@ The following workspace options are available for use:
Additionally the following baseline options can be included:
-- [Binding.Field](#bindingfield)
-- [Binding.IgnoreCase](#bindingignorecase)
-- [Binding.NameSeparator](#bindingnameseparator)
-- [Binding.PreferTargetInfo](#bindingprefertargetinfo)
-- [Binding.TargetName](#bindingtargetname)
-- [Binding.TargetType](#bindingtargettype)
-- [Binding.UseQualifiedName](#bindingusequalifiedname)
- [Configuration](#configuration)
- [Rule.Baseline](#rulebaseline)
- [Rule.Include](#ruleinclude)
diff --git a/docs/deprecations.md b/docs/deprecations.md
index a2169559dc..29a35234ad 100644
--- a/docs/deprecations.md
+++ b/docs/deprecations.md
@@ -95,6 +95,17 @@ From _v3_ these properties will be removed.
These changes do not affect normal usage of PSRule.
Supporting scripts that directly use the old names may not work correctly until you update these names.
+### Binding configuration in baselines
+
+Prior to v3, a baseline could configure a binding configuration to modify how objects are recognized by name, type, and scope.
+This existed to support scenarios before a module configuration and language scopes where core to how PSRule operates.
+
+- Rules within a module will automatically use binding configuration from the module configuration.
+ If no binding configuration is set, the configuration of the workspace will be used.
+- Rules within the workspace will automatically use the binding configuration from options (`ps-rule.yaml`).
+
+Configuring binding configuration on a baseline is removed from PSRule v3.
+
## Deprecations for v2
### Default baseline by module manifest
diff --git a/docs/scenarios/baselines/Baseline.rule.yaml b/docs/scenarios/baselines/Baseline.rule.yaml
index 68ee127df9..d4737801fa 100644
--- a/docs/scenarios/baselines/Baseline.rule.yaml
+++ b/docs/scenarios/baselines/Baseline.rule.yaml
@@ -6,11 +6,6 @@ kind: Baseline
metadata:
name: TestBaseline1
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - kind
rule:
include:
- 'WithBaseline'
@@ -24,11 +19,6 @@ kind: Baseline
metadata:
name: TestBaseline2
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - kind
rule:
include:
- 'WithBaseline'
diff --git a/schemas/PSRule-language.schema.json b/schemas/PSRule-language.schema.json
index 314457d697..f839d33d5a 100644
--- a/schemas/PSRule-language.schema.json
+++ b/schemas/PSRule-language.schema.json
@@ -133,9 +133,6 @@
"description": "A specification for a baseline.",
"markdownDescription": "A specification for a baseline. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Baseline/)",
"properties": {
- "binding": {
- "$ref": "#/definitions/binding-option"
- },
"configuration": {
"$ref": "#/definitions/configuration"
},
diff --git a/src/PSRule.Types/Options/BaselineOption.cs b/src/PSRule.Types/Options/BaselineOption.cs
index 3444dd5f9d..a796e89b39 100644
--- a/src/PSRule.Types/Options/BaselineOption.cs
+++ b/src/PSRule.Types/Options/BaselineOption.cs
@@ -6,23 +6,6 @@
namespace PSRule.Options;
-///
-/// Options that configure baselines.
-///
-///
-/// See .
-///
-public interface IBaselineOption : IOption
-{
- ///
- /// A mapping of baseline group names to baselines.
- ///
- ///
- /// See .
- ///
- StringArrayMap? Group { get; }
-}
-
///
/// Options that configure baselines.
///
diff --git a/src/PSRule.Types/Options/IBaselineOption.cs b/src/PSRule.Types/Options/IBaselineOption.cs
new file mode 100644
index 0000000000..cea4b24658
--- /dev/null
+++ b/src/PSRule.Types/Options/IBaselineOption.cs
@@ -0,0 +1,23 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using PSRule.Data;
+
+namespace PSRule.Options;
+
+///
+/// Options that configure baselines.
+///
+///
+/// See .
+///
+public interface IBaselineOption : IOption
+{
+ ///
+ /// A mapping of baseline group names to baselines.
+ ///
+ ///
+ /// See .
+ ///
+ StringArrayMap? Group { get; }
+}
diff --git a/src/PSRule/Common/BaselineJsonSerializationMapper.cs b/src/PSRule/Common/BaselineJsonSerializationMapper.cs
index ba4bdc21d8..d12441baed 100644
--- a/src/PSRule/Common/BaselineJsonSerializationMapper.cs
+++ b/src/PSRule/Common/BaselineJsonSerializationMapper.cs
@@ -47,7 +47,6 @@ private static void MapBaselineSpec(JsonWriter writer, JsonSerializer serializer
MapPropertyName(writer, propertyName);
writer.WriteStartObject();
- MapProperty(writer, serializer, nameof(baselineSpec.Binding), baselineSpec.Binding);
MapProperty(writer, serializer, nameof(baselineSpec.Configuration), baselineSpec.Configuration);
MapProperty(writer, nameof(baselineSpec.Convention), baselineSpec.Convention);
MapProperty(writer, serializer, nameof(baselineSpec.Rule), baselineSpec.Rule);
diff --git a/src/PSRule/Common/BaselineYamlSerializationMapper.cs b/src/PSRule/Common/BaselineYamlSerializationMapper.cs
index aa23557d4e..6e19c27c8b 100644
--- a/src/PSRule/Common/BaselineYamlSerializationMapper.cs
+++ b/src/PSRule/Common/BaselineYamlSerializationMapper.cs
@@ -50,7 +50,6 @@ private static void MapBaselineSpec(IEmitter emitter, string propertyName, Basel
MapPropertyName(emitter, propertyName);
emitter.Emit(new MappingStart());
- MapProperty(emitter, nameof(baselineSpec.Binding), baselineSpec.Binding);
MapProperty(emitter, nameof(baselineSpec.Configuration), baselineSpec.Configuration);
MapProperty(emitter, nameof(baselineSpec.Convention), baselineSpec.Convention);
MapProperty(emitter, nameof(baselineSpec.Rule), baselineSpec.Rule);
diff --git a/src/PSRule/Configuration/BaselineOption.cs b/src/PSRule/Configuration/BaselineOption.cs
index 786cee2cc9..1ca945dc34 100644
--- a/src/PSRule/Configuration/BaselineOption.cs
+++ b/src/PSRule/Configuration/BaselineOption.cs
@@ -26,13 +26,10 @@ internal sealed class BaselineInline : BaselineOption, IBaselineV1Spec
{
public BaselineInline()
{
- Binding = new BindingOption();
Configuration = new ConfigurationOption();
Rule = new RuleOption();
}
- public BindingOption Binding { get; set; }
-
public ConfigurationOption Configuration { get; set; }
public ConventionOption Convention { get; set; }
@@ -87,28 +84,11 @@ public static BaselineOption FromString(string value)
return string.IsNullOrEmpty(value) ? null : new BaselineRef(value);
}
+ ///
+ /// Load from environment variables.
+ ///
internal static void Load(IBaselineV1Spec option)
{
- // Binding.Field - currently not supported
-
- if (Environment.TryBool("PSRULE_BINDING_IGNORECASE", out var ignoreCase))
- option.Binding.IgnoreCase = ignoreCase;
-
- if (Environment.TryString("PSRULE_BINDING_NAMESEPARATOR", out var nameSeparator))
- option.Binding.NameSeparator = nameSeparator;
-
- if (Environment.TryBool("PSRULE_BINDING_PREFERTARGETINFO", out var preferTargetInfo))
- option.Binding.PreferTargetInfo = preferTargetInfo;
-
- if (Environment.TryStringArray("PSRULE_BINDING_TARGETNAME", out var targetName))
- option.Binding.TargetName = targetName;
-
- if (Environment.TryStringArray("PSRULE_BINDING_TARGETTYPE", out var targetType))
- option.Binding.TargetType = targetType;
-
- if (Environment.TryBool("PSRULE_BINDING_USEQUALIFIEDNAME", out var useQualifiedName))
- option.Binding.UseQualifiedName = useQualifiedName;
-
if (Environment.TryString("PSRULE_RULE_BASELINE", out var baseline))
option.Rule.Baseline = baseline;
@@ -128,33 +108,10 @@ internal static void Load(IBaselineV1Spec option)
}
///
- /// Load matching values
+ /// Load from a dictionary.
///
- /// A baseline options object to load.
- /// One or more indexed properties.
internal static void Load(IBaselineV1Spec option, Dictionary properties)
{
- if (properties.TryPopValue("Binding.Field", out Hashtable map))
- option.Binding.Field = new FieldMap(map);
-
- if (properties.TryPopBool("Binding.IgnoreCase", out var ignoreCase))
- option.Binding.IgnoreCase = ignoreCase;
-
- if (properties.TryPopString("Binding.NameSeparator", out var nameSeparator))
- option.Binding.NameSeparator = nameSeparator;
-
- if (properties.TryPopBool("Binding.PreferTargetInfo", out var preferTargetInfo))
- option.Binding.PreferTargetInfo = preferTargetInfo;
-
- if (properties.TryPopStringArray("Binding.TargetName", out var targetName))
- option.Binding.TargetName = targetName;
-
- if (properties.TryPopStringArray("Binding.TargetType", out var targetType))
- option.Binding.TargetType = targetType;
-
- if (properties.TryPopValue("Binding.UseQualifiedName", out bool useQualifiedName))
- option.Binding.UseQualifiedName = useQualifiedName;
-
if (properties.TryPopString("Rule.Baseline", out var baseline))
option.Rule.Baseline = baseline;
diff --git a/src/PSRule/Configuration/BindingOption.cs b/src/PSRule/Configuration/BindingOption.cs
index b721179b62..84fb7a72c6 100644
--- a/src/PSRule/Configuration/BindingOption.cs
+++ b/src/PSRule/Configuration/BindingOption.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
+using System.Collections;
using System.ComponentModel;
namespace PSRule.Configuration;
@@ -8,7 +9,7 @@ namespace PSRule.Configuration;
///
/// Options that affect property binding of TargetName and TargetType.
///
-public sealed class BindingOption : IEquatable
+public sealed class BindingOption : IEquatable, IBindingOption
{
private const bool DEFAULT_IGNORECASE = true;
private const bool DEFAULT_PREFERTARGETINFO = false;
@@ -172,4 +173,57 @@ internal static BindingOption Combine(BindingOption o1, BindingOption o2)
///
[DefaultValue(null)]
public bool? UseQualifiedName { get; set; }
+
+ ///
+ /// Load from environment variables.
+ ///
+ internal void Load()
+ {
+ // Binding.Field - currently not supported
+
+ if (Environment.TryBool("PSRULE_BINDING_IGNORECASE", out var ignoreCase))
+ IgnoreCase = ignoreCase;
+
+ if (Environment.TryString("PSRULE_BINDING_NAMESEPARATOR", out var nameSeparator))
+ NameSeparator = nameSeparator;
+
+ if (Environment.TryBool("PSRULE_BINDING_PREFERTARGETINFO", out var preferTargetInfo))
+ PreferTargetInfo = preferTargetInfo;
+
+ if (Environment.TryStringArray("PSRULE_BINDING_TARGETNAME", out var targetName))
+ TargetName = targetName;
+
+ if (Environment.TryStringArray("PSRULE_BINDING_TARGETTYPE", out var targetType))
+ TargetType = targetType;
+
+ if (Environment.TryBool("PSRULE_BINDING_USEQUALIFIEDNAME", out var useQualifiedName))
+ UseQualifiedName = useQualifiedName;
+ }
+
+ ///
+ /// Load from a dictionary.
+ ///
+ internal void Load(Dictionary index)
+ {
+ if (index.TryPopValue("Binding.Field", out Hashtable map))
+ Field = new FieldMap(map);
+
+ if (index.TryPopBool("Binding.IgnoreCase", out var ignoreCase))
+ IgnoreCase = ignoreCase;
+
+ if (index.TryPopString("Binding.NameSeparator", out var nameSeparator))
+ NameSeparator = nameSeparator;
+
+ if (index.TryPopBool("Binding.PreferTargetInfo", out var preferTargetInfo))
+ PreferTargetInfo = preferTargetInfo;
+
+ if (index.TryPopStringArray("Binding.TargetName", out var targetName))
+ TargetName = targetName;
+
+ if (index.TryPopStringArray("Binding.TargetType", out var targetType))
+ TargetType = targetType;
+
+ if (index.TryPopValue("Binding.UseQualifiedName", out bool useQualifiedName))
+ UseQualifiedName = useQualifiedName;
+ }
}
diff --git a/src/PSRule/Configuration/IBindingOption.cs b/src/PSRule/Configuration/IBindingOption.cs
new file mode 100644
index 0000000000..4591b27ae1
--- /dev/null
+++ b/src/PSRule/Configuration/IBindingOption.cs
@@ -0,0 +1,10 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using PSRule.Options;
+
+namespace PSRule.Configuration;
+
+public interface IBindingOption : IOption
+{
+}
diff --git a/src/PSRule/Configuration/PSRuleOption.cs b/src/PSRule/Configuration/PSRuleOption.cs
index e442dc74b5..e31d962df3 100644
--- a/src/PSRule/Configuration/PSRuleOption.cs
+++ b/src/PSRule/Configuration/PSRuleOption.cs
@@ -6,7 +6,6 @@
using System.Management.Automation;
using Newtonsoft.Json;
using PSRule.Converters.Yaml;
-using PSRule.Definitions;
using PSRule.Definitions.Baselines;
using PSRule.Pipeline;
using PSRule.Resources;
@@ -336,6 +335,7 @@ private static PSRuleOption FromEnvironment(PSRuleOption option)
// Start loading matching values
option.Baseline.Load();
+ option.Binding.Load();
option.Convention.Load();
option.Execution.Load();
option.Include.Load();
@@ -365,6 +365,7 @@ public static PSRuleOption FromHashtable(Hashtable hashtable)
// Start loading matching values
var index = BuildIndex(hashtable);
option.Baseline.Load(index);
+ option.Binding.Load(index);
option.Convention.Load(index);
option.Execution.Load(index);
option.Include.Load(index);
diff --git a/src/PSRule/Definitions/Baselines/BaselineSpec.cs b/src/PSRule/Definitions/Baselines/BaselineSpec.cs
index 2550f3549f..71bb5feb0a 100644
--- a/src/PSRule/Definitions/Baselines/BaselineSpec.cs
+++ b/src/PSRule/Definitions/Baselines/BaselineSpec.cs
@@ -10,9 +10,6 @@ namespace PSRule.Definitions.Baselines;
///
public sealed class BaselineSpec : Spec, IBaselineV1Spec
{
- ///
- public BindingOption Binding { get; set; }
-
///
public ConfigurationOption Configuration { get; set; }
diff --git a/src/PSRule/Definitions/Baselines/IBaselineV1Spec.cs b/src/PSRule/Definitions/Baselines/IBaselineV1Spec.cs
index cf23413366..e14c9a2c94 100644
--- a/src/PSRule/Definitions/Baselines/IBaselineV1Spec.cs
+++ b/src/PSRule/Definitions/Baselines/IBaselineV1Spec.cs
@@ -10,11 +10,6 @@ namespace PSRule.Definitions.Baselines;
///
internal interface IBaselineV1Spec
{
- ///
- /// Options that affect property binding.
- ///
- BindingOption Binding { get; set; }
-
///
/// Allows configuration key/ values to be specified that can be used within rule definitions.
///
diff --git a/src/PSRule/Pipeline/OptionContextBuilder.cs b/src/PSRule/Pipeline/OptionContextBuilder.cs
index cb086c239c..8b26e2495f 100644
--- a/src/PSRule/Pipeline/OptionContextBuilder.cs
+++ b/src/PSRule/Pipeline/OptionContextBuilder.cs
@@ -26,11 +26,11 @@ internal sealed class OptionContextBuilder
internal OptionContextBuilder(string[] include = null, Hashtable tag = null, string[] convention = null)
{
- _ModuleBaselineScope = new Dictionary();
- _Scopes = new List();
+ _ModuleBaselineScope = [];
+ _Scopes = [];
_Comparer = new OptionScopeComparer();
_DefaultCulture = GetDefaultCulture();
- _ConventionOrder = new List();
+ _ConventionOrder = [];
Parameter(include, tag, convention);
}
diff --git a/src/PSRule/Pipeline/OptionScope.cs b/src/PSRule/Pipeline/OptionScope.cs
index 8140081227..2494db4f07 100644
--- a/src/PSRule/Pipeline/OptionScope.cs
+++ b/src/PSRule/Pipeline/OptionScope.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System.Collections;
+using System.Diagnostics;
using PSRule.Configuration;
using PSRule.Definitions;
using PSRule.Definitions.Baselines;
@@ -38,6 +39,7 @@ internal enum ScopeType
Module = 4
}
+[DebuggerDisplay("{Type} - {LanguageScope}")]
internal class OptionScope
{
public readonly ScopeType Type;
@@ -136,7 +138,6 @@ internal static OptionScope FromBaseline(ScopeType type, string baselineId, stri
{
return new OptionScope(type, module)
{
- Binding = spec.Binding,
Configuration = spec.Configuration,
Rule = new RuleOption
{
diff --git a/tests/PSRule.Tests/Baseline.Rule.jsonc b/tests/PSRule.Tests/Baseline.Rule.jsonc
index fcd78fe933..af3a3401cb 100644
--- a/tests/PSRule.Tests/Baseline.Rule.jsonc
+++ b/tests/PSRule.Tests/Baseline.Rule.jsonc
@@ -11,23 +11,6 @@
},
"spec": {
// Additional comment
- "binding": {
- "field": {
- "kind": [
- "kind"
- ],
- "uniqueIdentifer": [
- "Id",
- "AlternateName"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "kind"
- ]
- },
"rule": {
"include": [
// Additional comment
@@ -56,14 +39,6 @@
"name": "TestBaseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "metadata.name"
- ],
- "targetType": [
- "kind"
- ]
- },
"rule": {
"include": [
""
diff --git a/tests/PSRule.Tests/Baseline.Rule.yaml b/tests/PSRule.Tests/Baseline.Rule.yaml
index bff3791677..a31b10d658 100644
--- a/tests/PSRule.Tests/Baseline.Rule.yaml
+++ b/tests/PSRule.Tests/Baseline.Rule.yaml
@@ -9,17 +9,6 @@ metadata:
key: value
spec:
# Additional comment
- binding:
- field:
- kind:
- - kind
- uniqueIdentifer:
- - Id
- - AlternateName
- targetName:
- - AlternateName
- targetType:
- - kind
rule:
include:
# Additional comment
@@ -38,11 +27,6 @@ kind: Baseline
metadata:
name: TestBaseline2
spec:
- binding:
- targetName:
- - metadata.name
- targetType:
- - kind
rule:
include:
- ''
diff --git a/tests/PSRule.Tests/BaselineTests.cs b/tests/PSRule.Tests/BaselineTests.cs
index 989b739db7..87bbfd2ae2 100644
--- a/tests/PSRule.Tests/BaselineTests.cs
+++ b/tests/PSRule.Tests/BaselineTests.cs
@@ -59,10 +59,10 @@ public void ReadBaselineYaml()
// TestBaseline6
Assert.Equal("TestBaseline6", baseline[5].Name);
var labels = baseline[5].Spec.Rule.Labels;
- Assert.True(labels.Contains("framework.v1/control", new string[] { "*" }));
- Assert.True(labels.Contains("framework.v1/control", new string[] { "c-1" }));
- Assert.False(labels.Contains("framework.v1/control", new string[] { "c-3" }));
- Assert.False(labels.Contains("framework.v3/control", new string[] { "*" }));
+ Assert.True(labels.Contains("framework.v1/control", ["*"]));
+ Assert.True(labels.Contains("framework.v1/control", ["c-1"]));
+ Assert.False(labels.Contains("framework.v1/control", ["c-3"]));
+ Assert.False(labels.Contains("framework.v3/control", ["*"]));
}
[Fact]
@@ -100,10 +100,10 @@ public void ReadBaselineJson()
// TestBaseline6
Assert.Equal("TestBaseline6", baseline[5].Name);
var labels = baseline[5].Spec.Rule.Labels;
- Assert.True(labels.Contains("framework.v1/control", new string[] { "*" }));
- Assert.True(labels.Contains("framework.v1/control", new string[] { "c-1" }));
- Assert.False(labels.Contains("framework.v1/control", new string[] { "c-3" }));
- Assert.False(labels.Contains("framework.v3/control", new string[] { "*" }));
+ Assert.True(labels.Contains("framework.v1/control", ["*"]));
+ Assert.True(labels.Contains("framework.v1/control", ["c-1"]));
+ Assert.False(labels.Contains("framework.v1/control", ["c-3"]));
+ Assert.False(labels.Contains("framework.v3/control", ["*"]));
}
[Theory]
@@ -130,7 +130,7 @@ public void FilterBaseline(string path)
var baseline = GetBaselines(GetSource(path));
Assert.NotNull(baseline);
- var filter = new BaselineFilter(new string[] { "TestBaseline5" });
+ var filter = new BaselineFilter(["TestBaseline5"]);
var actual = baseline.FirstOrDefault(b => filter.Match(b));
Assert.Equal("TestBaseline5", actual.Name);
@@ -149,11 +149,6 @@ public void BaselineAsYaml()
Assert.Equal("Baseline", actual[0]["kind"]);
Assert.Equal("TestBaseline1", actual[0]["metadata"]["name"]);
Assert.NotNull(actual[0]["spec"]);
- Assert.Equal("kind", actual[0]["spec"]["binding"]["field"]["kind"][0]);
- Assert.Equal("Id", actual[0]["spec"]["binding"]["field"]["uniqueIdentifer"][0]);
- Assert.Equal("AlternateName", actual[0]["spec"]["binding"]["field"]["uniqueIdentifer"][1]);
- Assert.Equal("AlternateName", actual[0]["spec"]["binding"]["targetName"][0]);
- Assert.Equal("kind", actual[0]["spec"]["binding"]["targetType"][0]);
Assert.Equal("WithBaseline", actual[0]["spec"]["rule"]["include"][0]);
Assert.Equal("value1", actual[0]["spec"]["configuration"]["key1"]);
Assert.Equal("abc", actual[0]["spec"]["configuration"]["key2"][0]["value1"]);
@@ -172,11 +167,6 @@ public void BaselineAsJson()
Assert.Equal("Baseline", actual[0]["kind"]);
Assert.Equal("TestBaseline1", actual[0]["metadata"]["name"]);
Assert.NotNull(actual[0]["spec"]);
- Assert.Equal("kind", actual[0]["spec"]["binding"]["field"]["kind"][0]);
- Assert.Equal("AlternateName", actual[0]["spec"]["binding"]["field"]["uniqueIdentifer"][0]);
- Assert.Equal("Id", actual[0]["spec"]["binding"]["field"]["uniqueIdentifer"][1]);
- Assert.Equal("AlternateName", actual[0]["spec"]["binding"]["targetName"][0]);
- Assert.Equal("kind", actual[0]["spec"]["binding"]["targetType"][0]);
Assert.Equal("WithBaseline", actual[0]["spec"]["rule"]["include"][0]);
Assert.Equal("value1", actual[0]["spec"]["configuration"]["key1"]);
Assert.Equal("abc", actual[0]["spec"]["configuration"]["key2"][0]["value1"]);
@@ -211,10 +201,10 @@ private static Source[] GetSourceInModule(string path, string moduleName, Source
var file = new SourceFile(GetSourcePath(path), moduleName, type, null);
var source = new Source(
module: new Source.ModuleInfo(AppDomain.CurrentDomain.BaseDirectory, moduleName, "1.0.0", null, "4de0fd26-6aae-401f-a943-b49f082f141e", "Microsoft", null),
- file: new SourceFile[] { file },
+ file: [file],
dependency: false
);
- return new Source[] { source };
+ return [source];
}
private static string GetSourcePath(string fileName)
diff --git a/tests/PSRule.Tests/FromFileBaseline.Rule.ps1 b/tests/PSRule.Tests/FromFileBaseline.Rule.ps1
index 3514c3bb1e..71431b823f 100644
--- a/tests/PSRule.Tests/FromFileBaseline.Rule.ps1
+++ b/tests/PSRule.Tests/FromFileBaseline.Rule.ps1
@@ -7,9 +7,7 @@
# Synopsis: Test for baseline
Rule 'WithBaseline' -Tag @{ category = 'group2'; severity = 'high' } {
- $PSRule.TargetName -eq 'TestObject1'
- $PSRule.TargetType -eq 'TestObjectType'
- $PSRule.Field.kind -eq 'TestObjectType'
+ $Configuration.GetStringOrDefault('key1', $Null) -eq 'value1'
} -Labels @{ 'framework.v1/control' = @('c-2') }
# Synopsis: Test for baseline
diff --git a/tests/PSRule.Tests/OptionContextTests.cs b/tests/PSRule.Tests/OptionContextTests.cs
index 7104d4810f..d224ad847c 100644
--- a/tests/PSRule.Tests/OptionContextTests.cs
+++ b/tests/PSRule.Tests/OptionContextTests.cs
@@ -42,22 +42,22 @@ public void Order()
Assert.NotNull(ruleFilter);
Assert.True(ruleFilter.IncludeLocal);
- // With explict baseline
+ // With explicit baseline
builder = new OptionContextBuilder(GetOption());
- builder.Baseline(ScopeType.Explicit, "BaselineExplicit", null, GetBaseline(ruleInclude: new[] { "abc" }), false);
+ builder.Baseline(ScopeType.Explicit, "BaselineExplicit", null, GetBaseline(ruleInclude: ["abc"]), false);
localScope.Configure(builder.Build(localScope.Name));
ruleFilter = localScope.GetFilter(ResourceKind.Rule) as RuleFilter;
Assert.NotNull(ruleFilter);
Assert.False(ruleFilter.IncludeLocal);
// With include from parameters
- builder = new OptionContextBuilder(GetOption(), include: new string[] { "abc" });
+ builder = new OptionContextBuilder(GetOption(), include: ["abc"]);
localScope.Configure(builder.Build(localScope.Name));
ruleFilter = localScope.GetFilter(ResourceKind.Rule) as RuleFilter;
Assert.NotNull(ruleFilter);
Assert.False(ruleFilter.IncludeLocal);
- builder = new OptionContextBuilder(GetOption(ruleInclude: new[] { "abc" }));
+ builder = new OptionContextBuilder(GetOption(ruleInclude: ["abc"]));
localScope.Configure(builder.Build(localScope.Name));
ruleFilter = localScope.GetFilter(ResourceKind.Rule) as RuleFilter;
Assert.NotNull(ruleFilter);
@@ -89,7 +89,7 @@ public void Merge_multiple_options_from_file()
Assert.Equal("value6", option6);
// With module default baseline
- builder.Baseline(ScopeType.Module, "BaselineDefault", "Module1", GetBaseline(targetType: new[] { "defaultType" }, ruleInclude: new[] { "defaultRule" }), false);
+ builder.Baseline(ScopeType.Module, "BaselineDefault", "Module1", GetBaseline(targetType: ["defaultType"], ruleInclude: ["defaultRule"]), false);
context = builder.Build(null);
Assert.Equal(new[] { "ResourceName", "AlternateName" }, context.Binding.TargetName);
@@ -102,18 +102,18 @@ public void Merge_multiple_options_from_file()
Assert.Equal(new[] { "ResourceType", "kind" }, context.Binding.TargetType);
Assert.Equal(new[] { "rule1", "rule2" }, context.Rule.Include);
- // With explict baseline
+ // With explicit baseline
builder.Baseline(ScopeType.Explicit, "BaselineExplicit", "Module1", GetBaseline(), false);
context = builder.Build(null);
Assert.Equal(new[] { "ResourceName", "AlternateName" }, context.Binding.TargetName);
- Assert.Equal(new[] { "typeName" }, context.Binding.TargetType);
+ Assert.Equal(new[] { "ResourceType", "kind" }, context.Binding.TargetType);
Assert.Equal(new[] { "rule1" }, context.Rule.Include);
context = builder.Build("Module1");
Assert.Equal(new[] { "ResourceName", "AlternateName" }, context.Binding.TargetName);
- Assert.Equal(new[] { "typeName" }, context.Binding.TargetType);
+ Assert.Equal(new[] { "ResourceType", "kind" }, context.Binding.TargetType);
Assert.Equal(new[] { "rule1" }, context.Rule.Include);
}
@@ -124,7 +124,7 @@ private static PSRuleOption GetOption(string[] culture = null, string[] ruleIncl
var option = new PSRuleOption();
// Specify a culture otherwise it varies within CI.
- option.Output.Culture = culture ?? new string[] { "en-ZZ" };
+ option.Output.Culture = culture ?? ["en-ZZ"];
option.Rule.Include = ruleInclude;
@@ -141,14 +141,9 @@ private static PSRuleOption GetOptionFromFile(string file = "PSRule.Tests.yml")
private static BaselineSpec GetBaseline(string[] targetType = null, string[] ruleInclude = null)
{
- targetType ??= new[] { "typeName" };
- ruleInclude ??= new[] { "rule1" };
+ ruleInclude ??= ["rule1"];
return new BaselineSpec
{
- Binding = new BindingOption
- {
- TargetType = targetType
- },
Rule = new RuleOption
{
Include = ruleInclude
diff --git a/tests/PSRule.Tests/Output.Baseline.0.jsonc b/tests/PSRule.Tests/Output.Baseline.0.jsonc
index a4a68ac5b0..ed4e03994a 100644
--- a/tests/PSRule.Tests/Output.Baseline.0.jsonc
+++ b/tests/PSRule.Tests/Output.Baseline.0.jsonc
@@ -1,9 +1,9 @@
[{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Module4"},"spec":{"binding":{"field":{"kind":["Id"],"uniqueIdentifer":["AlternateName","Id"]},"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig1":"Test"},"rule":{"include":["M4.Rule1"]}}},{
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Module4"},"spec":{"configuration":{"ruleConfig1":"Test"},"rule":{"include":["M4.Rule1"]}}},{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Module4a"},"spec":{"binding":{"field":{"kind":["Id"],"uniqueIdentifer":["AlternateName","Id"]},"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig1":"Test2"},"rule":{"include":["M4.Rule1"]}}},{
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Module4a"},"spec":{"configuration":{"ruleConfig1":"Test2"},"rule":{"include":["M4.Rule1"]}}},{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline2"},"spec":{"binding":{"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}},{
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline2"},"spec":{"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}},{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline3"},"spec":{"binding":{"field":{"alternativeType":["AlternateName"]},"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}}]
\ No newline at end of file
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline3"},"spec":{"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}}]
\ No newline at end of file
diff --git a/tests/PSRule.Tests/Output.Baseline.2.jsonc b/tests/PSRule.Tests/Output.Baseline.2.jsonc
index 41450f3c1f..8d499d6867 100644
--- a/tests/PSRule.Tests/Output.Baseline.2.jsonc
+++ b/tests/PSRule.Tests/Output.Baseline.2.jsonc
@@ -7,23 +7,6 @@
"name": "Module4"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test"
},
@@ -42,23 +25,6 @@
"name": "Module4a"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test2"
},
@@ -77,14 +43,6 @@
"name": "Baseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -103,19 +61,6 @@
"name": "Baseline3"
},
"spec": {
- "binding": {
- "field": {
- "alternativeType": [
- "AlternateName"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
diff --git a/tests/PSRule.Tests/Output.Baseline.4.jsonc b/tests/PSRule.Tests/Output.Baseline.4.jsonc
index 0207ba3335..d55ff94152 100644
--- a/tests/PSRule.Tests/Output.Baseline.4.jsonc
+++ b/tests/PSRule.Tests/Output.Baseline.4.jsonc
@@ -7,23 +7,6 @@
"name": "Module4"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test"
},
@@ -42,23 +25,6 @@
"name": "Module4a"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test2"
},
@@ -77,14 +43,6 @@
"name": "Baseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -103,19 +61,6 @@
"name": "Baseline3"
},
"spec": {
- "binding": {
- "field": {
- "alternativeType": [
- "AlternateName"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
diff --git a/tests/PSRule.Tests/Output.Baseline.yaml b/tests/PSRule.Tests/Output.Baseline.yaml
index 83ffdc7b77..0274a0383a 100644
--- a/tests/PSRule.Tests/Output.Baseline.yaml
+++ b/tests/PSRule.Tests/Output.Baseline.yaml
@@ -4,17 +4,6 @@ kind: Baseline
metadata:
name: Module4
spec:
- binding:
- field:
- kind:
- - Id
- uniqueIdentifer:
- - AlternateName
- - Id
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig1: Test
rule:
@@ -27,17 +16,6 @@ kind: Baseline
metadata:
name: Module4a
spec:
- binding:
- field:
- kind:
- - Id
- uniqueIdentifer:
- - AlternateName
- - Id
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig1: Test2
rule:
@@ -50,11 +28,6 @@ kind: Baseline
metadata:
name: Baseline2
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig2: Test3
rule:
@@ -67,14 +40,6 @@ kind: Baseline
metadata:
name: Baseline3
spec:
- binding:
- field:
- alternativeType:
- - AlternateName
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig2: Test3
rule:
diff --git a/tests/PSRule.Tests/PSRule.Baseline.Tests.ps1 b/tests/PSRule.Tests/PSRule.Baseline.Tests.ps1
index 83a4d7d342..ffeb6984c3 100644
--- a/tests/PSRule.Tests/PSRule.Baseline.Tests.ps1
+++ b/tests/PSRule.Tests/PSRule.Baseline.Tests.ps1
@@ -47,17 +47,6 @@ kind: Baseline
metadata:
name: Module4
spec:
- binding:
- field:
- kind:
- - Id
- uniqueIdentifer:
- - AlternateName
- - Id
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig1: Test
rule:
@@ -71,17 +60,6 @@ kind: Baseline
metadata:
name: Module4a
spec:
- binding:
- field:
- kind:
- - Id
- uniqueIdentifer:
- - AlternateName
- - Id
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig1: Test2
rule:
@@ -95,11 +73,6 @@ kind: Baseline
metadata:
name: Baseline2
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig2: Test3
rule:
@@ -113,14 +86,6 @@ kind: Baseline
metadata:
name: Baseline3
spec:
- binding:
- field:
- alternativeType:
- - AlternateName
- targetName:
- - AlternateName
- targetType:
- - Kind
configuration:
ruleConfig2: Test3
rule:
@@ -139,23 +104,6 @@ spec:
"name": "Module4"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test"
},
@@ -178,14 +126,6 @@ spec:
"name": "Baseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -208,19 +148,6 @@ spec:
"name": "Baseline3"
},
"spec": {
- "binding": {
- "field": {
- "alternativeType": [
- "AlternateName"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -244,23 +171,6 @@ $baselineTwoSpaceJsonTestCases = @(
"name": "Module4"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test"
},
@@ -283,14 +193,6 @@ $baselineTwoSpaceJsonTestCases = @(
"name": "Baseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -313,19 +215,6 @@ $baselineTwoSpaceJsonTestCases = @(
"name": "Baseline3"
},
"spec": {
- "binding": {
- "field": {
- "alternativeType": [
- "AlternateName"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -342,17 +231,17 @@ $baselineZeroSpaceJsonTestCases = @(
@{Baseline = 'Module4'; ExpectedJson = @"
[{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Module4"},"spec":{"binding":{"field":{"kind":["Id"],"uniqueIdentifer":["AlternateName","Id"]},"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig1":"Test"},"rule":{"include":["M4.Rule1"]}}}]
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Module4"},"spec":{"configuration":{"ruleConfig1":"Test"},"rule":{"include":["M4.Rule1"]}}}]
"@}
@{Baseline = 'Baseline2'; ExpectedJson = @"
[{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline2"},"spec":{"binding":{"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}}]
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline2"},"spec":{"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}}]
"@}
@{Baseline = 'Baseline3'; ExpectedJson = @"
[{
// Synopsis: This is an example baseline
-"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline3"},"spec":{"binding":{"field":{"alternativeType":["AlternateName"]},"targetName":["AlternateName"],"targetType":["Kind"]},"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}}]
+"apiVersion":"github.com/microsoft/PSRule/v1","kind":"Baseline","metadata":{"name":"Baseline3"},"spec":{"configuration":{"ruleConfig2":"Test3"},"rule":{"include":["M4.Rule1"]}}}]
"@}
)
#endregion
@@ -698,89 +587,98 @@ Describe 'Baseline' -Tag 'Baseline' {
}
It 'With -Baseline' {
- $result = @($testObject | Invoke-PSRule -Path $ruleFilePath,$baselineFilePath -Baseline 'TestBaseline1');
+ $options = @{
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
+ }
+
+ $result = @($testObject | Invoke-PSRule -Option $options -Path $ruleFilePath,$baselineFilePath -Baseline 'TestBaseline1');
$result | Should -Not -BeNullOrEmpty;
$result.Length | Should -Be 1;
$result[0].RuleName | Should -Be 'WithBaseline';
$result[0].Outcome | Should -Be 'Pass';
$result[0].TargetName | Should -Be 'TestObject1';
$result[0].TargetType | Should -Be 'TestObjectType';
- $result[0].Field.kind | Should -Be 'TestObjectType';
# Use a baseline group by name
- $result = @($testObject | Invoke-PSRule -Path $ruleFilePath,$baselineFilePath -Baseline '@latest' -Option @{
+ $options = @{
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
'Baseline.Group' = @{
latest = 'TestBaseline1'
}
- });
+ }
+ $result = @($testObject | Invoke-PSRule -Option $options -Path $ruleFilePath,$baselineFilePath -Baseline '@latest');
$result | Should -Not -BeNullOrEmpty;
$result.Length | Should -Be 1;
$result[0].RuleName | Should -Be 'WithBaseline';
$result[0].Outcome | Should -Be 'Pass';
$result[0].TargetName | Should -Be 'TestObject1';
$result[0].TargetType | Should -Be 'TestObjectType';
- $result[0].Field.kind | Should -Be 'TestObjectType';
}
It 'With -Module' {
$Null = Import-Module (Join-Path $here -ChildPath 'TestModule4') -Force;
+ $options = @{
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
+ }
+
# Module
- $result = @($testObject | Invoke-PSRule -Module TestModule4);
+ $result = @($testObject | Invoke-PSRule -Option $options -Module TestModule4);
$result | Should -Not -BeNullOrEmpty;
$result.Length | Should -Be 1;
$result[0].RuleName | Should -Be 'M4.Rule1';
$result[0].Outcome | Should -Be 'Pass';
# Module + Workspace
- $option = @{
+ $options = @{
'Configuration.ruleConfig1' = 'Test2'
'Rule.Include' = @('M4.Rule1', 'M4.Rule2')
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
'Binding.Field' = @{ kind = 'Kind' }
}
- $result = @($testObject | Invoke-PSRule -Module TestModule4 -Option $option);
+ $result = @($testObject | Invoke-PSRule -Module TestModule4 -Option $options);
$result | Should -Not -BeNullOrEmpty;
$result.Length | Should -Be 2;
$result[0].RuleName | Should -Be 'M4.Rule1';
$result[0].Outcome | Should -Be 'Fail';
$result[0].TargetName | Should -Be 'TestObject1';
$result[0].TargetType | Should -Be 'TestObjectType';
- $result[0].Field.kind | Should -Be 'TestObjectType';
- $result[0].Field.uniqueIdentifer | Should -Be '1';
- $result[0].Field.AlternativeType | Should -Be 'TestObjectType';
$result[1].RuleName | Should -Be 'M4.Rule2';
$result[1].Outcome | Should -Be 'Pass';
$result[1].TargetName | Should -Be 'TestObject1';
$result[1].TargetType | Should -Be 'TestObjectType';
- $result[1].Field.AlternativeType | Should -Be 'TestObjectType';
# Module + Workspace + Parameter
- $option = @{
+ $options = @{
'Configuration.ruleConfig1' = 'Test2'
'Rule.Include' = @('M4.Rule1', 'M4.Rule2')
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
}
- $result = @($testObject | Invoke-PSRule -Module TestModule4 -Option $option -Name 'M4.Rule2');
+ $result = @($testObject | Invoke-PSRule -Module TestModule4 -Option $options -Name 'M4.Rule2');
$result | Should -Not -BeNullOrEmpty;
$result.Length | Should -Be 1;
$result[0].RuleName | Should -Be 'M4.Rule2';
$result[0].Outcome | Should -Be 'Pass';
- $result[0].Field.kind | Should -Be '1';
- $result[0].Field.uniqueIdentifer | Should -Be '1';
# Module + Workspace + Parameter + Explicit
- $option = @{
+ $options = @{
'Configuration.ruleConfig1' = 'Test2'
'Rule.Include' = @('M4.Rule1', 'M4.Rule2')
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
}
- $result = @($testObject | Invoke-PSRule -Module TestModule4 -Option $option -Name 'M4.Rule2', 'M4.Rule3' -Baseline 'Baseline2');
+ $result = @($testObject | Invoke-PSRule -Module TestModule4 -Option $options -Name 'M4.Rule2', 'M4.Rule3' -Baseline 'Baseline2');
$result | Should -Not -BeNullOrEmpty;
$result.Length | Should -Be 2;
$result[0].RuleName | Should -Be 'M4.Rule2';
$result[0].Outcome | Should -Be 'Pass';
- $result[0].Field.AlternativeType | Should -Be 'TestObjectType';
$result[1].RuleName | Should -Be 'M4.Rule3';
$result[1].Outcome | Should -Be 'Pass';
- $result[1].Field.AlternativeType | Should -Be 'TestObjectType';
# Module Config + Module + Workspace + Parameter + Explicit
$result = @($testObject | Invoke-PSRule -Module TestModule4 -Name 'M4.Rule4' -Baseline 'Baseline3');
@@ -788,7 +686,6 @@ Describe 'Baseline' -Tag 'Baseline' {
$result.Length | Should -Be 1;
$result[0].RuleName | Should -Be 'M4.Rule4';
$result[0].Outcome | Should -Be 'Pass';
- $result[0].Field.AlternativeType | Should -Be 'TestObject1';
# Explict with default
$result = @($testObject | Invoke-PSRule -Module TestModule4 -Path $ruleFilePath -Baseline 'Module4');
@@ -798,6 +695,8 @@ Describe 'Baseline' -Tag 'Baseline' {
# Explict with local scope
$result = @($testObject | Invoke-PSRule -Module TestModule4 -Path $ruleFilePath -Baseline 'Module4' -Option @{
+ 'Binding.TargetName' = 'AlternateName'
+ 'Binding.TargetType' = 'kind'
'Rule.IncludeLocal' = $True
});
$result | Should -Not -BeNullOrEmpty;
diff --git a/tests/PSRule.Tests/TargetBinderTests.cs b/tests/PSRule.Tests/TargetBinderTests.cs
index 4391329647..92411232cf 100644
--- a/tests/PSRule.Tests/TargetBinderTests.cs
+++ b/tests/PSRule.Tests/TargetBinderTests.cs
@@ -4,7 +4,6 @@
using System.Management.Automation;
using Newtonsoft.Json.Linq;
using PSRule.Configuration;
-using PSRule.Definitions.Baselines;
using PSRule.Definitions.ModuleConfigs;
using PSRule.Pipeline;
@@ -85,8 +84,8 @@ private static ITargetBinder GetBinder()
{
Binding = new BindingOption
{
- TargetName = new[] { "name" },
- TargetType = new[] { "type" }
+ TargetName = ["name"],
+ TargetType = ["type"]
}
});
@@ -94,8 +93,8 @@ private static ITargetBinder GetBinder()
{
Binding = new BindingOption
{
- TargetName = new[] { "AlternativeName" },
- TargetType = new[] { "type" }
+ TargetName = ["AlternativeName"],
+ TargetType = ["type"]
}
});
@@ -103,8 +102,8 @@ private static ITargetBinder GetBinder()
{
Binding = new BindingOption
{
- TargetName = new[] { "name" },
- TargetType = new[] { "type" },
+ TargetName = ["name"],
+ TargetType = ["type"],
PreferTargetInfo = true
}
});
@@ -129,14 +128,5 @@ private static ITargetBinder GetBinder()
return builder.Build();
}
- private static IBaselineV1Spec GetOption(string[] targetName, string[] targetType, bool preferTargetInfo = false)
- {
- var result = new BaselineOption.BaselineInline();
- result.Binding.TargetName = targetName;
- result.Binding.TargetType = targetType;
- result.Binding.PreferTargetInfo = preferTargetInfo;
- return result;
- }
-
#endregion Helper methods
}
diff --git a/tests/PSRule.Tests/TestModule4/rules/Baseline.Rule.yaml b/tests/PSRule.Tests/TestModule4/rules/Baseline.Rule.yaml
index 7f335a0f6c..a86e34ee34 100644
--- a/tests/PSRule.Tests/TestModule4/rules/Baseline.Rule.yaml
+++ b/tests/PSRule.Tests/TestModule4/rules/Baseline.Rule.yaml
@@ -8,17 +8,6 @@ kind: Baseline
metadata:
name: Module4
spec:
- binding:
- field:
- kind:
- - Id
- uniqueIdentifer:
- - Id
- - AlternateName
- targetName:
- - AlternateName
- targetType:
- - Kind
rule:
include:
- 'M4.Rule1'
@@ -32,17 +21,6 @@ kind: Baseline
metadata:
name: Module4a
spec:
- binding:
- field:
- kind:
- - Id
- uniqueIdentifer:
- - Id
- - AlternateName
- targetName:
- - AlternateName
- targetType:
- - Kind
rule:
include:
- 'M4.Rule1'
@@ -56,11 +34,6 @@ kind: Baseline
metadata:
name: Baseline2
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - Kind
rule:
include:
- 'M4.Rule1'
@@ -74,13 +47,6 @@ kind: Baseline
metadata:
name: Baseline3
spec:
- binding:
- targetName:
- - AlternateName
- targetType:
- - Kind
- field:
- AlternativeType: [ 'AlternateName' ]
rule:
include:
- 'M4.Rule1'
diff --git a/tests/PSRule.Tests/TestModule4/rules/Module4.Rule.ps1 b/tests/PSRule.Tests/TestModule4/rules/Module4.Rule.ps1
index 1371d38673..a09a0e372a 100644
--- a/tests/PSRule.Tests/TestModule4/rules/Module4.Rule.ps1
+++ b/tests/PSRule.Tests/TestModule4/rules/Module4.Rule.ps1
@@ -7,8 +7,6 @@
# Synopsis: Test rule in TestModule4
Rule 'M4.Rule1' {
- $PSRule.TargetName -eq 'TestObject1'
- $PSRule.TargetType -eq 'TestObjectType'
$Configuration.ruleConfig1 -eq 'Test'
}
diff --git a/tests/PSRule.Tests/TestModule5/rules/Baseline.Rule.jsonc b/tests/PSRule.Tests/TestModule5/rules/Baseline.Rule.jsonc
index 597be63f73..c357ffb765 100644
--- a/tests/PSRule.Tests/TestModule5/rules/Baseline.Rule.jsonc
+++ b/tests/PSRule.Tests/TestModule5/rules/Baseline.Rule.jsonc
@@ -10,23 +10,6 @@
"name": "Module4"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test"
},
@@ -45,23 +28,6 @@
"name": "Module4a"
},
"spec": {
- "binding": {
- "field": {
- "kind": [
- "Id"
- ],
- "uniqueIdentifer": [
- "AlternateName",
- "Id"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig1": "Test2"
},
@@ -80,14 +46,6 @@
"name": "Baseline2"
},
"spec": {
- "binding": {
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},
@@ -106,19 +64,6 @@
"name": "Baseline3"
},
"spec": {
- "binding": {
- "field": {
- "AlternativeType": [
- "AlternateName"
- ]
- },
- "targetName": [
- "AlternateName"
- ],
- "targetType": [
- "Kind"
- ]
- },
"configuration": {
"ruleConfig2": "Test3"
},