test_configurator.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_UPDATE_CLIENT_TEST_CONFIGURATOR_H_
  5. #define COMPONENTS_UPDATE_CLIENT_TEST_CONFIGURATOR_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include "base/containers/flat_map.h"
  12. #include "base/memory/raw_ptr.h"
  13. #include "base/memory/ref_counted.h"
  14. #include "components/update_client/configurator.h"
  15. #include "services/network/test/test_url_loader_factory.h"
  16. #include "third_party/abseil-cpp/absl/types/optional.h"
  17. #include "url/gurl.h"
  18. class PrefService;
  19. namespace network {
  20. class SharedURLLoaderFactory;
  21. } // namespace network
  22. namespace update_client {
  23. class ActivityDataService;
  24. class CrxDownloaderFactory;
  25. class NetworkFetcherFactory;
  26. class PatchChromiumFactory;
  27. class ProtocolHandlerFactory;
  28. class UnzipChromiumFactory;
  29. #define POST_INTERCEPT_SCHEME "https"
  30. #define POST_INTERCEPT_HOSTNAME "localhost2"
  31. #define POST_INTERCEPT_PATH "/update2"
  32. // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
  33. // the RSA public key the following hash:
  34. const uint8_t jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
  35. 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
  36. 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
  37. 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
  38. // component 1 public key (base64 encoded):
  39. const char jebg_public_key[] =
  40. "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC68bW8i/RzSaeXOcNLuBw0SP9+1bdo5ysLqH"
  41. "qfLqZs6XyJWEyL0U6f1axPR6LwViku21kgdc6PI524eb8Cr+a/iXGgZ8SdvZTcfQ/g/ukwlblF"
  42. "mtqYfDoVpz03U8rDQ9b6DxeJBF4r48TNlFORggrAiNR26qbf1i178Au12AzWtwIDAQAB";
  43. // component 2 has extension id "abagagagagagagagagagagagagagagag", and
  44. // the RSA public key the following hash:
  45. const uint8_t abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  46. 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  47. 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  48. 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01};
  49. // component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and
  50. // the RSA public key the following hash:
  51. const uint8_t ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e,
  52. 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2,
  53. 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b,
  54. 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17};
  55. // runaction_test_win.crx and its payload id: gjpmebpgbhcamgdgjcmnjfhggjpgcimm
  56. const uint8_t gjpm_hash[] = {0x69, 0xfc, 0x41, 0xf6, 0x17, 0x20, 0xc6, 0x36,
  57. 0x92, 0xcd, 0x95, 0x76, 0x69, 0xf6, 0x28, 0xcc,
  58. 0xbe, 0x98, 0x4b, 0x93, 0x17, 0xd6, 0x9c, 0xb3,
  59. 0x64, 0x0c, 0x0d, 0x25, 0x61, 0xc5, 0x80, 0x1d};
  60. class TestConfigurator : public Configurator {
  61. public:
  62. explicit TestConfigurator(PrefService* pref_service = nullptr);
  63. TestConfigurator(const TestConfigurator&) = delete;
  64. TestConfigurator& operator=(const TestConfigurator&) = delete;
  65. // Overrides for Configurator.
  66. double InitialDelay() const override;
  67. int NextCheckDelay() const override;
  68. int OnDemandDelay() const override;
  69. int UpdateDelay() const override;
  70. std::vector<GURL> UpdateUrl() const override;
  71. std::vector<GURL> PingUrl() const override;
  72. std::string GetProdId() const override;
  73. base::Version GetBrowserVersion() const override;
  74. std::string GetChannel() const override;
  75. std::string GetLang() const override;
  76. std::string GetOSLongName() const override;
  77. base::flat_map<std::string, std::string> ExtraRequestParams() const override;
  78. std::string GetDownloadPreference() const override;
  79. scoped_refptr<NetworkFetcherFactory> GetNetworkFetcherFactory() override;
  80. scoped_refptr<CrxDownloaderFactory> GetCrxDownloaderFactory() override;
  81. scoped_refptr<UnzipperFactory> GetUnzipperFactory() override;
  82. scoped_refptr<PatcherFactory> GetPatcherFactory() override;
  83. bool EnabledDeltas() const override;
  84. bool EnabledBackgroundDownloader() const override;
  85. bool EnabledCupSigning() const override;
  86. PrefService* GetPrefService() const override;
  87. ActivityDataService* GetActivityDataService() const override;
  88. bool IsPerUserInstall() const override;
  89. std::unique_ptr<ProtocolHandlerFactory> GetProtocolHandlerFactory()
  90. const override;
  91. absl::optional<bool> IsMachineExternallyManaged() const override;
  92. UpdaterStateProvider GetUpdaterStateProvider() const override;
  93. void SetOnDemandTime(int seconds);
  94. void SetInitialDelay(double seconds);
  95. void SetDownloadPreference(const std::string& download_preference);
  96. void SetEnabledCupSigning(bool use_cup_signing);
  97. void SetUpdateCheckUrl(const GURL& url);
  98. void SetUpdateCheckUrls(const std::vector<GURL>& urls);
  99. void SetPingUrl(const GURL& url);
  100. void SetCrxDownloaderFactory(
  101. scoped_refptr<CrxDownloaderFactory> crx_downloader_factory);
  102. void SetIsMachineExternallyManaged(
  103. absl::optional<bool> is_machine_externally_managed);
  104. void SetUpdaterStateProvider(UpdaterStateProvider update_state_provider);
  105. network::TestURLLoaderFactory* test_url_loader_factory() {
  106. return &test_url_loader_factory_;
  107. }
  108. private:
  109. friend class base::RefCountedThreadSafe<TestConfigurator>;
  110. ~TestConfigurator() override;
  111. class TestPatchService;
  112. double initial_time_{0};
  113. int ondemand_time_{0};
  114. std::string download_preference_;
  115. bool enabled_cup_signing_;
  116. raw_ptr<PrefService> pref_service_; // Not owned by this class.
  117. std::vector<GURL> update_check_urls_;
  118. GURL ping_url_;
  119. scoped_refptr<update_client::UnzipChromiumFactory> unzip_factory_;
  120. scoped_refptr<update_client::PatchChromiumFactory> patch_factory_;
  121. scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_;
  122. network::TestURLLoaderFactory test_url_loader_factory_;
  123. scoped_refptr<NetworkFetcherFactory> network_fetcher_factory_;
  124. scoped_refptr<CrxDownloaderFactory> crx_downloader_factory_;
  125. UpdaterStateProvider updater_state_provider_;
  126. absl::optional<bool> is_machine_externally_managed_;
  127. };
  128. } // namespace update_client
  129. #endif // COMPONENTS_UPDATE_CLIENT_TEST_CONFIGURATOR_H_