commit 6e35ddf12f28d925b261648a60142515f8059e94
parent 4bfc7cb7b1ebe814a95d1440be93535be35a55fb
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Fri, 17 May 2024 19:34:44 -0700
Fix limit mode metadata blocking (#4489)
## Change
The serialization code should not be modifying the object that it is
operating on. Move it to instead skip the output of some values rather
than removing them.
When the remoting server is operating in limited mode, the metadata must
match between the initial limitation set and the incoming unit. This
removal was also breaking that, as the entry was now missing.
## Validation
Manual confirmation that the limit mode works after the change.
Diffstat:
4 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
@@ -345,7 +345,7 @@ jobs:
testSelector: 'testAssemblies'
testAssemblyVer2: '**\Microsoft.Management.Configuration.UnitTests.dll'
searchFolder: '$(buildOutDir)\Microsoft.Management.Configuration.UnitTests'
- codeCoverageEnabled: true
+ codeCoverageEnabled: false
platform: '$(buildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: true
diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.cpp
@@ -28,7 +28,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation
// TODO: Consider having the version/uri/type information all together in the future
if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 1)
{
- throw E_NOTIMPL;
+ THROW_HR(E_NOTIMPL);
}
else if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 2)
{
@@ -36,22 +36,31 @@ namespace winrt::Microsoft::Management::Configuration::implementation
}
else if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 3)
{
- throw E_NOTIMPL;
+ THROW_HR(E_NOTIMPL);
}
else
{
AICLI_LOG(Config, Error, << "Unknown configuration version: " << schemaVersion.ToString());
- throw E_UNEXPECTED;
+ THROW_HR(E_UNEXPECTED);
}
}
- void ConfigurationSetSerializer::WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet)
+ void ConfigurationSetSerializer::WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet, std::initializer_list<ConfigurationField> exclusions)
{
+ // Create a sorted list of the field names to exclude
+ std::vector<winrt::hstring> exclusionStrings;
+ for (ConfigurationField field : exclusions)
+ {
+ exclusionStrings.emplace_back(GetConfigurationFieldNameHString(field));
+ }
+ std::sort(exclusionStrings.begin(), exclusionStrings.end());
+
emitter << BeginMap;
for (const auto& [key, value] : valueSet)
{
- if (value != nullptr)
+ if (value != nullptr &&
+ !std::binary_search(exclusionStrings.begin(), exclusionStrings.end(), key))
{
std::string keyName = winrt::to_string(key);
emitter << Key << keyName << Value;
diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.h b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer.h
@@ -2,9 +2,11 @@
// Licensed under the MIT License.
#pragma once
#include "ConfigurationSetSerializer.h"
+#include "ConfigurationSetUtilities.h"
#include "ConfigurationSet.h"
#include <winget/Yaml.h>
+#include <initializer_list>
namespace winrt::Microsoft::Management::Configuration::implementation
{
@@ -26,7 +28,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation
ConfigurationSetSerializer() = default;
void WriteYamlConfigurationUnits(AppInstaller::YAML::Emitter& emitter, const std::vector<ConfigurationUnit>& units);
- void WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet);
+ void WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet, std::initializer_list<ConfigurationField> exclusions = {});
void WriteYamlValue(AppInstaller::YAML::Emitter& emitter, const winrt::Windows::Foundation::IInspectable& value);
void WriteYamlValueSetAsArray(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSetArray);
winrt::hstring GetSchemaVersionComment(winrt::hstring version);
diff --git a/src/Microsoft.Management.Configuration/ConfigurationSetSerializer_0_2.cpp b/src/Microsoft.Management.Configuration/ConfigurationSetSerializer_0_2.cpp
@@ -73,15 +73,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation
void ConfigurationSetSerializer_0_2::WriteResourceDirectives(AppInstaller::YAML::Emitter& emitter, const ConfigurationUnit& unit)
{
- auto metadata = unit.Metadata();
-
- const auto moduleKey = GetConfigurationFieldNameHString(ConfigurationField::ModuleDirective);
- if (metadata.HasKey(moduleKey))
- {
- metadata.Remove(moduleKey);
- }
-
emitter << Key << GetConfigurationFieldName(ConfigurationField::Directives);
- WriteYamlValueSet(emitter, metadata);
+ WriteYamlValueSet(emitter, unit.Metadata(), { ConfigurationField::ModuleDirective });
}
}