Commit graph

260 commits

Author SHA1 Message Date
Umherirrender
82134d5837 tests: Migrate to IDatabase::newUpdateQueryBuilder
Bug: T353219
Change-Id: Icecc444e6b4d6d2e9f4b13cda2931b10bb753318
2024-04-14 18:48:21 +00:00
Reedy
2c0790333d tests: More use statements in auth tests
Change-Id: Ic57b19a779065a18112334d79ede395ced1a202b
2024-02-16 21:49:35 +00:00
Reedy
e94e265a93 tests: Add Tests to PHP namespacing
Change-Id: I849268172751d50292e93aa75abe8094873f56bc
2024-02-16 19:10:11 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Amir Sarabadani
2d66025fdf Drop deprecated configs $wgMinimalPasswordLength and $wgMaximalPasswordLength
Soft-deprecated since 1.26 and hard-deprecated since at least
I9776d11d4e2d184 (1.39).

Not set in production.

Change-Id: I55e4569c5a40f77a719bc7ab1924eaa706e0da53
2024-02-01 16:29:05 +01:00
Bartosz Dziewoński
4aebcfe097 Change more uses of getDBLoadBalancerFactory() to getConnectionProvider()
Some less trivial cases. Also update variable names.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: I6657d783375fac5c7fa856b884ff1fb09285e94c
2024-01-23 16:34:45 +01:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
jenkins-bot
dd4461c17d Merge "tests: Avoid dynamic properties in auth tests" 2023-11-27 20:57:00 +00:00
Umherirrender
ab5babb47a tests: Create new classes to hold dynamic properties in auth tests
Dynamic properties are deprecated in php8.2

Bug: T326478
Change-Id: Ic0c8b4653b10855796e5ab2a68898d8e9f52ca03
2023-11-24 17:26:00 +01:00
Umherirrender
d85abecc71 tests: Avoid dynamic properties in auth tests
- Set only properties defined by the class
- Use the DynamicPropertyTestHelper
- Use the existing local variables with & in closures

Dynamic properties are deprecated in php8.2

Bug: T326478
Change-Id: I7312268ecfd7c66fec72cbb2fa3df72fd1f3044c
2023-11-24 16:25:31 +00:00
Umherirrender
2eca47315f tests: Avoid dynamic properties in AuthenticationProvider Test
Deprecated in php8.2

Bug: T326478
Change-Id: I6a883d9d4bdd210e098cde90458af51857e5f136
2023-11-22 21:52:13 +01:00
James D. Forrester
4ed5ca48b1 Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessary
Bug: T342301
Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
2023-11-21 09:02:48 -05:00
Tim Starling
990acd88be Stop using nonexistent DatabaseBlock constructor options
Remove the 'user' option from the documentation and defaults. It has
been ignored since a3b4881f6f (2021, 1.37).

Fix tests which pass unknown constructor options. I found these by
temporarily patching the constructor to throw when an unknown option is
given.

Change-Id: I95cb2a38a5688d83c90ad501786f6d6bb02765ba
2023-11-06 12:03:51 +11:00
Tim Starling
cc40f0a12d Migrate callers of DatabaseBlock methods moved to DatabaseBlockStore
* Migrate callers of DatabaseBlock methods newListFromTarget,
  newFromID, newFromTarget, doAutoblock.
* Deprecate DatabaseBlock methods newFromID and getAutoblockExpiry.
  These are the methods with no extension callers in code search.

Bug: T255433
Change-Id: If0358459f53d32e7fe984c2fb8b61e0088f28922
2023-11-06 12:03:51 +11:00
Tim Starling
d06ac1a3cd Move DatabaseBlock read query methods to DatabaseBlockStore
* Move to DatabaseBlockStore the DatabaseBlock methods newFromID,
  getQueryInfo, getRangeCond, newFromRow, isExemptedFromAutoblocks,
  doAutoblock, updateTimestamp, getAutoblockExpiry, newFromTarget,
  newListFromTarget.
* Split DatabaseBlock::getBlocksForIPList. Now
  BlockManager::getBlocksForIPList() is responsible for XFF header
  validation and trusted proxy handling. DatabaseBlockStore::
  newListFromIPs() just does the queries and constructs the Block
  objects.
* In DatabaseBlockStore::newFromRow() and doAutoblock(), use the
  DatabaseBlock constructor instead of calling many setter methods. Add
  constructor options decodedExpiry, decodedTimestamp, id,
  parentBlockId and restrictions to support this.
* Move isExemptedFromAutoblocks() to its own service. Remove the cache
  since in my testing with production eval.php, the WAN cache fetch is
  10 times slower than just using the message cache, contradicting the
  comment written in 2008.
* Fix AuthManagerTest which was previously passing an unrecognised
  "restrictions" option to DatabaseBlock. Now that the option actually
  works, we have to use the right type.

Bug: T255433
Change-Id: I5049e60be1681f67fcca133e569e315792dc42dd
2023-11-03 11:00:57 +11:00
daniel
04197cb13f Introduce StatusFormatter
This takes us one step closer to deprecating Status,
so we can isolate StatusValue from presentation logic.

FormatterFactory is introduced as a mechanism for
getting instance of formatters that need access to the user interface
language and other request dependent information.

Usage is demonstrated in thumb.php, SpecialCreateAccount, and
SearchHandler. The examples indicates that there is no work do
be done around ErrorPageError and LocalizedHttpException.

Change-Id: I7fe5fee24cadf934e578c36856cc5d45fb9d0981
2023-10-27 14:56:51 +02:00
Tim Starling
66f85fa125 AuthManager: deny auto-creation for globally blocked users
* In AuthManager::autoCreateUser(), check the permissions of the
  performer instead of relying on the secondary providers. This means
  that auto-creation will be denied when the anonymous user is globally
  IP-blocked.
* Remove create account block check from
  CheckBlocksSecondaryAuthenticationProvider. testUserForCreation() is
  supposed to only do target name checks, but it's not actually
  possible to block a non-existent local name. So we don't need this
  code.
* Add a $performer parameter to autoCreateUser() so that
  Special:CreateLocalAccount can have elevated permissions when it
  creates an account with IP block exemption.
* When a performer is passed, don't use the session as a cache.
* Since we are passing autocreateaccount as the action to
  PermissionManager instead of createaccount, some special cases need to
  be tweaked. Previously AuthManager checked for either
  autocreateaccount or createaccount rights. Now PermissionManager does
  that when the action is autocreateaccount.

By removing redundant checks from testUserForCreation(), the number of
ipblocks queries during a normal Special:CreateAccount post request is
reduced from 8 to 6.

The CentralAuth change I7e7a7fc8bcd86285f857063a38de02b41b5175d0 should
be merged immediately after this one.

Bug: T234371
Bug: T345683
Change-Id: If2937c7d717d2adc249f608d4585122b02a43fff
2023-10-20 10:07:50 +11:00
Tim Starling
a588e3969d Add PermissionManager::$blockManager
PermissionManager has an extensive need for block information, and it
gets it from the global state with User::getBlock(). In the future it
should get block information from BlockManager.

However, this is complicated because BlockManager already depends on
PermissionManager, solely for ipblock-exempt rights. For now, have
BlockManager use the service container for this information.

To simplify review, the changes which use
PermissionManager::$blockManager will be in a subsequent commit.

Bug: T345683
Change-Id: I7a92eed142dcf2595cc3e2c5fa85a362c2a10d99
2023-10-19 10:15:20 +11:00
thiemowmde
a6245986bc Use short callable syntax for build-in functions like "lcfirst"
While we can wrap these in an additional `fn ()` we can also use
"lcfirst" directly. Function names encoded as strings are valid
callables in PHP.

Change-Id: I966046d5e357b409c57a9bff8a4a5737c1e22b03
2023-10-18 10:58:52 +02:00
thiemowmde
46bed8ac6d Make use of assertStatusGood/Error and such in tests
Change-Id: I11eace3d9823ca28a1d9a64f959f5f8ca2945821
2023-10-04 17:16:00 +00:00
Amir Sarabadani
cd2e19c050 tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago.

Bug: T330641
Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
2023-09-25 21:08:09 +02:00
Amir Sarabadani
c00148768c Introduce LoggingSelectQueryBuilder
To replace DatabaseLogEntry::getSelectQueryData()

Many migrations can't happen right now because of use of
ChangeTagsStore::modifyDisplayQuery() but I will fix that soon.

Bug: T344971
Change-Id: Iafb2bb5ea3a0da49da1dafb69b65dea3c15029ed
2023-09-25 15:51:24 +02:00
Amir Sarabadani
abbb4281cb tests: Migrate more cases to SQB
Bug: T344971
Change-Id: Ia69d82d6a6e623b9032240dc910fb47ff5887661
2023-09-21 18:30:37 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
dec0cf54a2 tests: Migrate more easy cases to SQB
The script couldn't find these because they were using wfGetDb(). I
fixed that and that cleaned up a lot more.

Bug: T344971
Change-Id: I5c4c5fa65c42292bfb4d870936775e598fb30719
2023-09-18 20:53:39 +02:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
jenkins-bot
fc40cf1067 Merge "Make "temp reserved" usernames not be "usable"" 2023-09-06 21:11:52 +00:00
Gergő Tisza
07cf76b090 Improve message for fatal password validity errors on login
Bug: T214215
Change-Id: I92696c6ba6b7996aecd276798b1de07b31475aae
2023-09-04 15:57:17 +00:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Tim Starling
07f1bc9f89 Make "temp reserved" usernames not be "usable"
If a username matches $wgAutoCreateTempUser['reservedPattern'], but the
username is not a valid temp user, return false from
UserNameUtils::isUsable().

This makes reserved patterns analogous to $wgReservedUsernames, and
provides a simple way to reject central sessions for temp users on wikis
where temp users are disabled.

Bug: T342475
Change-Id: I1d7f843e71e605fccf3de93fd145ff43e396619f
2023-08-25 15:06:22 +10:00
Reedy
a1144dc7c5 mark various anonymous functions as static
Change-Id: Iefe896769359f0d32e52bf20aa03e1c3715d5074
2023-08-22 19:38:38 +00:00
Umherirrender
6b9dfaa229 tests: Use namespaced MediaWiki\Request\FauxRequest
Bug: T321681
Change-Id: Id7770dd550eeb6a016b96eac25a979af8727bdaa
2023-08-20 01:54:10 +02:00
Daimona Eaytoy
2668b94a5a Do not use UTSysop directly in auth tests
These tests are all making two assumptions:
- That the sysop test account exists
- That its name is UTSysop

Both assumptions happen to be true right now, but the first one will no
longer be after change I30861742. The second one will probably remain
true for a while, but still, tests shouldn't rely on this implementation
detail when possible.

If a test needs an exiting test user, it should call getTestUser /
getTestSysop.

Use mocks or different usernames where the user actually doesn't matter,
e.g. in non-Database tests where UTSysop already doesn't exist.

Bug: T342428
Change-Id: Ie77e72f5a5ee6a2ef4ec9dceaa9044bb690f68b2
2023-08-16 00:34:30 +00:00
Thalia
13f4d6bc83 Ensure temporary users are blocked by configured IP blocks
Temporary users are blocked if their IP address is listed in
$wgDnsBlacklistUrls or $wgSoftBlockRanges.

Bug: T343704
Change-Id: Ia3383bd10c3c6c35c586550b68f4af5f4659e815
2023-08-07 14:14:54 +01:00
Daimona Eaytoy
d3243571d0 Fix DB usage in non-database tests (part 2)
Mock the relevant services that need the DB instead, when possible. When
not possible, e.g. because DB access is needed for the test to make
sense, add the test to the Database group instead.

Change-Id: Iefbfe00bedc243906c6b860572568343268646cc
2023-08-06 22:57:28 +00:00
Derick Alangi
891787e10c
Auth: Introduce several AuthManager session keys as constants
This patch introduces session keys as constants as they repeat across
this class but are the same strings. Making them as constants will ensure
they're the same across usage and avoid errors.

If we ever want to change this key in the future, we can just change the
value of the constant and no need to change all occurrences in the entire
file.

== Introduces ==
+ AUTHN_STATE
+ ACCOUNT_CREATION_STATE
+ ACCOUNT_LINK_STATE
+ AUTOCREATE_BLOCKLIST

NOTE: Constants created as public but marked as internal to be used by
relevant tests in core.

Change-Id: I49e4ea01f0f8b548e32f88653e67ba4058c8bc07
2023-08-06 12:55:40 +01:00
Tim Starling
9b3c418d01 Make tests override needed configuration
* Fix tests depending on $wgUsePigLatinVariant=true, which is in
  DevelopmentSettings.php but not TestSetup::applyInitialConfig().
* Fix test depending on DNS resolution details.

Change-Id: I877dc3323bf4024caab7666a8820103de0b48d23
2023-07-27 06:40:48 +00:00
Tim Starling
f6b1c1f84a Fix flaky test testSecuritySensitiveOperationStatus
equalTo() no longer takes a $delta parameter, so use equalToWithDelta()
instead.

Increase the delta to 2 seconds.

Add comments for readability.

Bug: T342775
Change-Id: I85c7a650a45dbdaf0645f45d1277b1e7515a06eb
2023-07-27 09:48:09 +10:00
Daimona Eaytoy
2d9b8797ef AuthManagerTest: Use localhost instead of local.wmftest.net
AIUI, the latter is vagrant-specific and doesn't work e.g. in
MediaWiki-Docker.

Change-Id: I63891b6796dbaeab63e7f34b1fddfafa5106fd1f
2023-07-16 20:26:22 +02:00
Amir Sarabadani
77342327ee tests: Migrate calls to Database::update to UpdateQueryBuilder
Bug: T330640
Change-Id: I30f9e84658fbd996b5512e96dda3f6412ebf3a20
2023-07-14 15:40:11 +02:00
daniel
c4033734db HookContainer: deprecate old hook handler formats
This reduces the acceptable forms for hook handlers to three things:
* a callable (in the form of a string, an array, or a closure)
* an object, which is expected to have a public "on" method that
  matches the hook name.
* an array containing an object spec in the "handler" key, for use
  with ExtensionRegistry.

All other forms will trigger a deprecation warning.

Bug: T339167
Depends-On: I980f2d45e6bb8c6a04058e68c758f71bbcf709de
Depends-On: Ieae405f70caa01d84602583cc214b0ee3fadc796
Depends-On: If15df4b598c02ed9bda5eea0ae89a16ebbf4f2e2
Depends-On: Id70276fa1e1821bd400dc0ae5cea722a21d524d5
Change-Id: I83bc81d1b3033c38b9313884a9c70a187fdde227
2023-06-21 11:40:10 +00:00
Umherirrender
580439e604 tests: Use MainConfigNames consts to refer config names
PasswordSalt was dropped in 2e909bcb

Change-Id: I58d2b8d4e2a235afdc8054eafdea4e85b61f03c1
2023-06-19 20:21:08 +00:00
daniel
4c90b274f7 Remove the $replace parameter from HookContainer::scopedRegister.
This parameter was unused outside core, and the functionality
was intended for testing. Removing it simplifies the code quite a bit.

Note that the $replace parameter remains functional in
MediaWikiIntegrationTestCase::setTemporaryHook.

Change-Id: Ib5b4f379fbb74d54c600040a4c90f8354f4c1c61
2023-06-14 11:00:54 +00:00
Lucas Werkmeister
5f2bfc44ce Simplify HookContainer (v2)
This reverts change I50c3d1c5df (commit b0317287bc), thus reinstating
change I7d690a1172 (commit d139eb07fe). The only change from the
original is in getHookMethodName(), additionally replacing '-' with '_'
(not just ':' and '\'). The original commit message follows:

This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Bug: T338213
Change-Id: I6efb09e314ad2b124a33a757fdda2a07ae0d8f7c
2023-06-06 12:06:23 +02:00
Lucas Werkmeister
b0317287bc Revert "Simplify HookContainer"
This apparently caused some change in how hook handlers are called (it
now calls e.g.  AbuseFilterHookHandler::onAbuseFilter-generateUserVars()
instead of AbuseFilterHookHandler::onAbuseFilter_generateUserVars()),
causing both test failures and errors on Beta.

This reverts commit d139eb07fe.

Bug: T338213
Change-Id: I50c3d1c5dfd2d7eeac59992156a8a644cf0197e5
2023-06-06 11:12:18 +02:00
daniel
d139eb07fe Simplify HookContainer
This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Change-Id: I7d690a1172af44a90b957b2274d68e51b7f09938
2023-06-04 15:36:38 +02:00
Umherirrender
d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00
jenkins-bot
0650757cc4 Merge "tests: Allow overridable data providers to be static" 2023-05-17 09:15:40 +00:00