2020-03-24 19:08:37 +01:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
// Licensed under the MIT License.
|
2018-12-18 17:11:21 +01:00
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Management.Automation;
|
|
|
|
using System.Management.Automation.Configuration;
|
|
|
|
using System.Management.Automation.Internal;
|
|
|
|
using System.Reflection;
|
2019-01-30 02:24:18 +01:00
|
|
|
using System.Threading;
|
2018-01-03 21:43:28 +01:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
2018-12-18 17:11:21 +01:00
|
|
|
using Xunit;
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
namespace PSTests.Sequential
|
|
|
|
{
|
2018-12-13 23:22:07 +01:00
|
|
|
[TestCaseOrderer("TestOrder.TestCaseOrdering.PriorityOrderer", "powershell-tests")]
|
2018-01-03 21:43:28 +01:00
|
|
|
public class PowerShellPolicyFixture : IDisposable
|
|
|
|
{
|
2018-12-18 17:11:21 +01:00
|
|
|
private const string ConfigFileName = "powershell.config.json";
|
2020-05-29 06:56:33 +02:00
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
private readonly string systemWideConfigFile;
|
|
|
|
private readonly string currentUserConfigFile;
|
|
|
|
|
|
|
|
private readonly string systemWideConfigBackupFile;
|
|
|
|
private readonly string currentUserConfigBackupFile;
|
|
|
|
|
|
|
|
private readonly string systemWideConfigDirectory;
|
|
|
|
private readonly string currentUserConfigDirectory;
|
|
|
|
|
|
|
|
private readonly JsonSerializer serializer;
|
|
|
|
|
|
|
|
private readonly PowerShellPolicies systemWidePolicies;
|
|
|
|
private readonly PowerShellPolicies currentUserPolicies;
|
|
|
|
|
|
|
|
private readonly bool originalTestHookValue;
|
|
|
|
|
|
|
|
public PowerShellPolicyFixture()
|
|
|
|
{
|
|
|
|
systemWideConfigDirectory = Utils.DefaultPowerShellAppBase;
|
2019-10-07 11:15:01 +02:00
|
|
|
currentUserConfigDirectory = Platform.ConfigDirectory;
|
2018-01-03 21:43:28 +01:00
|
|
|
|
2018-01-04 06:58:46 +01:00
|
|
|
if (!Directory.Exists(currentUserConfigDirectory))
|
|
|
|
{
|
|
|
|
// Create the CurrentUser config directory if it doesn't exist
|
|
|
|
Directory.CreateDirectory(currentUserConfigDirectory);
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:11:21 +01:00
|
|
|
systemWideConfigFile = Path.Combine(systemWideConfigDirectory, ConfigFileName);
|
|
|
|
currentUserConfigFile = Path.Combine(currentUserConfigDirectory, ConfigFileName);
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
if (File.Exists(systemWideConfigFile))
|
|
|
|
{
|
|
|
|
systemWideConfigBackupFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
|
|
|
File.Move(systemWideConfigFile, systemWideConfigBackupFile);
|
|
|
|
}
|
2018-12-18 17:11:21 +01:00
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
if (File.Exists(currentUserConfigFile))
|
|
|
|
{
|
|
|
|
currentUserConfigBackupFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
|
|
|
File.Move(currentUserConfigFile, currentUserConfigBackupFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
var settings = new JsonSerializerSettings()
|
|
|
|
{
|
|
|
|
TypeNameHandling = TypeNameHandling.None,
|
|
|
|
MaxDepth = 10,
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
};
|
|
|
|
serializer = JsonSerializer.Create(settings);
|
|
|
|
|
|
|
|
systemWidePolicies = new PowerShellPolicies()
|
|
|
|
{
|
|
|
|
ScriptExecution = new ScriptExecution() { ExecutionPolicy = "RemoteSigned", EnableScripts = true },
|
|
|
|
ScriptBlockLogging = new ScriptBlockLogging() { EnableScriptBlockInvocationLogging = true, EnableScriptBlockLogging = false },
|
|
|
|
ModuleLogging = new ModuleLogging() { EnableModuleLogging = false, ModuleNames = new string[] { "PSReadline", "PowerShellGet" } },
|
|
|
|
ProtectedEventLogging = new ProtectedEventLogging() { EnableProtectedEventLogging = false, EncryptionCertificate = new string[] { "Joe" } },
|
2019-02-22 07:35:32 +01:00
|
|
|
Transcription = new Transcription() { EnableInvocationHeader = true, EnableTranscripting = true, OutputDirectory = @"c:\tmp" },
|
|
|
|
UpdatableHelp = new UpdatableHelp() { DefaultSourcePath = @"f:\temp" },
|
2018-01-03 21:43:28 +01:00
|
|
|
ConsoleSessionConfiguration = new ConsoleSessionConfiguration() { EnableConsoleSessionConfiguration = true, ConsoleSessionConfigurationName = "name" }
|
|
|
|
};
|
|
|
|
|
|
|
|
currentUserPolicies = new PowerShellPolicies()
|
|
|
|
{
|
|
|
|
ScriptExecution = new ScriptExecution() { ExecutionPolicy = "RemoteSigned" },
|
|
|
|
ScriptBlockLogging = new ScriptBlockLogging() { EnableScriptBlockLogging = false },
|
|
|
|
ModuleLogging = new ModuleLogging() { EnableModuleLogging = false },
|
|
|
|
ProtectedEventLogging = new ProtectedEventLogging() { EncryptionCertificate = new string[] { "Joe" } }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set the test hook to disable policy caching
|
|
|
|
originalTestHookValue = InternalTestHooks.BypassGroupPolicyCaching;
|
|
|
|
InternalTestHooks.BypassGroupPolicyCaching = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
CleanupConfigFiles();
|
|
|
|
if (systemWideConfigBackupFile != null)
|
|
|
|
{
|
|
|
|
File.Move(systemWideConfigBackupFile, systemWideConfigFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentUserConfigBackupFile != null)
|
|
|
|
{
|
|
|
|
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
|
|
|
|
}
|
2018-12-18 17:11:21 +01:00
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal PowerShellPolicies SystemWidePolicies
|
|
|
|
{
|
|
|
|
get { return systemWidePolicies; }
|
|
|
|
}
|
|
|
|
|
|
|
|
internal PowerShellPolicies CurrentUserPolicies
|
|
|
|
{
|
|
|
|
get { return currentUserPolicies; }
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Compare_Policy_Settings
|
|
|
|
|
|
|
|
internal void CompareScriptExecution(ScriptExecution a, ScriptExecution b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EnableScripts, b.EnableScripts);
|
|
|
|
Assert.Equal(a.ExecutionPolicy, b.ExecutionPolicy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareScriptBlockLogging(ScriptBlockLogging a, ScriptBlockLogging b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EnableScriptBlockInvocationLogging, b.EnableScriptBlockInvocationLogging);
|
|
|
|
Assert.Equal(a.EnableScriptBlockLogging, b.EnableScriptBlockLogging);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareModuleLogging(ModuleLogging a, ModuleLogging b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EnableModuleLogging, b.EnableModuleLogging);
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a.ModuleNames == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b.ModuleNames);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.ModuleNames.Length, b.ModuleNames.Length);
|
|
|
|
for (int i = 0; i < a.ModuleNames.Length; i++)
|
|
|
|
{
|
|
|
|
Assert.Equal(a.ModuleNames[i], b.ModuleNames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareProtectedEventLogging(ProtectedEventLogging a, ProtectedEventLogging b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EnableProtectedEventLogging, b.EnableProtectedEventLogging);
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a.EncryptionCertificate == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b.EncryptionCertificate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EncryptionCertificate.Length, b.EncryptionCertificate.Length);
|
|
|
|
for (int i = 0; i < a.EncryptionCertificate.Length; i++)
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EncryptionCertificate[i], b.EncryptionCertificate[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareTranscription(Transcription a, Transcription b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EnableTranscripting, b.EnableTranscripting);
|
|
|
|
Assert.Equal(a.EnableInvocationHeader, b.EnableInvocationHeader);
|
|
|
|
Assert.Equal(a.OutputDirectory, b.OutputDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareUpdatableHelp(UpdatableHelp a, UpdatableHelp b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.DefaultSourcePath, b.DefaultSourcePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareConsoleSessionConfiguration(ConsoleSessionConfiguration a, ConsoleSessionConfiguration b)
|
|
|
|
{
|
2020-07-31 01:06:38 +02:00
|
|
|
if (a == null)
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
|
|
|
Assert.Null(b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Assert.Equal(a.EnableConsoleSessionConfiguration, b.EnableConsoleSessionConfiguration);
|
|
|
|
Assert.Equal(a.ConsoleSessionConfigurationName, b.ConsoleSessionConfigurationName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void CompareTwoPolicies(PowerShellPolicies a, PowerShellPolicies b)
|
|
|
|
{
|
|
|
|
// Compare 'ScriptExecution' settings
|
|
|
|
CompareScriptExecution(a.ScriptExecution, b.ScriptExecution);
|
|
|
|
|
|
|
|
// Compare 'ScriptBlockLogging' settings
|
|
|
|
CompareScriptBlockLogging(a.ScriptBlockLogging, b.ScriptBlockLogging);
|
|
|
|
|
|
|
|
// Compare 'ModuleLogging' settings
|
|
|
|
CompareModuleLogging(a.ModuleLogging, b.ModuleLogging);
|
|
|
|
|
|
|
|
// Compare 'ProtectedEventLogging' settings
|
|
|
|
CompareProtectedEventLogging(a.ProtectedEventLogging, b.ProtectedEventLogging);
|
|
|
|
|
|
|
|
// Compare 'Transcription' settings
|
|
|
|
CompareTranscription(a.Transcription, b.Transcription);
|
|
|
|
|
|
|
|
// Compare 'UpdatableHelp' settings
|
|
|
|
CompareUpdatableHelp(a.UpdatableHelp, b.UpdatableHelp);
|
|
|
|
|
|
|
|
// Compare 'ConsoleSessionConfiguration' settings
|
|
|
|
CompareConsoleSessionConfiguration(a.ConsoleSessionConfiguration, b.ConsoleSessionConfiguration);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Configuration_File_Setup
|
|
|
|
|
|
|
|
public void CleanupConfigFiles()
|
|
|
|
{
|
2019-01-30 02:24:18 +01:00
|
|
|
var maxPause = 10;
|
2018-12-18 17:11:21 +01:00
|
|
|
|
2019-01-30 02:24:18 +01:00
|
|
|
while (maxPause-- != 0 && (File.Exists(systemWideConfigFile) || File.Exists(currentUserConfigFile)))
|
2018-01-03 21:43:28 +01:00
|
|
|
{
|
2019-01-30 02:24:18 +01:00
|
|
|
var pause = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
File.Delete(systemWideConfigFile);
|
|
|
|
}
|
|
|
|
catch (IOException)
|
|
|
|
{
|
|
|
|
pause = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
File.Delete(currentUserConfigFile);
|
|
|
|
}
|
|
|
|
catch (IOException)
|
|
|
|
{
|
|
|
|
pause = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pause)
|
|
|
|
{
|
|
|
|
Thread.Sleep(5);
|
|
|
|
}
|
2018-01-03 21:43:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetupConfigFile1()
|
|
|
|
{
|
|
|
|
CleanupConfigFiles();
|
|
|
|
|
|
|
|
// System wide config file has all policy settings
|
|
|
|
var systemWideConfig = new { ConsolePrompting = true, PowerShellPolicies = systemWidePolicies };
|
|
|
|
using (var streamWriter = new StreamWriter(systemWideConfigFile))
|
|
|
|
{
|
|
|
|
serializer.Serialize(streamWriter, systemWideConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Current user config file has partial policy settings
|
|
|
|
var currentUserConfig = new { DisablePromptToUpdateHelp = false, PowerShellPolicies = currentUserPolicies };
|
|
|
|
using (var streamWriter = new StreamWriter(currentUserConfigFile))
|
|
|
|
{
|
|
|
|
serializer.Serialize(streamWriter, currentUserConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetupConfigFile2()
|
|
|
|
{
|
|
|
|
CleanupConfigFiles();
|
|
|
|
|
|
|
|
// System wide config file has all policy settings
|
|
|
|
var systemWideConfig = new { ConsolePrompting = true, PowerShellPolicies = systemWidePolicies };
|
|
|
|
using (var streamWriter = new StreamWriter(systemWideConfigFile))
|
|
|
|
{
|
|
|
|
serializer.Serialize(streamWriter, systemWideConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Current user config file is empty
|
|
|
|
CreateEmptyFile(currentUserConfigFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetupConfigFile3()
|
|
|
|
{
|
|
|
|
CleanupConfigFiles();
|
|
|
|
|
|
|
|
// System wide config file is empty
|
|
|
|
CreateEmptyFile(systemWideConfigFile);
|
|
|
|
|
|
|
|
// Current user config file has partial policy settings
|
|
|
|
var currentUserConfig = new { DisablePromptToUpdateHelp = false, PowerShellPolicies = currentUserPolicies };
|
|
|
|
using (var streamWriter = new StreamWriter(currentUserConfigFile))
|
|
|
|
{
|
|
|
|
serializer.Serialize(streamWriter, currentUserConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetupConfigFile4()
|
|
|
|
{
|
|
|
|
CleanupConfigFiles();
|
2018-12-18 17:11:21 +01:00
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
// System wide config file is empty
|
|
|
|
CreateEmptyFile(systemWideConfigFile);
|
2018-12-18 17:11:21 +01:00
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
// Current user config file is empty
|
|
|
|
CreateEmptyFile(currentUserConfigFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CreateEmptyFile(string fileName)
|
|
|
|
{
|
|
|
|
File.Create(fileName).Dispose();
|
|
|
|
}
|
|
|
|
|
2019-10-30 22:44:34 +01:00
|
|
|
internal void ForceReadingFromFile()
|
|
|
|
{
|
|
|
|
// Reset the cached roots.
|
|
|
|
FieldInfo roots = typeof(PowerShellConfig).GetField("configRoots", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
JObject[] value = (JObject[])roots.GetValue(PowerShellConfig.Instance);
|
|
|
|
value[0] = null;
|
|
|
|
value[1] = null;
|
|
|
|
}
|
|
|
|
|
2018-01-03 21:43:28 +01:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PowerShellPolicyTests : IClassFixture<PowerShellPolicyFixture>
|
|
|
|
{
|
2018-12-18 17:11:21 +01:00
|
|
|
private PowerShellPolicyFixture fixture;
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
public PowerShellPolicyTests(PowerShellPolicyFixture fixture)
|
|
|
|
{
|
|
|
|
this.fixture = fixture;
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(1)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void PowerShellConfig_GetPowerShellPolicies_BothConfigFilesNotEmpty()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile1();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.AllUsers);
|
2018-01-03 21:43:28 +01:00
|
|
|
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
|
|
|
|
|
|
|
|
Assert.NotNull(sysPolicies);
|
|
|
|
Assert.NotNull(userPolicies);
|
|
|
|
|
|
|
|
fixture.CompareTwoPolicies(sysPolicies, fixture.SystemWidePolicies);
|
|
|
|
fixture.CompareTwoPolicies(userPolicies, fixture.CurrentUserPolicies);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(2)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void PowerShellConfig_GetPowerShellPolicies_EmptyUserConfig()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile2();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.AllUsers);
|
2018-01-03 21:43:28 +01:00
|
|
|
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
|
|
|
|
|
|
|
|
Assert.NotNull(sysPolicies);
|
|
|
|
Assert.Null(userPolicies);
|
|
|
|
|
|
|
|
fixture.CompareTwoPolicies(sysPolicies, fixture.SystemWidePolicies);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(3)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void PowerShellConfig_GetPowerShellPolicies_EmptySystemConfig()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile3();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.AllUsers);
|
2018-01-03 21:43:28 +01:00
|
|
|
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
|
|
|
|
|
|
|
|
Assert.Null(sysPolicies);
|
|
|
|
Assert.NotNull(userPolicies);
|
|
|
|
|
|
|
|
fixture.CompareTwoPolicies(userPolicies, fixture.CurrentUserPolicies);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(4)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void PowerShellConfig_GetPowerShellPolicies_BothConfigFilesEmpty()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile4();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.AllUsers);
|
2018-01-03 21:43:28 +01:00
|
|
|
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
|
|
|
|
|
|
|
|
Assert.Null(sysPolicies);
|
|
|
|
Assert.Null(userPolicies);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(5)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void PowerShellConfig_GetPowerShellPolicies_BothConfigFilesNotExist()
|
|
|
|
{
|
|
|
|
fixture.CleanupConfigFiles();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.AllUsers);
|
2018-01-03 21:43:28 +01:00
|
|
|
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
|
|
|
|
|
|
|
|
Assert.Null(sysPolicies);
|
|
|
|
Assert.Null(userPolicies);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(6)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void Utils_GetPolicySetting_BothConfigFilesNotEmpty()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile1();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
ScriptExecution scriptExecution;
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
|
|
|
|
|
|
|
|
ScriptBlockLogging scriptBlockLogging;
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
ModuleLogging moduleLogging;
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
|
|
|
|
|
|
|
|
ProtectedEventLogging protectedEventLogging;
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
|
|
|
|
Transcription transcription;
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
|
|
|
|
|
|
|
|
UpdatableHelp updatableHelp;
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
|
|
|
|
|
|
|
|
ConsoleSessionConfiguration consoleSessionConfiguration;
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(7)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void Utils_GetPolicySetting_EmptyUserConfig()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile2();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
// The CurrentUser config is empty
|
|
|
|
ScriptExecution scriptExecution;
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
|
|
|
|
|
|
|
|
ScriptBlockLogging scriptBlockLogging;
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
ModuleLogging moduleLogging;
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
|
|
|
|
|
|
|
|
ProtectedEventLogging protectedEventLogging;
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
Transcription transcription;
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
|
|
|
|
|
|
|
|
UpdatableHelp updatableHelp;
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
|
|
|
|
|
|
|
|
ConsoleSessionConfiguration consoleSessionConfiguration;
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(8)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void Utils_GetPolicySetting_EmptySystemConfig()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile3();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
// The SystemWide config is empty
|
|
|
|
ScriptExecution scriptExecution;
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
|
|
|
|
|
|
|
|
ScriptBlockLogging scriptBlockLogging;
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
|
|
|
|
|
|
|
|
ModuleLogging moduleLogging;
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
|
|
|
|
|
|
|
|
ProtectedEventLogging protectedEventLogging;
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
|
|
|
|
|
|
|
|
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
|
|
|
|
Transcription transcription;
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
UpdatableHelp updatableHelp;
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
ConsoleSessionConfiguration consoleSessionConfiguration;
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(9)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void Utils_GetPolicySetting_BothConfigFilesEmpty()
|
|
|
|
{
|
|
|
|
fixture.SetupConfigFile4();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
// Both config files are empty
|
|
|
|
ScriptExecution scriptExecution;
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
ScriptBlockLogging scriptBlockLogging;
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
ModuleLogging moduleLogging;
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
ProtectedEventLogging protectedEventLogging;
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
|
|
|
|
Transcription transcription;
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
UpdatableHelp updatableHelp;
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
ConsoleSessionConfiguration consoleSessionConfiguration;
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:22:07 +01:00
|
|
|
[Fact, TestPriority(10)]
|
2018-01-03 21:43:28 +01:00
|
|
|
public void Utils_GetPolicySetting_BothConfigFilesNotExist()
|
|
|
|
{
|
|
|
|
fixture.CleanupConfigFiles();
|
2019-10-30 22:44:34 +01:00
|
|
|
fixture.ForceReadingFromFile();
|
2018-01-03 21:43:28 +01:00
|
|
|
|
|
|
|
// Both config files don't exist
|
|
|
|
ScriptExecution scriptExecution;
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptExecution(scriptExecution, null);
|
|
|
|
|
|
|
|
ScriptBlockLogging scriptBlockLogging;
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
|
|
|
|
|
|
|
|
ModuleLogging moduleLogging;
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareModuleLogging(moduleLogging, null);
|
|
|
|
|
|
|
|
ProtectedEventLogging protectedEventLogging;
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
|
|
|
|
|
|
|
|
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
|
|
|
|
Transcription transcription;
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareTranscription(transcription, null);
|
|
|
|
|
|
|
|
UpdatableHelp updatableHelp;
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareUpdatableHelp(updatableHelp, null);
|
|
|
|
|
|
|
|
ConsoleSessionConfiguration consoleSessionConfiguration;
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
|
|
|
|
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
|
|
|
|
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 21:20:58 +01:00
|
|
|
}
|