Commit graph

43 commits

Author SHA1 Message Date
daniel
bf092744c9 PHPUnit: introduce setMainCache
The main object cache is disabled during testing. Some integration tests
need it though. This provides a clean way to enable it, to replace the hacks
that were used so far.

Note that we may want to enable the main cache during testing soon. When
that happens, this method is still useful to disable the cache in certain
tests, and to set a specific cache instance.

Change-Id: I04ae1bf1b6b2c8f6310acd2edf89459d01a9c870
2022-07-07 16:25:59 +10:00
Alexander Vorwerk
3dd77b0c47 BotPasswordSessionProvider: inject GrantsInfo
MWGrants is deprecated and should be replaced with the GrantsInfo and
the GrantsLocalization services.

Bug: T253077
Change-Id: I3cbf568b6de654acb6b06b4ab5d9d97a09f78ece
2022-04-12 18:48:48 +02:00
Aaron Schulz
ff1d05f7ba phpunit: Fix slow testBotPasswordThrottled by lowering limits
Follows-up Ief9e724c84755248, which increased this
from 5 to 1000 API requests.

Bug: T298735
Bug: T225730
Change-Id: I567712f167a7264c22dd86f6005e5fa60939c752
2022-04-01 02:44:57 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +00:00
Petr Pchelko
24ae5a6318 Use CentralIdLookup service instead of static factory
Change-Id: Ia0f263b4eff00cc6efee7a88c62d562dafd57950
2021-07-26 07:00:53 -07:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Ammarpad
3953ffa1c1 ApiLoginTest: Remove testGotCookie that's been broken for 10 years
For a decade (since https://phabricator.wikimedia.org/rMWa11cf96d0688)
this test has not been executed. It's safe to assume that it's useless
now and this code is better deleted.

It still fails if re-enabled and it seems to me the reason for its
brokenness is still there, so it's simply not fixable.

Bug: T273603
Change-Id: I6887cb88ae0a2d6665b018246215855498a7ff42
2021-02-02 19:07:00 +00:00
Umherirrender
bdf8cefaf8 Make unit tests assertion about assertNotEquals more strict
Originally an autofix of PHPUnitAssertEquals sniff, but manually
updated.

Change-Id: I78efc6f7997f0b7227b40d7eab1495cc7a1d7da5
2020-11-01 23:12:06 +00:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
Brad Jorsch
f96be6f9ae api: Report Failed rather than NeedToken on session loss for action=login
This has long been somewhat confusing, and it's more likely a client
will wind up looping due to a cookie handling bug than that the session
loss is a transient failure on the server side.

Bug: T249526
Change-Id: I3430eb4cb1b6d85d6869c3d78709236f04da10a3
2020-04-06 17:28:47 -04:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Aryeh Gregor
de0143015a Use non-deprecated login in ApiLoginTest
Change-Id: I62c7bfce88aeda7ec1429493e733f868887976a9
2018-10-10 11:13:05 +03:00
Aryeh Gregor
1496fd4b4e Improve ApiLogin test coverage
Coverage is 100% except for one session-related bit that seems a bit
involved to test right now.  It looks like it will be easier once
SessionManager becomes a service.

I removed the third parameter from the return value of
canonicalizeLoginData, since af37a4c7 made it always return true.

I also removed three lines of dead code from ApiLogin.php.

Change-Id: Ia0073eddd27c82827518e0031e3c313f83cfd7cc
2018-10-10 11:11:43 +03:00
Aryeh Gregor
8435e0907b Clean up ApiLoginTest
Change-Id: Icd77f8a5ee0c26cfbd3cc8f220412cfa1bf49d60
2018-10-09 20:04:58 +03:00
Kunal Mehta
fb73286fba Add PasswordFactory to MediaWikiServices
Instead of having basically every caller do:
 $pf = new PasswordFactory();
 $pf->init( RequestContext::getMain()->getConfig() );
Just create a single PasswordFactory via MediaWikiServices and pass that
around. Things that want to use their own config can still pass settings
via the new constructor.

This will eventually let us remove the init() function, removing the
only hard dependency upon MediaWiki, to make it easier to librarize
(T89742).

Change-Id: I0fc7520dc023b11a7fa66083eff7b88ebfe49c7b
2018-08-02 14:46:35 +01:00
Aryeh Gregor
c7778c31d5 Improve test coverage for ApiLogin.php
I only made one small addition, because I don't understand login/session
code well enough to easily do more.

Change-Id: I36c5ea8e31fb00d75da24c38381f74ba8a15f31a
2018-03-21 19:57:27 +02:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
jenkins-bot
59e7337ea6 Merge "API: Remove deprecated response values from action=login" 2016-10-11 16:27:54 +00:00
Gergő Tisza
4930b32e37 API: Remove deprecated response values from action=login
Re-apply 23e5cdb after temporarily reverting in fda4d48 due to bot breakage.

Bug: T121527
Change-Id: Ia89719d8bbebb7446b9c41cc9f29ecf26c75839b
2016-10-07 04:38:24 +00:00
Gergő Tisza
af37a4c77d Fix login API for users with @ in their usernames
An @ in the username caused the password to be treated as a bot password,
but apparently some real usernames still contain it. Try both logins
instead. Security considerations are the same as for the other bot
password syntax: the length check makes sure we do not provide any
information on a timing side channel about the password unless it is
extremely long.

Change-Id: I58f42544a08c3208c41f54cfae932632d9c5affa
2016-09-14 01:47:52 +00:00
Gergő Tisza
854a462dc0 Remove $wgDisableAuthManager
Change-Id: I2b2c9693a275fcc026916bd97f303e7a5c8df341
2016-08-09 23:00:27 +00:00
Gergő Tisza
fda4d48e84 Revert "API: Remove deprecated response values from action=login"
Revert commit 23e5cdb503
temporarily so Pywikibot users can catch up with API changes

Bug: T121527
Bug: T142155
Change-Id: I3879a5d76a1727dd653daeebc79d4d9cabd0332e
2016-08-05 22:50:51 +00:00
Brad Jorsch
23e5cdb503 API: Remove deprecated response values from action=login
Bug: T121527
Change-Id: Ie370d6dc5a922ad9c50758ba81b98aa8492f83cb
2016-07-27 12:15:34 -04:00
addshore
f48f94dfcc Remove uses of deprecated TestUser properties
Change-Id: Ib44c66492e27516dfe205a5e428ebfd6b0fcdfd9
2016-06-22 16:40:31 +01:00
jenkins-bot
94117ad9c1 Merge "Speed up password-handling in the unit tests" 2016-05-18 12:46:28 +00:00
Brad Jorsch
54d58ef506 API changes for AuthManager
Changes here are:
* action=login is deprecated for use other than bot passwords
* list=users will indicate if a missing user name is creatable.
* Added action=query&meta=authmanagerinfo
* Added action=clientlogin is to be used to log into the main account
* action=createaccount is changed in a non-BC manner
* Added action=linkaccount
* Added action=unlinkaccount
* Added action=changeauthenticationdata
* Added action=removeauthenticationdata
* Added action=resetpassword

Bug: T110276
Bug: T110747
Bug: T110751
Bug: T32788
Bug: T67857
Bug: T28597
Bug: T76103
Change-Id: I244fa9b1e0623247d6d9fa30990411c6df94a496
2016-05-16 15:12:52 +00:00
Ori Livneh
61096dd7ac Speed up password-handling in the unit tests
* Speed up password generation and verification by setting MWOldPassword as the
  default password type. Do this once, in MediaWikiTestCase::makeTestConfig(),
  rather than in five different places.
* Rename '$pwhash' to '$passwordHash', for consistency. It's ugly to have both
  '$passwordFactory' and '$pwhash' in the same scope.
* Make TestUser::setPasswordForUser() check first whether the desired password
  is already set. This is actually the common case, since the password is reset
  in the setup code for every test, but only a few tests actually change the
  password.

Change-Id: I423f09ff7472b6cbde21cb709ea7c7ef9e298f18
2016-05-13 16:13:12 -07:00
Brad Jorsch
6c0abf937a Use ::class in place of string constants
This takes advantage of namespacing, and avoids having
double-backslashes all over the place.

Change-Id: I450fe4e9b1c4cf4e24fced3932fe796cbbadf3a3
2016-03-28 14:53:45 -04:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
Reedy
1834ee3d8e Fix numerous class/function casing
Change-Id: I23982bfa0548c9ea3bdb432be7982f1563930715
2016-03-18 23:14:49 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Brad Jorsch
2257fe4228 Revert "Remove SessionManager, temporarily"
This reverts commit 823db5d63dd5200d04c63da50ba6bf16f928e70b.

Change-Id: Ibb3e023e4eb6715295586dea87d0725c344a8271
2016-02-03 21:44:59 +00:00
Brad Jorsch
5083e810eb Remove SessionManager, temporarily
The plan here is to take it out of 1.27.0-wmf.12 and put it back in
1.27.0-wmf.13.

Since BotPasswords depends on SessionManager, that's getting temporarily
removed too.

This reverts the following commits:
* 6acd424e0d SessionManager: Notify AuthPlugin before calling hooks
* 4d1ad32d8a Close a loophole in CookieSessionProvider
* fcdd643a46 SessionManager: Don't save non-persisted sessions to backend storage
* 058aec4c76 MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php
* b5c0c03bb7 SessionManager: Save user name to metadata even if the user doesn't exist locally
* 13f2f09a19 SECURITY: Fix User::setToken() call on User::newSystemUser
* 305bc75b27 SessionManager: Don't generate user tokens when checking the tokens
* 7c4bd85d21 RequestContext::exportSession() should only export persisted session IDs
* 296ccfd4a9 SessionManager: Save 'persisted' flag in session metadata
* 94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
* 46a565d6b0 Avoid false "added in both Session and $_SESSION" when value is null
* c00d0b5d94 Log backtrace for "User::loadFromSession called before the end of Setup.php"
* 4eeff5b559 Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure'
* 7491b52f70 Call session_cache_limiter() before starting a session
* 2c34aeea72 SessionManager: Abstract forceHTTPS cookie setting
* 9aa53627a5 Ignore auth cookies with value 'deleted'
* 43f904b51a SessionManager: Kill getPersistedSessionId()
* 50c5256352 SessionManager: Add SessionBackend::setProviderMetadata()
* f640d40315 SessionManager: Notify AuthPlugin when auto-creating accounts
* 70b05d1ac1 Add checks of $wgEnableBotPasswords in more places
* bfed32eb78 Do not raise a PHP warning when session write fails
* 722a7331ad Only check LoggedOut timestamp on the user loaded from session
* 4f5057b84b SessionManager: Change behavior of getSessionById()
* 66e82e614e Fix typo in [[MediaWiki:Botpasswords-editexisting/en]]
* f9fd9516d9 Add "bot passwords"
* d7716f1df0 Add missing argument for wfDebugLog
* a73c5b7395 Add SessionManager

Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
2016-02-01 22:06:49 +00:00
Brad Jorsch
94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
User keeps most of its token-related methods because anon edit tokens
are special. Login and createaccount tokens are completely moved.

Change-Id: I524218fab7e2d78fd24482ad364428e98dc48bdf
2016-01-27 15:27:20 -05:00
Brad Jorsch
f9fd9516d9 Add "bot passwords"
Bot passwords are something like OAuth-lite, or Google's application
passwords: the bot can use API action=login to log in with the special
username and password, and will then be allowed to use the API with a
restricted set of rights.

This is intended to provide an easy migration path for legacy bots and
for bots on wikis without OAuth, since AuthManager is going to greatly
complicate non-interactive authentication. If OAuth is available, an
owner-only consumer would be a better choice.

Bug: T121113
Change-Id: Iaa4015e00edbfbfaedcc8b2d27a2d3fd25009159
Depends-On: I7e15331efb162275c4116bcae61f19d6b884cbe3
2016-01-12 22:37:44 +00:00
addshore
0273f2d498 Remove use of deprecated TestUser->user
Change-Id: Iec47ea2609b4d407e827cec5bf2a834b75727005
2015-08-07 17:10:26 +01:00
Chad Horohoe
c33f4de066 Profile all external HTTP requests from MW
Change-Id: Ie980b080da2ef21ec7d9fc32f1accc55710de140
2015-03-03 20:54:30 -08:00
Siebrand Mazeland
80a8a8e85c Pass phpcs-strict on some test files (5/x)
Change-Id: I690645cd8a9b1165dcc8271b201c695ea9391226
2014-04-24 18:51:45 +02:00
addshore
79e8123466 Split ApiTest class into seperate module classes
Also!
 - adds @covers tags

Change-Id: I6d4f98f75cd3c2a52c982ece6dd295a4bf84a6fa
2013-11-05 12:40:50 +01:00
Renamed from tests/phpunit/includes/api/ApiTest.php (Browse further)