aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/http
Commit message (Collapse)AuthorAgeFilesLines
* tests: Use MediaWikiCoversValidator when extends PHPUnit's TestCaseUmherirrender2024-11-191-0/+1
| | | | | | | | | | | Validate the @covers annotation to be valid on CI runs. This is done for mosts tests via MediaWikiCoversValidator in base class MediaWikiIntegrationTestCase or MediaWikiUnitTestCase Only omitted when @coversNothing is used. This is already used in other library-related test cases. Change-Id: Ib31db02b4c623e80049a5f4645c77824244b6d6d
* phpunit: Replace trivial wfParseUrl use with parse_url()Timo Tijhof2024-08-291-2/+2
| | | | | | | | Follows-up changes I57a8e7ea1b3, I1e76d2f5ae, I98ea4670e8, and more in a search for "parse_url" in Codesearch (WMF Deployed). Bug: T319340 Change-Id: I2b389612f4d591080f7e6235ddfc72f832b31143
* Use StatusValue::getMessages() instead of deprecated methodsBartosz Dziewoński2024-05-181-12/+4
| | | | | | | | | This commit replaces some of the uses of getErrorsArray(), getWarningsArray(), getErrorsByType(), and getErrors(). In many cases the code becomes shorter and clearer. Follow-up to Ibc4ce11594cf36ce7b2495d2636ee080d3443b04. Change-Id: Id0ebeac26ae62231edb48458dbd2e13ddcbd0a9e
* tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-162-4/+4
| | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* Clean up testsMatěj Suchánek2024-02-121-1/+1
| | | | | | | Replace strpos with str_contains, str_starts_with, etc. Fix spelling of "cannot" and other typos. Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
* http: MultiHttpClient supports TelemetryHeadersInterfacePiotr Miazga2023-09-121-10/+8
| | | | | | | | | | | | | | Introduce a new interface Wikimedia/Http/TelemetryHeadersInterface that provides telemetry information that could be attached to HTTP Requests. MultiHttpClient is expecting `telemetry` option of TelemetryHeadersInterface type. The MediaWiki/Http/Telemetry implements the interface, therefore ObjectCache can inject it to RESTBagOStuff, that further injects it to MultiHttpClient. Bug: T344926 Change-Id: I59a3f1048c403fe2e4ef0c74353dfe74ff9ca893
* http: Propagate `tracestate` and `traceparent` headersPiotr Miazga2023-08-071-0/+32
| | | | | | | | | | | Introduce a Telemetry singleton for propagating `tracestate` and `traceheaders` during a MW web request. This class allows for easier testing and mocking. In the future we might use this as a wrapper for OpenTelemetry. Bug: T320559 Change-Id: I3e5e54afa21f8c099877b3765c769f2d2f8f5d61
* Remove deprecated MWHttpRequest::factoryUmherirrender2023-04-261-5/+0
| | | | | Bug: T324918 Change-Id: Ie03d4b25eb239bbbbc2346821a86f09c29e03524
* Remove deprecated class HttpUmherirrender2023-04-241-32/+0
| | | | | | | | | | | | | | The class and all functions are deprecated: - Http::request() - Http::get() - Http::post() - Http::userAgent() - Http::isValidURI() - Http::getProxy() - Http::createMultiClient() Bug: T305813 Change-Id: Icd8af4822b16b4bf4558b756e20171c3ae9a9fa1
* Just another 80 or so PHPStorm inspection fixes (#4)Tim Starling2023-03-251-1/+0
| | | | | | | | | | | | | * Unnecessary regex modifier. I agree with this inspection which flags /s modifiers on regexes that don't use a dot. * Property declared dynamically. * Unused local variable. But it's acceptable for an unused local variable to take the return value of a method under test, when it is being tested for its side-effects. And it's acceptable for an unused local variable to document unused list expansion elements, or the nature of array keys in a foreach. Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
* Hard-deprecate MWHttpRequest::factoryUmherirrender2023-02-131-1/+3
| | | | | Bug: T324918 Change-Id: I360d57b5aa9e2e8cbfc8b5c5654ab1aaf1d944b3
* Replace comment about deprecated Http::requestUmherirrender2022-12-111-3/+3
| | | | | Bug: T305813 Change-Id: I76ea5e98b133ab07d2ef71bbcebd0646b6f2f5ad
* Migrate usage of `setMwGlobals()` to `overrideConfigValue(s)`Derick Alangi2022-08-011-2/+4
| | | | Change-Id: I49d97864d8f9d8cadf01b0c0dc653fbac4ca9e94
* tests: Use ::class in assertInstanceOf functionUmherirrender2022-01-161-1/+1
| | | | Change-Id: I1b498c88c702c131553c8948bcec5730ec0dcb35
* http: Don't set X-Forwarded-Proto when using a reverse proxyKunal Mehta2021-11-171-1/+0
| | | | | | | | | | | Discussion on Ia16d8f86b1cb20 indicates that we want to go in the other direction - MediaWiki shouldn't set X-Forwarded-Proto, rather the reverse proxy (envoy in Wikimedia's case) should set it. This follows-up cc241c2add4ebdd. Bug: T288848 Change-Id: Ifc5e9da9a02b45d9d1ad51c3e1389f9ac7325c86
* build: Update mediawiki-codesniffer from v37.0.0 to v38.0.0Alexander Vorwerk2021-10-221-3/+3
| | | | Change-Id: Iff096d3789b8c261aa47fb41d6f450a3bda7ce6a
* Allow using a reverse proxy for local HTTP requestsKunal Mehta2021-10-151-0/+12
| | | | | | | | | | | | | | $wgLocalHTTPProxy can be used to configure a reverse proxy for requests to domains in $wgLocalVirtualHosts. The previous implementation of using it as a proper HTTP proxy is no longer supported and has been reverted out of REL1_37 (856da72363d1ba8bf). It sets the hostname of the request as a "Host" header, scheme as "X-Forwarded-Proto" and then sets the proxy's scheme, host and port as those of the request. Bug: T288848 Change-Id: Ibc3616f5ad925d464d937ab15461a88619c8b7a7
* tests: MWHttpRequestTest is a unit test, not an integration testKunal Mehta2021-10-081-0/+88
| | | | Change-Id: Iea8aff749c4e7da3fbfb0f6c3fbefd450d9a3b6a
* Move HttpRequestFactoryTest to a unit testDannyS7122021-06-021-259/+0
| | | | | | | No integration in needed or used, if we use a mock Status to avoid the real Status::getWikitext Change-Id: I3c6188c4d511d9225be160a8ce06f6b7d4b3f615
* phpunit: Mass-replace setMethods with onlyMethods and adjustDaimona Eaytoy2021-04-161-2/+2
| | | | | | | | | | | | Ended up using grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g' special-casing setMethods( null ) -> onlyMethods( [] ) and then manual fix of failing test (from PS2 onwards). Bug: T278010 Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
* Add missing @param and @return to documentation in testsUmherirrender2021-01-221-0/+5
| | | | Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
* Add a function to HttpRequestFactory for creating a GuzzleHttp\ClientBill Pirkle2020-10-221-0/+20
| | | | | | | | | Guzzle is a vendor library included with MediaWiki, and it is sometimes useful to directly use a GuzzleHttp\Client instance. Add a function to HttpRequestFactory for this purpose. Bug: T263816 Change-Id: I35f4b911676c7a58dfa5a8dd0d104125188dd62c
* Fix GuzzleHttpRequest request headersTim Starling2020-09-211-0/+25
| | | | | | | | | | | The headers passed to Guzzle via the Client constructor are termed "conditional", meaning that headers in the Request override them. If you set a "body" option containing a MultipartStream, it sets a default Content-Type request header, overriding the one from the Client constructor. So to send a multipart stream with a custom Content-Type, it is necessary to pass headers to Guzzle in the Request object. Change-Id: Ie7bfc548ce4211fbf3ec67e3913bbdd3482977c3
* MediaWikiTestCase to MediaWikiIntegrationTestCaseaddshore2020-06-303-3/+3
| | | | | | | | | | | | | The name change happened some time ago, and I think its about time to start using the name name! (Done with a find and replace) My personal motivation for doing this is that I have started trying out vscode as an IDE for mediawiki development, and right now it doesn't appear to handle php aliases very well or at all. Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
* Respect configured default HTTP timeouts, and introduce max timeoutsTim Starling2020-05-212-13/+139
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add HttpRequestFactory::createMultiClient(), which returns a MultiHttpClient with configured defaults applied. This is similar to the recently-deprecated Http::createMultiClient(). * Introduce $wgHTTPMaxTimeout and $wgHTTPMaxConnectTimeout which, if set to a lower value than their defaults of infinity, will limit the applied HTTP timeouts, whether configured or passed on a per-request basis. This is based on the frequently correct assumption that ops know more about timeouts than developers. * In case developers believe, after becoming aware of this new situation, that they actually do know more about timeouts than ops, it is possible to override the configured maximum by passing similarly named options to HttpRequestFactory::createMultiClient() and HttpRequestFactory::create(). * Apply modern standards to HttpRequestFactory by injecting a logger and all configuration parameters used by its backends. * As in Http, the new createMultiClient() will use a MediaWiki/1.35 User-Agent and the 'http' channel for logging. * Document that no proxy will be used for createMultiClient(). Proxy config is weird and was previously a good reason to use MultiHttpClient over HttpRequestFactory. * Deprecate direct construction of MWHttpRequest without a timeout parameter Bug: T245170 Change-Id: I8252f6c854b98059f4916d5460ea71cf4b580149
* Support cookies in GuzzleHttpRequestEdward Chernenko2020-03-181-1/+45
| | | | | | | | | | | | | | | | | | Currently GuzzleHttpRequest is not sending any cookies. Furthermore, Guzzle expects its own format of CookieJar, which is not compatible with CookieJar used by MediaWiki. Solution is to add Guzzle Middleware that would obtain Cookie header from MediaWiki CookieJar and add it to outgoing Guzzle requests. Note: special handling of received cookies (Set-Cookie header from the server) is unnecessary, this is not Guzzle-specific code and is already done in MWHttpRequest::parseCookies(). Still, adding both a test of sending cookies and receiving cookies. Bug: T245644 Change-Id: If69840e65d5671989cf15450964da3c691fd164a
* Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUseJames D. Forrester2020-01-101-1/+1
| | | | Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
* Mimic CURLOPT_POST in GuzzleHttpRequestMoritz Schubotz (physikerwelt)2019-12-041-0/+22
| | | | | | | | | | | | | The MWHttpRequest is implemented by the CurlHttpRequest class and also the GuzzleHttpRequest class. However, curl based rendering set the CURLOPT_POST which implies that the 'Content-Type' header defaults to 'application/x-www-form-urlencoded'. To homgonize the functionality this patch mimics the curl behaviour in Guzzle. Bug: T232866 Change-Id: Id60a8de18e5f1e750a3bde23bd8b0deca4071165
* Merge "tests: Prefer PHPUnit's assertSame() when comparing empty strings"jenkins-bot2019-09-201-1/+1
|\
| * tests: Prefer PHPUnit's assertSame() when comparing empty stringsThiemo Kreuz2019-09-201-1/+1
| | | | | | | | | | | | | | | | assertSame() is guaranteed to never do any magic type conversion. This can be critical when accidentially comparing empty strings (a value PHP considers to be "falsy") to false, 0, 0.0, null, and such. Change-Id: I2e2685c5992cae252f629a68ffe1a049f2e5ed1b
* | tests: Prefer assertSame() when comparing the integer 0Thiemo Kreuz2019-09-191-3/+3
|/ | | | | | | assertSame() is guaranteed to not do any type conversion. This can be critical when acciden tially comparing, for example, 0 to 0.0. Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
* Split HttpTest and SessionTest to unit and integrationAmir Sarabadani2019-07-131-81/+0
| | | | | | | This way it moves 73 more tests to unit tests Bug: T87781 Change-Id: I963488450bb355573d71ae31b57d71683ce51683
* Revert "Separate MediaWiki unit and integration tests"Legoktm2019-06-132-0/+270
| | | | | | | | This reverts commit 0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9. Reason for revert: Broke postgres tests. Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
* Separate MediaWiki unit and integration testsMáté Szabó2019-06-132-270/+0
| | | | | | | | | | | | | | | | | | | | | This changeset implements T89432 and related tickets and is based on exploration done at the Prague Hackathon. The goal is to identify tests in MediaWiki core that can be run without having to install & configure MediaWiki and its dependencies, and provide a way to execute these tests via the standard phpunit entry point, allowing for faster development and integration with existing tooling like IDEs. The initial set of tests that met these criteria were identified using the work Amir did in I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory under phpunit/ and organized into a separate test suite. The environment for this suite is set up via a PHPUnit bootstrap file without a custom entry point. You can execute these tests by running: $ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml Bug: T89432 Bug: T87781 Bug: T84948 Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
* Add tests for HttpRequestFactoryTest.daniel2019-05-132-448/+120
| | | | | | | | This also moves several tests out of HttpTest, so they are not lost when the deprecated Http class is removed. Bug: T222935 Change-Id: Ib4aac96ba1a978e8b6738ed446663afc3cc8c792
* Deprecate the Http classAryeh Gregor2019-05-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | All methods got moved to HttpRequestFactory or MWHttpRequest or dropped. I made the return value of the new HttpRequestFactory::request/get/post methods null on error instead of false, so that when we drop PHP 7 support, we can use a "?string" return value. This could theoretically change behavior of code that was switched from the old Http methods, but probably won't. I kept the old behavior for the deprecated methods. I changed the default value of $wgHTTPProxy from false to ''. This way it should be usable directly without a trivial wrapper method. For the benefit of anyone who might have set it to false in LocalSettings.php, I also recommend casting to string just in case. Http::$httpEngine is deprecated. Eventually it will be removed along with the curl and PHP engines, leaving only the Guzlle engine. I also added deprecation of MWHttpRequest::factory, which occurred in 1.31, to the release notes for 1.34. Now hopefully we can hard-deprecate it in another couple of versions. Bug: T214390 Change-Id: I2a316a758d793857f248bd251b90f5e9a6440e3a
* Use https://www.php.net/ instead of https://secure.php.net/Fomafix2019-04-121-3/+3
| | | | Change-Id: I0acca592c6909e91b28b904da49dcbd6a43cd2a5
* http: Support callback functions in GuzzleHttpRequestBill Pirkle2019-01-242-16/+151
| | | | | | | | | | Provide backward compatibility for callback functions in GuzzleHttpRequest, which was missing in T202110, and restore GuzzleHttpRequest as the default provided by HttpRequestFactory. Bug: T212175 Depends-On: I4b45e79d35252d13f714f3271b87301ca515121a Change-Id: I60d1a034b44874f6d24a04058db264eeb565f5e1
* Create GuzzleHttpRequest class as new default for HttpRequestFactoryBill Pirkle2018-12-101-1/+25
| | | | | | | | | | | Create a GuzzleHttpRequest class using the external Guzzle (docs.guzzlephp.org) library. This will be the new default request type, but CurlHttpRequest and PhpHttpRequest remain available and accessible via Http::$httpEngine. Bug: T202110 Change-Id: Ie720be2628d7baf427b002847f103fd86ee4cff3 Depends-On: I143a6410d111e75f01dbbfd43f300e2e60247451
* Replace HTTP by HTTPSFomafix2018-05-221-3/+3
| | | | | | | | | | | * https://www.unicode.org/ instead of http://www.unicode.org/ or http://unicode.org/ * https://secure.php.net/ instead of http://www.php.net/ or http://php.net/ * https://hhvm.com/ instead of http://hhvm.com/ * https://www.iis.net/ instead of http://www.iis.net/ Change-Id: I84d818a7e0ced5ffb9485ec89a75efb28a77c1e0
* phpunit: Add some @covers and @large/@medium to integration testsTimo Tijhof2018-03-201-0/+1
| | | | | | | | - @small: single class, no I/O (unit test). - @medium: multi-class (partial or no mocks), no I/O (unit/integration test). - @large: multi-class, I/O allowed (integration test). Change-Id: I09317e6dd9b0ee34b7467fbffdd07957ef55dc04
* MWHttpRequest: Restore ability to pass null for $optionsKunal Mehta2018-02-061-1/+1
| | | | | | | | | | Prior to 3de744597e34, it was possible to pass `null` for $options. Restore that by setting the default type to be null, and explicitly document that null is a supported value in the doc block. Also update the signature of MWHttpRequestTester to match. Change-Id: I74d586afa5527e0a30ea99f3989f4dd12fa9fea1
* Add @coversNothing in places where @covers does not applyKunal Mehta2017-12-281-0/+1
| | | | | | | | | | | These tests apply to things that are not relevant to PHP code coverage, such as testing presence of messages, JSON files, or the PHPUnit tests themselves. Using @coversNothing indicates that there is no code here to be covered, and prevents warnings when using --strict-coverage mode (T152923). Change-Id: Id89ee2c15a3ce3f10e34b13fb677cd1af75af9e6
* tests: Use checkPHPExtension() instead of re-implementing itKunal Mehta2017-12-251-3/+1
| | | | Change-Id: I7f5e8684d556befc0aefa302187c573e7a3cff62
* Do not run tests that depend on curl if it is not loadedHuji Lee2017-09-191-0/+4
| | | | | Bug: T176193 Change-Id: Ia7b9b0196f800eb14463acc2a24df5ac1e48f3ed
* Move HttpAccept* to libsAmir Sarabadani2017-06-122-208/+0
| | | | | Bug: T163923 Change-Id: I4984f6b77843669950afeff82351827cd416a80d
* Move HttpAcceptNegotiator and HttpAcceptParser from Wikibase to coreAmir Sarabadani2017-06-102-0/+208
| | | | | | | This will be needed for implementing Special:PageData Bug: T163923 Change-Id: I2315d7dcdfa5973998917af311ebecc855b37f73
* HttpFunctions: Increase code coverageTimo Tijhof2017-03-291-41/+51
| | | | | | | | | | | | | | | * Complete coverage for Http::getProxy(). * Remove bogus @covers tag on data provider, and add the relevant MWHttpRequest::getFinalUrl to the test instead. * Convert test to use dataProvider and add missing test cases to increase getFinalUrl() test coverage to 100%. * Minor clean up in getFinalUrl to consistently use early-return for all cases, not just for relative 'domain' and 'isset-host' cases. Without this coverage actually couldn't reach 100% due to the remainder of the empty else branch never being reached (CRAP: "Redundant 'else' after 'return'") Change-Id: I775d95965dc23a1e6c4c62ed84f9da64b6c72135
* Follow-up 1e9c3619: Correct @T1234 accidental cruftJames D. Forrester2017-02-241-1/+1
| | | | Change-Id: I94e50ef3356e4e53f9a9082484dff97e49a0e2e2
* tests: Replace implicit Bugzilla bug numbers with Phab onesJames D. Forrester2017-02-211-3/+3
| | | | | | | It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345" except where it doesn't, so let's just standardise on the real numbers. Change-Id: I46261416f7603558dceb76ebe695a5cac274e417