From df124ef1bb08294feb94615ce4a46fad125f54b6 Mon Sep 17 00:00:00 2001 From: Flor Elisa Chacon Ochoa Date: Tue, 20 Jun 2023 15:33:24 -0700 Subject: [PATCH 1/3] Respect GP for default sources in COM --- src/AppInstallerRepositoryCore/RepositorySource.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AppInstallerRepositoryCore/RepositorySource.cpp b/src/AppInstallerRepositoryCore/RepositorySource.cpp index 6c25dcbb16..48b59191e1 100644 --- a/src/AppInstallerRepositoryCore/RepositorySource.cpp +++ b/src/AppInstallerRepositoryCore/RepositorySource.cpp @@ -259,6 +259,8 @@ namespace AppInstaller::Repository Source::Source(WellKnownSource source) { + THROW_HR_IF(APPINSTALLER_CLI_ERROR_BLOCKED_BY_POLICY, !IsWellKnownSourceEnabled(source)); + SourceDetails details = GetWellKnownSourceDetailsInternal(source); m_sourceReferences.emplace_back(CreateSourceFromDetails(details)); } From 5387dd4bf5d6b0b07ac5559cf09aa64408e3bf80 Mon Sep 17 00:00:00 2001 From: Flor Elisa Chacon Ochoa Date: Tue, 20 Jun 2023 16:55:42 -0700 Subject: [PATCH 2/3] Consider default source type for allowed sources --- src/AppInstallerCLITests/TestSource.cpp | 5 +++++ src/AppInstallerCLITests/TestSource.h | 1 + .../Microsoft/ConfigurableTestSourceFactory.cpp | 5 +++++ .../Microsoft/PreIndexedPackageSourceFactory.cpp | 5 +++++ .../Microsoft/PredefinedInstalledSourceFactory.cpp | 5 +++++ .../Microsoft/PredefinedWriteableSourceFactory.cpp | 5 +++++ src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp | 5 +++++ src/AppInstallerRepositoryCore/RepositorySource.cpp | 4 ++++ src/AppInstallerRepositoryCore/Rest/RestSourceFactory.cpp | 5 +++++ src/AppInstallerRepositoryCore/SourceFactory.h | 3 +++ 10 files changed, 43 insertions(+) diff --git a/src/AppInstallerCLITests/TestSource.cpp b/src/AppInstallerCLITests/TestSource.cpp index 307f790f1a..d8970960d4 100644 --- a/src/AppInstallerCLITests/TestSource.cpp +++ b/src/AppInstallerCLITests/TestSource.cpp @@ -263,6 +263,11 @@ namespace TestCommon } } + std::string_view TestSourceFactory::TypeName() const + { + return "*TestSource"sv; + } + std::shared_ptr TestSourceFactory::Create(const SourceDetails& details) { if (OnOpenWithCustomHeader) diff --git a/src/AppInstallerCLITests/TestSource.h b/src/AppInstallerCLITests/TestSource.h index 0d09f51231..3dd1160d3a 100644 --- a/src/AppInstallerCLITests/TestSource.h +++ b/src/AppInstallerCLITests/TestSource.h @@ -137,6 +137,7 @@ namespace TestCommon TestSourceFactory(OpenFunctorWithCustomHeader open) : OnOpenWithCustomHeader(std::move(open)) {} // ISourceFactory + std::string_view TypeName() const override; std::shared_ptr Create(const AppInstaller::Repository::SourceDetails& details) override; bool Add(AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override; bool Update(const AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override; diff --git a/src/AppInstallerRepositoryCore/Microsoft/ConfigurableTestSourceFactory.cpp b/src/AppInstallerRepositoryCore/Microsoft/ConfigurableTestSourceFactory.cpp index a171515cd3..88f9be280c 100644 --- a/src/AppInstallerRepositoryCore/Microsoft/ConfigurableTestSourceFactory.cpp +++ b/src/AppInstallerRepositoryCore/Microsoft/ConfigurableTestSourceFactory.cpp @@ -111,6 +111,11 @@ namespace AppInstaller::Repository::Microsoft // The actual factory implementation. struct ConfigurableTestSourceFactoryImpl : public ISourceFactory { + std::string_view TypeName() const override final + { + return ConfigurableTestSourceFactory::Type(); + } + std::shared_ptr Create(const SourceDetails& details) override final { return std::make_shared(details); diff --git a/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp b/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp index 8dee1a7270..7c84835ef8 100644 --- a/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp +++ b/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp @@ -115,6 +115,11 @@ namespace AppInstaller::Repository::Microsoft // The base class for a package that comes from a preindexed packaged source. struct PreIndexedFactoryBase : public ISourceFactory { + std::string_view TypeName() const override final + { + return PreIndexedPackageSourceFactory::Type(); + } + std::shared_ptr Create(const SourceDetails& details) override final { // With more than one source implementation, we will probably need to probe first diff --git a/src/AppInstallerRepositoryCore/Microsoft/PredefinedInstalledSourceFactory.cpp b/src/AppInstallerRepositoryCore/Microsoft/PredefinedInstalledSourceFactory.cpp index 5bce3eb693..3b1a780c5b 100644 --- a/src/AppInstallerRepositoryCore/Microsoft/PredefinedInstalledSourceFactory.cpp +++ b/src/AppInstallerRepositoryCore/Microsoft/PredefinedInstalledSourceFactory.cpp @@ -168,6 +168,11 @@ namespace AppInstaller::Repository::Microsoft // The factory for the predefined installed source. struct Factory : public ISourceFactory { + std::string_view TypeName() const override final + { + return PredefinedInstalledSourceFactory::Type(); + } + std::shared_ptr Create(const SourceDetails& details) override final { THROW_HR_IF(E_INVALIDARG, details.Type != PredefinedInstalledSourceFactory::Type()); diff --git a/src/AppInstallerRepositoryCore/Microsoft/PredefinedWriteableSourceFactory.cpp b/src/AppInstallerRepositoryCore/Microsoft/PredefinedWriteableSourceFactory.cpp index 070c88a4ae..51657a0f0c 100644 --- a/src/AppInstallerRepositoryCore/Microsoft/PredefinedWriteableSourceFactory.cpp +++ b/src/AppInstallerRepositoryCore/Microsoft/PredefinedWriteableSourceFactory.cpp @@ -20,6 +20,11 @@ namespace AppInstaller::Repository::Microsoft // The factory for the predefined installing source. struct PredefinedWriteableSourceFactoryImpl : public ISourceFactory { + std::string_view TypeName() const override final + { + return PredefinedWriteableSourceFactory::Type(); + } + std::shared_ptr Create(const SourceDetails& details) override final; bool Add(SourceDetails&, IProgressCallback&) override final diff --git a/src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp b/src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp index 504834dd79..3717491936 100644 --- a/src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp +++ b/src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp @@ -80,6 +80,11 @@ namespace AppInstaller::Repository struct PackageTrackingCatalogSourceFactoryImpl : public ISourceFactory { + std::string_view TypeName() const override final + { + return PackageTrackingCatalogSourceFactory::Type(); + } + std::shared_ptr Create(const SourceDetails& details) override final { THROW_HR_IF(E_INVALIDARG, !Utility::CaseInsensitiveEquals(details.Type, PackageTrackingCatalogSourceFactory::Type())); diff --git a/src/AppInstallerRepositoryCore/RepositorySource.cpp b/src/AppInstallerRepositoryCore/RepositorySource.cpp index 48b59191e1..1870e75386 100644 --- a/src/AppInstallerRepositoryCore/RepositorySource.cpp +++ b/src/AppInstallerRepositoryCore/RepositorySource.cpp @@ -603,6 +603,10 @@ namespace AppInstaller::Repository auto& sourceDetails = m_sourceReferences[0]->GetDetails(); + // GetForType() has some special handling, like a default in case the type is empty. + // We get the canonical name here to make it easier to have checks for the source type. + sourceDetails.Type = ISourceFactory::GetForType(sourceDetails.Type)->TypeName(); + AICLI_LOG(Repo, Info, << "Adding source: Name[" << sourceDetails.Name << "], Type[" << sourceDetails.Type << "], Arg[" << sourceDetails.Arg << "]"); // Check all sources for the given name. diff --git a/src/AppInstallerRepositoryCore/Rest/RestSourceFactory.cpp b/src/AppInstallerRepositoryCore/Rest/RestSourceFactory.cpp index c3f7320239..5d1180a4e4 100644 --- a/src/AppInstallerRepositoryCore/Rest/RestSourceFactory.cpp +++ b/src/AppInstallerRepositoryCore/Rest/RestSourceFactory.cpp @@ -85,6 +85,11 @@ namespace AppInstaller::Repository::Rest // The base class for data that comes from a rest based source. struct RestSourceFactoryImpl : public ISourceFactory { + std::string_view TypeName() const override final + { + return RestSourceFactory::Type(); + } + std::shared_ptr Create(const SourceDetails& details) override final { THROW_HR_IF(E_INVALIDARG, !Utility::CaseInsensitiveEquals(details.Type, RestSourceFactory::Type())); diff --git a/src/AppInstallerRepositoryCore/SourceFactory.h b/src/AppInstallerRepositoryCore/SourceFactory.h index 6aff2ee36f..0445d950aa 100644 --- a/src/AppInstallerRepositoryCore/SourceFactory.h +++ b/src/AppInstallerRepositoryCore/SourceFactory.h @@ -14,6 +14,9 @@ namespace AppInstaller::Repository { virtual ~ISourceFactory() = default; + // Gets the name of the source type. + virtual std::string_view TypeName() const = 0; + // Creates a source object from the given details. virtual std::shared_ptr Create(const SourceDetails& details) = 0; From c54ddd4a9255530e176b47f5084cf804bc08eae9 Mon Sep 17 00:00:00 2001 From: Flor Elisa Chacon Ochoa Date: Wed, 21 Jun 2023 11:46:28 -0700 Subject: [PATCH 3/3] Only get typename for empty --- src/AppInstallerRepositoryCore/RepositorySource.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/AppInstallerRepositoryCore/RepositorySource.cpp b/src/AppInstallerRepositoryCore/RepositorySource.cpp index 1870e75386..145912e553 100644 --- a/src/AppInstallerRepositoryCore/RepositorySource.cpp +++ b/src/AppInstallerRepositoryCore/RepositorySource.cpp @@ -603,9 +603,12 @@ namespace AppInstaller::Repository auto& sourceDetails = m_sourceReferences[0]->GetDetails(); - // GetForType() has some special handling, like a default in case the type is empty. - // We get the canonical name here to make it easier to have checks for the source type. - sourceDetails.Type = ISourceFactory::GetForType(sourceDetails.Type)->TypeName(); + // If the source type is empty, use a default. + // AddSourceForDetails will also check for empty, but we need the actual type before that for validation. + if (sourceDetails.Type.empty()) + { + sourceDetails.Type = ISourceFactory::GetForType("")->TypeName(); + } AICLI_LOG(Repo, Info, << "Adding source: Name[" << sourceDetails.Name << "], Type[" << sourceDetails.Type << "], Arg[" << sourceDetails.Arg << "]");