Problem/Motivation

Tests should not depend on the network unless that is their explicit goal. Several core tests silently do though, because the default configuration of some modules and test profiles points at real drupal.org services, and test mocks often replace the http_client service only, while some code builds its own client from http_client_factory.

This surfaced in #3619842: Translation install and update batch does a HEAD and then a GET request for every project unnecessarily, does not accept compressed data, where the locale translation batch was changed to do one conditional GET instead of a HEAD + GET. In main, installer and translation tests already send HEAD requests to ftp.drupal.org, and the result happens not to matter, since the local test translation file is always newer than the remote one.

Tests depending on the network are slower, fail when the network or the remote service is down, and change behavior when the remote content changes, which is out of our control.

All production Guzzle clients in core are created by ClientFactory::fromOptions(), which gives a single place to observe them.

Steps to reproduce

Run the test suite without network access, or with ftp.drupal.org / updates.drupal.org resolving to 127.0.0.1.

Proposed resolution

The detector found these HTTP requests made, look at the issues solving them here:

Source Endpoint Requests Issue
Locale translation updates ftp.drupal.org 71 #3644177: Tests should not request translations from ftp.drupal.org
Update status updates.drupal.org/release-history 26 #3644200: Unintentional announcements, security advisories and update status fetched in tests
Security advisories updates.drupal.org/psa.json 15 #3644200: Unintentional announcements, security advisories and update status fetched in tests
Announcements feed in Umami tests www.drupal.org/announcements.json 4 #3644175: Uninstall announcements feed on Umami
Announcements feed in other tests www.drupal.org/announcements.json 9 #3644200: Unintentional announcements, security advisories and update status fetched in tests
Media oEmbed oembed.com, oembed1.com, www.youtube.com, i.ytimg.com 12 #3644258: oEmbed kernel tests fetch from oembed.com and YouTube
KernelTestBaseTest::testOutboundHttpRequest() (intentional) example.com 1
Total 138

Remaining tasks

Review the issues. Once those landed, the detector should not find any more testing of the internet.

User interface changes

None.

Introduced terminology

N/A.

API changes

N/A.

Data model changes

None.

Release notes snippet

N/A.

LLM disclosure

LLM was used to find this problem and come up with a detector. With human review.

Issue fork drupal-3644166

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gábor hojtsy created an issue. See original summary.

gábor hojtsy’s picture

LLM analysis of the results of the detector run: the MR pipeline failed 51 test classes in kernel, functional and functional JavaScript jobs, all of them on the detector; nothing else failed. Grouped by the code making the request:

Source Endpoint Tests Likely fix
LocaleFileManager ftp.drupal.org 22: AssetOptimizationUmamiTest, ConfigTranslationInstallTest, DemoUmamiProfileTest, DistributionProfileTranslationQueryTest, DistributionProfileTranslationTest, DrupalFlushAllCachesInInstallerTest, HelpTopicTranslationTest, InstallerExistingConfigExistingSettingsTest, InstallerExistingConfigNoProfileTest, InstallerExistingConfigTest, InstallerLanguageDirectionTest, InstallerTranslationDownloadTest, InstallerTranslationMultipleLanguageKeepEnglishTest, InstallerTranslationQueryTest, InstallerTranslationTest, LocaleNonInteractiveInstallTest, LocaleThemeInstallTest, MultipleRequestsPerformanceTest, NodeTypeTranslationTest, OpenTelemetryPerformanceTest, UmamiMultilingualInstallTest, UninstallDefaultContentTest use_source: local in the testing and testing_locale profiles and the testing_config_install fixture; a test-level override for demo_umami; mock http_client_factory too in InstallerTranslationDownloadTest
UpdateFetcher updates.drupal.org/release-history 15: AssetCompressUpdatePathTest, BlockRemoveSyndicateBlocksUpdateTest, ConfigImportAllTest, HelpNoSearchUpgradeTest, NavigationUpdateTest, PreventDowngradeTest, SequencesTableRemovalUpdateTest, TextWithSummaryUpdatePathTest, UmamiMultilingualInstallTest, UpdateContribTest, dblog UpdatePathTest, UpdatePathTestBaseFilledTest, UpdatePathTestBaseTest, UserCreatedFieldDisplayUpgradeTest, ViewsAddFilterMinMaxLabelsUpdateTest Point update.settings:fetch.url at a local URL in UpdatePathTestBase (the database dumps have update module enabled); find which UpdateContribTest case misses the update_test fixtures (requests for aaa_update_test, bbb_update_test, ccc_update_test go out)
AnnounceFetcher www.drupal.org 12: AnnounceBlockTest, AssetOptimizationUmamiTest, ConfigImportAllTest, ContentTranslationConfigUITest, DemoUmamiProfileTest, MediaStandardProfileTest, StandardInstallerTest, StandardRecipeInstallTest, StandardRecipeTest, StandardTest, UmamiMultilingualInstallTest, UninstallDefaultContentTest Tests on the standard and Umami profiles: point the feed at a local fixture in tests; AnnounceBlockTest should use its test module's fixture
SecurityAdvisoriesFetcher updates.drupal.org/psa.json 7: DbLogTest, file DeleteTest, file UsageTest, WorkspaceCRUDTest (kernel tests running cron), StandardInstallerTest, StandardRecipeInstallTest, UmamiMultilingualInstallTest Disable system.advisories:enabled by default in tests, enabling it only in the advisories tests that use their local fixture
Media oEmbed: ProviderRepository, ResourceFetcher, OEmbed oembed.com, oembed1.com, www.youtube.com, i.ytimg.com 3: EntityLinksTest, MediaSourceValidationTest (fetches during setUp(), before its mock client is set), ProviderRepositoryTest::testNonExistingProviderDatabase (relies on the real oembed.com returning 404 and oembed1.com not resolving) Set the mock client before creating the oEmbed media type, use media_test_oembed fixtures, mock the failing responses
KernelTestBaseTest::testOutboundHttpRequest example.com 1 Intentional: tests that an outbound request can be made. Should have an opt-in.

All requests were logged in sites/simpletest/browser_output/external-http-requests.log of each job's artifacts (138 requests across the 14 test jobs).

gábor hojtsy’s picture

Title: Find external HTTP requests from core tests » [META] Find and resolve external HTTP requests from core tests
gábor hojtsy’s picture

Category: Task » Plan
catch’s picture

UmamiMultilingualInstallTest does a full UI install and checks the update status checkbox to make sure it works, but doesn't test anything else about update status. Assuming we don't want to drop the coverage, I think we need to do something like set a mock local endpoint in a settings.php override, possibly for every functional test so it's a catch-all. If we do that it might require the actual real update status tests to do this in settings.php instead of updating config or similar.

gábor hojtsy’s picture

Opened #3644200: Unintentional announcements and security advisories fetched in tests for the announcement and psa feeds. Proof from the collector looks good :) Fix is simple.

gábor hojtsy’s picture

Opened #3644236: Tests fetch update status data from updates.drupal.org for the update feed but that is only a small few lines on top of hte announcement/psa issue, so may fold it there.

gábor hojtsy’s picture

gábor hojtsy’s picture

Issue summary: View changes
gábor hojtsy’s picture

Issue summary: View changes
gábor hojtsy’s picture

Issue summary: View changes