Commit graph

50 commits

Author SHA1 Message Date
Tim Starling
a5372218b7 block: Deprecate and stop using $wgBlockTargetMigrationStage
* Deprecate and stop using $wgBlockTargetMigrationStage. Remove
  block_target migration code.
* Make the $schema parameters to DatabaseBlockStore methods default to
  SCHEMA_BLOCK. Avoid passing these parameters where possible.
* Remove cleanupBlocks.php
* Deprecate DatabaseBlock static methods which try to present the old
  schema for b/c.

Bug: T362133
Change-Id: I845bad8cc09a4528fef46a6f9d490ebdec881d99
2024-05-10 15:54:17 +10:00
Tim Starling
2998d9bd47 block: Migrate to the new block schema on non-WMF wikis
Migrate from ipblocks to block/block_target and drop the ipblocks
table. Update tests.

In PostgresUpdater, change some schema update functions to skip field
updates if the table doesn't exist, by analogy with
DatabaseUpdater::modifyField.

Bug: T346293
Change-Id: Icf91b35f7f729cead7c800429653eb30731762a1
2024-05-09 10:14:43 -04:00
jenkins-bot
d9f0f2f8e2 Merge "tests: Migrate to IReadableDatabase::newSelectQueryBuilder" 2024-05-03 05:10:13 +00:00
Umherirrender
fe5a3ebd1f tests: Use IDatabase for mocking instead of DBConnRef
DBConnRef is internal, use of IDatabase interface is more common

Change-Id: Id7649d0723a936cebc7e5a40bf826e38220acee5
2024-05-02 22:11:12 +00:00
Umherirrender
6f94bde337 tests: Migrate to IReadableDatabase::newSelectQueryBuilder
Bug: T344971
Change-Id: Ic6940fcc06225069a0c3618c22a0e62942e5dd88
2024-05-02 23:42:08 +02:00
Amir Sarabadani
8e183495e1 Stop using LoadBalancer::getConnectionRef() so it can be hard-deprecated
Bug: T326274
Change-Id: I90493d7cd4c21fdc022bcc19765fc04d986a9c8f
2024-04-30 13:31:08 +01:00
Dreamy Jazz
102424bfb3 Update wgAutoCreateTempUser config defaults
Why:
* The default value of wgAutoCreateTempUser has not changed since
  the decision to use a different prefix for temporary accounts
  (T332805).
* The default needs to be updated to reduce the number of overrides
  in operations/mediawiki-config and also to make the development
  experience more consistent with what is happening on WMF
  production.

What:
* Update the wgAutoCreateTempUser default in the following ways:
** Set expireAfterDays as 365
** Set notifyBeforeExpirationDays as 10
** Set genPattern and reservedPattern to '~$1'
** Set matchPattern to null, which will mean that the genPattern
   is used as the value.
* Update RealTempUserConfig::getPlaceholderName to add the year to
  the placeholder name so that if the match pattern includes the
  first digit of the year, then the placeholder name still is
  considered a valid temporary account username.
* Replace modifications of the wgAutoCreateTempUser config in
  integration tests with a use of the TempUserTestTrait to make
  the code cleaner and make it easier to find tests that relies on
  the values in wgAutoCreateTempUser.
* Update multiple tests to handle the new defaults for the config.

Bug: T359335
Change-Id: Ifa5a0123cd915bdb7c87e473c51fb93321622f12
2024-04-03 16:25:47 +00:00
jenkins-bot
c5c3c1c692 Merge "tests: Remove cleanup of blocks, done by ChangedTablesTracker" 2024-01-20 15:40:45 +00:00
Umherirrender
723c10d6dc tests: Improve DatabaseBlockTest::addDBDataOnce
Use the normalized data in the block list and
avoid user handling to speed up test

Change-Id: Ide5aa5353b9f3e5c1c004212248ab4d8c884eb94
2024-01-20 11:50:26 +01:00
Umherirrender
16a436ce6c tests: Remove cleanup of blocks, done by ChangedTablesTracker
In DatabaseBlockTest changed from addDBDataOnce() to addDBData() as
ChangedTablesTracker cannot reset tables changed by addDBDataOnce()
between each test run.

Remove also User::clearInstanceCache done together with the deletion as
the TestUser class is calling this already between tests.

Change-Id: Ibd5e544138a2a9b554abc2dea54a5db38f9a828f
2024-01-20 11:41:15 +01:00
Alexander Vorwerk
e838ef9773 Don't allow passing a db to DatabaseBlockStore::insertBlock
Bug: T291849
Change-Id: I5f5cec791eb2999d7295440248f74fba79156b6f
2024-01-01 14:23:24 +01:00
Martin Urbanec
c9908da103 IP Masking: Expire temporary accounts in 1 year
Why:
Temporary accounts (introduced as part of IP Masking)
are supposed to expire 1 year after their registration.
Automatic account expiration can be done via a maintenance
script, which would be periodically executed via cron / systemd.

Make it possible for extensions to provide their own logic
for generating a list of temporary accounts to invalidate.
This is used in CentralAuth to base registration timestamp
on the global registration timestamp.

The default behavior is "temporary accounts do not expire",
given the feature requires a maintenance script to run
periodically, which will not be the case on third party
instances.

What:
* Add `expireAfterDays` to $wgAutoCreateTempUser, controlling
  how many days temporary accounts have.
* Add UserSelectQueryBuilder::whereRegisteredTimestamp(),
  filtering accounts based on user_registration.
* Add ExpireTemporaryAccounts maintenance script, which is
  @stable to extend.

Bug: T344695
Change-Id: If17bf84ee6620c8eb784b7d835682ad5e7afdfcc
2023-11-09 15:11:48 +01:00
jenkins-bot
5a7226f41d Merge "Stop using nonexistent DatabaseBlock constructor options" 2023-11-06 21:41:01 +00:00
jenkins-bot
b011c84294 Merge "block,Permissions: Blocks should not apply to implicit rights" 2023-11-06 17:31:40 +00:00
daniel
898d11f9b7 block,Permissions: Blocks should not apply to implicit rights
Implicit rights represent actions granted to all users.
They can be rate limited, but not revoked.

Bug: T350202
Bug: T350117
Bug: T350347
Change-Id: I22bf5e60c38900f881d43577351761827066a25c
2023-11-06 17:06:47 +00: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
9e7c9c13b9 Multiblocks preparation in User::getBlock(), PermissionManager and BlockManager
Functional changes:

* On account creation, if both a user block and an IP block apply,
  return a CompositeBlock instead of picking a winner.
* On other actions, instead of returning the whole CompositeBlock if
  some part of it matches the specified page and action, filter the
  individual parts of the CompositeBlock by whether or not they match.

Refactoring:

* Add BlockManager::getBlock(), which is the same as getUserBlock()
  except that it expects the caller to do IP exemption checking.
  Deprecate getUserBlock().
* Migrate some callers of User::getBlock() to use BlockManager.
* Have PermissionManager use BlockManager instead of
  User::getBlock().
* Add $request parameter to PermissionManager::getApplicableBlock(),
  to fix the weird bundling of the request with the User.
* Move the createaccount block database fetch from PermissionManager to
  BlockManager, where it can easily be cached.
* Fix code duplication between PermissionManager::isBlockedFrom() and
  PermissionManager::getApplicableBlock() by having the former call the
  latter.
* In CheckBlocksSecondaryAuthenticationProvider, use
  AuthManager::getRequest(). Previously it used the global request and
  also User::getRequest() via User::getBlock().

Bug: T345683
Change-Id: Icd75025665282a34d8854bda267a0eb3d759719c
2023-10-20 10:07:50 +11: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
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
jenkins-bot
65ca23c095 Merge "Ensure that soft blocks block temporary users" 2023-08-17 10:32:07 +00:00
Daimona Eaytoy
234d5ed105 Fix tests not properly cleaning up the DB
- UserEditTrackerTest: determine whether to create the page based on
  WikiPage::exists() instead of a method parameter. The current
  implementation only works because the page is not deleted between test
  runs, and the creation query is ignored. However, if the first call to
  `editTrackerDoEdit` doesn't have $create=true, tests would fail. For
  instance, testGetEditTimestamp would fail when run on its own because
  the revision cannot be inserted if the page doesn't exist. Just use
  WikiPage::exists instead of forcing callers to handle this correctly.
- DatabaseBlockTest: use addDBDataOnce instead of a DIY implementation.
  This also makes the tests more deterministic, because the records
  needed by the test class are created immediately. Also avoid redundant
  User::addToDatabase and ::saveSettings, these are already done by
  TestUser.
- PageRestrictionTest: avoid Title::newFromID which is not guaranteed to
  succeed if all pages have been deleted by that point. The second part
  of the test was effectively doing the same thing as the first part, so
  just remove it.
- WikiPageDbTest: avoid expensive page deletions in tearDown. These are
  all unnecessary because the DB is cleaned up after each test (and
  'page' is explicitly included in $tablesUsed). In fact, deleting test
  pages as done there can be even worse than not doing anything, because
  it creates log entries etc. Add page_restrictions to tablesUsed as
  that's not truncated automatically.
- DBSiteStoreTest: testReset would fail when run on its own because it
  depends on test sites being inserted in testGetSites. Make the test
  add the sites it needs, so that they can safely be cleared between
  test runs.

Change-Id: I1065fb3e8507b4b1a3bf185181f2f3059a97fd04
2023-08-16 01:05:11 +00:00
Thalia
3eff3be2a4 Ensure that soft blocks block temporary users
Why:

* A soft block against an IP address does not block logged-in
  users, but it should block temporary users, otherwise anonymous
  users can circumvent it by creating a temporary account.

What:

* Return a block for a temporary user if a soft block is found
  against their IP address, from DatabaseBlock::newLoad
* Return soft blocks for temporary users in
  BlockManager::getXffBlocks
* Update documentation to make clear that soft blocks apply to
  temporary users, including where they are referred to as
  anon-only blocks

Bug: T343714
Change-Id: I5a2928eb3370bd47544b164b08014ef62297ce36
2023-08-15 14:26:44 +01:00
Daimona Eaytoy
1c6e872bd4 Replace usages of deprecated MWException
Use SPL exceptions instead when the exception is unchecked.

Bug: T328220
Change-Id: Ia1e5edc2ef3269a44b670262b78b305d07559829
2023-06-06 17:05:32 +02:00
Alexander Vorwerk
31d063ca71 Deprecate passing a db to DatabaseBlockStore::insertBlock()
Instead of passing a custom database to DatabaseBlockStore::instertBlock
callers should rather just fetch a correct DatabaseBlockStore
using the new DatabaseBlockStoreFactory service.

Bug: T291849
Change-Id: Ia1319f35bbc5bd786d1d96d330f94255d7b3582a
2023-05-20 11:02:45 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
libraryupgrader
b70581e4ca
build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 38.0.0 → 39.0.0
  The following sniffs are failing and were disabled:
  * MediaWiki.PHPUnit.AssertEmpty.AssertEmptyUsed

* php-parallel-lint/php-console-highlighter: 0.5 → 1.0.0
* php-parallel-lint/php-parallel-lint: 1.3.1 → 1.3.2

npm:
* grunt-banana-checker: 0.9.0 → 0.10.0
* grunt: 1.5.2 → 1.5.3
* karma: 6.3.15 → 6.4.1
* async: 2.6.3 → 2.6.4
  * https://github.com/advisories/GHSA-fwr7-v2mv-hh25
* got: 11.8.3 → 11.8.5
  * https://github.com/advisories/GHSA-pfrx-2q88-qq97

Change-Id: I1d7bc9c9599b48d2bd837617cad409a31adb362a
2022-10-07 21:09:37 +03:00
Umherirrender
dee77e59a1 tests: Remove resetServiceForTesting after overrideConfigValues
overrideConfigValues is documented to reset services as well

Change-Id: Ie13a699f6cd912b912d34adb97704bab3cbdff2d
2022-07-27 23:08:27 +02:00
Derick Alangi
86d4a253e7 tests: Migrate setMwGlobals() to overrideConfigValue(s)()
Directories covered are: /api/, /auth/ and /block/, more to come.

Change-Id: I9dfb0773cbfff36cba7389ed2d9b3c7b1b22612e
2022-07-19 15:42:15 +01:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Alexander Vorwerk
91a59f1a11 DatabaseBlock: fetch a database connection for the correct wiki
Bug: T274817
Bug: T299655
Co-authored-by: Taavi Väänänen <hi@taavi.wtf>
Change-Id: I99700e9c562635d52f2350703f46f07a39eb349f
2022-01-20 20:23:56 +00:00
Alexander Vorwerk
b6793e47de Make Block objects aware of which wiki they belong to
Bug: T274817
Depends-On: I1c46c712a3afefce56238108cb2e78382dd41956
Change-Id: I8ae8133f7e232cc75aae6b72fcd7feaeb313cba7
2022-01-17 21:49:20 +01:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00: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
vladshapik
e991dff925 Hard-deprecate AbstractBlock::getTargetAndType() and getTarget()
Replace all uses of AbstractBlock::getTarget with
Block ::getTargetName and ::getTargetUserIdentity.
Create AbstractBlockTest and two test cases for
AbstractBlock::getTarget and ::getTargetAndType.
It tests triggering of the deprecation warning.

Bug: T282247
Depends-On: I0543f363af66c57f5763b91320d87a69f23f9466
Change-Id: Iaeca824cac30172178de72f3cf7b7ae4cdd6f880
2021-06-22 16:59:00 +03:00
Roman Stolar
67cc77312f Update DatabaseBlock construct option 'by' and 'byText' usage to use User Identity only
Bug: T283641
Change-Id: Ic6d4a6e10bda0115c87a85d8a9ddfd4098cd1373
2021-06-02 17:01:32 +03:00
daniel
753b1bcaff Introduce Block interface and replace AbstractBlock.
In order to allow Authority to know about user blocks,
we need a narrow interface to represent such blocks.

This deprecates some methods on AbstractBlocks in favor
of new methods on the Block interface that avoid binding to
the User class.

Bug: T271494
Change-Id: I7bb950533970984a014de0434518fbbefb695131
2021-05-11 11:36:11 +02:00
Petr Pchelko
42b727f159 Relax AbstractBlock typehints to UserIdentity where possible
Change-Id: Ia975f44a05567561b1cdc417735b124e568b2ece
2021-03-22 16:12:21 -06:00
Thalia
addb098c39 Deprecate DatabaseBlock methods moved to DatabaseBlockStore
Following 23c3c70d7f, soft deprecate the static methods on
DatabaseBlock that have been moved to DatabaseBlockStore:
* ::insert
* ::delete
* ::update
* ::purgeExpired

Update calls to the deprecated methods from core.

Change-Id: I1272eb978594fd4f386bda12cbc24131ad7d882f
2020-09-13 22:17:27 +00:00
Thalia
ccbbad4a91 Fix some typos in block test comments
Change-Id: I81eb1a49f4bff85256dcc123abb48541020f7b8a
2020-08-30 18:05:36 +01:00
Thalia
dc4ff4f5b4 DatabaseBlock: Deprecate some obsolete methods
Deprecate deleteIfExpired, chooseBlock and fromMaster, which are
unused.

deleteIfExpired, called internally, appears unused since
b3c844133a.

fromMaster, an internal getter/setter for the mFromMaster property,
is unused since newLoad was refactored in
a387a375a1.

chooseBlock is unused since the introduction of CompositeBlock in
1eaf65d0a5.

Change-Id: I9db6d989e3138b3e0cbf6315ecbf2f8793a37bd6
2020-04-15 20:35:48 +01:00
Thiemo Kreuz
e1dd371e11 Make use of PHPUnit's assertCount feature where possible
… and avoid assertEmpty() on arrays, in favor of a much more strict
assertSame( [] ).

Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
2020-03-02 15:58:41 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Kunal Mehta
99007e96c7 Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
2020-01-01 02:36:49 -08:00
Tchanders
a6533885b8 Revert "Revert "Store block reasons as CommentStoreComments in block classes""
This reverts commit 5f06efb318, which
reverted 9335363789, which makes
the deprecated property AbstractBlock::mReason private.

After 9335363789, AbstractBlock::mReason is obsolete, since the block
reason is now stored as a CommentStoreComment, AbstractBlock::reason.

Change-Id: Ica0a74be90383689ca8e4cfe6d0fb25c9a5942c5
2019-10-20 10:41:17 +01:00
Daimona Eaytoy
5f06efb318 Revert "Store block reasons as CommentStoreComments in block classes"
This reverts commit 9335363789.

Reason for revert: It's full of code accessing AbstractBlock::mReason
out there, see [1]. Also, it was never hard deprecated. While that may
be acceptable under some circumstances, it's definitely not OK to remove
code when there are consumers around. I'd have fixed it right now without
reverting if it were a single repo, but there's just too many.

[1] - https://codesearch.wmflabs.org/search/?q=-%3EmReason&i=nope&files=&repos=

Change-Id: I8669f502b50cff89e28dada0f65fe2b130ae9b37
2019-10-19 18:55:45 +00:00
Thalia
9335363789
Store block reasons as CommentStoreComments in block classes
AbstractBlock::setReason now accepts a string, Message or
CommentStoreComment. The CommentStoreComment is accessed via
AbstractBlock::getReasonComment.

AbstractBlock::getReason returns the reason as a string, with
the language and format consistent with how block reasons were
built before this commit. This method is deprecated, since it
makes assumptions about the language and format needed. The
deprecated mReason property is no longer public.

Doing this (and T227005) will remove the implicit dependency of
BlockManager::getUserBlock on language, which causes a recursion
error if the block is checked before the user has loaded. It also
provides a mechanism for getting the block reason in a language
specified by the caller. (This does not apply to DatabaseBlock
reasons entered via the Special:Block form, which were not and
are still not translatable.)

This commit also updates authentication classes to return the
translated reason.

Bug: T227007
Change-Id: Iec36876e930dff96a256aebbdc39cbfb331c244e
2019-10-18 17:47:56 -04:00
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
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
2019-09-19 15:35:23 +00:00
Thalia
e65a5b5882 Rename Block to MediaWiki\Block\DatabaseBlock
Keep Block as a deprecated class alias for DatabaseBlock.
Update calls to the Block constructor and Block static
methods from external classes.

Also update documentation in several places that refer to
blocks as Blocks.

Bug: T222737
Change-Id: I6d96b63ca0a84bee19486471e0a16a53a79d768a
2019-05-28 12:20:48 +01:00
Renamed from tests/phpunit/includes/BlockTest.php (Browse further)