Commit graph

147 commits

Author SHA1 Message Date
Umherirrender
eaa5679adc Check for Title::canHaveTalkPage in User::addWatch
Also check Title::isWatchable
Same for removing from the watchlist
This avoids exceptions

Change-Id: Ibb9e6906c87ffc3a3b619be59f128d9d3ed4aaba
2020-11-22 22:43:38 +00:00
Umherirrender
a9e1ec135c [UserTest] Set defaults for $wgAutoConfirmAge/$wgAutoConfirmCount
My dev wiki has some settings for these globals,
which results in broken test
1) UserTest::testGetEffectiveGroups
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'autoconfirmed'
-    1 => '*'
-    2 => 'user'
+    0 => '*'
+    1 => 'user'
 )

Change-Id: Id062c92aefdf9381d7575ece95124d62ec315aa4
2020-10-30 16:17:02 +01:00
Martin Urbanec
016d2e401c Remove NonSerializableTrait from User object
User objects are apparently serialized somewhere, removing
the trait until this gets fixed.

Remove UserTest::testSerialization_fails to
allow this change for now.

Bug: T264363
Change-Id: Id804755653452dc94184e5e481efcac3053e6535
2020-10-01 23:16:08 +02:00
daniel
dc436c3cff Introduce and apply NonSerializableTrait
The NonSerializableTrait prevents object serialization via php's native
serialization mechanism. Most objects are not safe to serialize, and
NonSerializableTrait provides a covenient and uniform way to protect
against serialization attempts.

This patch applies the NonSerializableTrait to some key classes in
MediaWiki.

Bug: T187731
Bug: T259181
Change-Id: I0c3b558d97e3415413bbaa3d98f6ebd5312c4a67
2020-09-28 21:55:49 +02:00
Clara Andrew-Wani
79afec9457 User: Use "Unknown user" for bad user id
Without this, a user created from an invalid user ID would end up
representing the current requests IP address, which may lead to
confusion. Using the reserved name "Unknown user" seems safer.

Change-Id: Icbfe7c3a561ac927713b610ac9a0b5e6b88bf2f0
2020-09-24 22:23:38 +00:00
DannyS712
8af8aaad0f UserTest: No need to set $wgUser
Bug: T243708
Change-Id: I8ba28ac21a08a7c466ad70727a21fb7a0c1a6275
2020-09-15 21:22:33 +00: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
jenkins-bot
ff51ff7fc6 Merge "user: Document User::add/removeWatch behavior on special pages" 2020-09-09 12:22:34 +00:00
daniel
f50240fe76 User: enforce pingLimiter() expiry time
This makes User::pingLimiter() include the expiry time in the payload of
the cache key that holds the current count. This allows us to ignore
stale counts.

Until now, we have been relying on the cache implementation to expire
the relevant keys in time. This however seems to fail sometimes.

Bug: T246991
Change-Id: Ifa3c558b4449f1ca133d0064781f26ac1bf59425
2020-09-03 15:57:01 +00:00
Thiemo Kreuz
fe562a64f1 user: Document User::add/removeWatch behavior on special pages
It's not the WatchedItemStore that throws this exception, but
really the methods in the User class that implement this behavior.
Hence it needs to be tested in UserTest. And documented. That was
missing before.

This patch also replaces some Title::newFromText with slightly faster
Title::makeTitle, if possible.

Change-Id: Id930a547329145c0703b4c97773a49fd78dd6332
2020-09-03 14:46:37 +00:00
daniel
e7a27f2db7 User::pingLimiter: add user-global rate limit type
"user" style rate limits can't be cross-site, since they are based on
the user ID. "user-global" uses CentralIdLookup to allow cross-wiki
rate limits.

Bug: T251661
Change-Id: Id680b96be2ea81d29447c4c1abafc8f98a339626
2020-09-02 19:38:04 +02:00
Petr Pchelko
ee5d922465 Remove hard-deprecated and unused User methods related to blocks
Change-Id: I0a4d7b5a1582f6249435cbedd49b1e414f86c4f6
2020-08-05 09:55:20 -07:00
Ammar Abdulhamid
6cbd116954 Remove selectFields User method
* Deprecated since 1.31
* Remaining call in Test replaced

Bug: T249181
Change-Id: Idb69f36a07055110fe0b7540186b23cc52dad76f
2020-07-12 15:21:48 +01:00
DannyS712
0637d80572 Hard deprecate the rest of the Revision class
Bug: T246284
Change-Id: I126d7892c90aa2200c668b5717820e729613bed8
2020-07-02 09:02:02 +00:00
jenkins-bot
a18a39f413 Merge "MediaWikiTestCase to MediaWikiIntegrationTestCase" 2020-07-01 18:39:57 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
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
2020-06-30 17:02:22 +01:00
Tim Starling
c75eef91bf Introduce $wgForceHTTPS
Add $wgForceHTTPS. When set to true:

* It makes the HTTP to HTTPS redirect unconditional and suppresses the
  forceHTTPS cookie.
* It makes session cookies be secure.
* In the Action API, it triggers the existing deprecation warning and
  avoids more expensive user/session checks.
* In login and signup, it suppresses the old hidden form fields for
  protocol switching.
* It hides the prefershttps user preference.

Other changes:

* Factor out the HTTPS redirect in MediaWiki::main() into
  maybeDoHttpsRedirect() and shouldDoHttpRedirect(). Improve
  documentation.
* User::requiresHTTPS() reflects $wgForceHTTPS whereas the Session
  concept of "force HTTPS" does not. The documentation of
  User::requiresHTTPS() says that it includes configuration, and
  retaining this definition was beneficial for some callers. Whereas
  Session::shouldForceHTTPS() was used fairly narrowly as the value
  of the forceHTTPS cookie, and injecting configuration into it is not
  so easy or beneficial, so I left it as it was, except for clarifying
  the documentation.
* Deprecate the following hooks: BeforeHttpsRedirect, UserRequiresHTTPS,
  CanIPUseHTTPS. No known extension uses them, and they're not compatible
  with the long-term goal of ending support for mixed-protocol wikis.
  BeforeHttpsRedirect was documented as unstable from its inception.
  CanIPUseHTTPS was a WMF config hack now superseded by GFOC's SNI
  sniffing.
* For tests which failed with $wgForceHTTPS=true, I mostly split the
  tests, testing each configuration value separately.
* Add ArrayUtils::cartesianProduct() as a helper for generating
  combinations of boolean options in the session tests.

Bug: T256095

Change-Id: Iefb5ba55af35350dfc7c050f9fb8f4e8a79751cb
2020-06-30 15:38:11 +10:00
jenkins-bot
9c85246254 Merge "Deprecate PasswordCannotMatchBlacklist" 2020-06-26 10:07:52 +00:00
Clara Andrew-Wani
4093985c28 Hard deprecate User::getNewtalk and User::setNewtalk
Bug: T239640
Change-Id: I7f901963ea67e8cdac1611838570ff9717d11232
2020-06-25 12:12:32 -04:00
Reedy
ece3f3306d Deprecate PasswordCannotMatchBlacklist
Bug: T254646
Change-Id: I0946d078cba5b60567ac4c804d023945bae61313
2020-06-25 14:45:34 +00:00
jenkins-bot
b5c027db01 Merge "Hard deprecate User::getNewMessageLinks" 2020-06-10 03:28:10 +00:00
DannyS712
249aa916d6 Hard deprecate User::getNewMessageLinks
Bug: T253949
Change-Id: I08d1fef9effeab420824c77f6ee7fd468ae51a3a
2020-06-10 02:02:16 +00:00
DannyS712
c595f2fd7e Remove use of the Revision object returned in WikiPage::doEditContent (2)
Each file's changes are independent and can be reviewed separately

Bug: T251853
Bug: T254952
Change-Id: Ifdc192796f0989c12fda7c0317bf2458874d6e19
2020-06-10 01:15:45 +00:00
DannyS712
f3bcc94bcf Deprecate User::getNewMessageRevisionId
Uses User::getNewMessageLinks, which uses Revision objects
Only caller updated to use a new private method

Bug: T253949
Change-Id: I04c0558916e7216540dd7bd12a2a391a1ed7660a
2020-06-05 21:36:06 +00:00
Petr Pchelko
40b88d635b Create UserGroupManager
Introduce a UserGroupManagerFactory and UserGroupManager.
The factory utilizes the same pattern as RevisionStore
for access to user groups of a foreign wiki.

Some user group related methods were ported from User
and UserGroupMembership and deprecated, more methods to
be moved over in future patches, not to make this one to large.

Eventually as all the group-related methods are moved and their
usages are replaced, the need for the UserRightsProxy will disappear,
thus it also will be deprecated and removed. Currently for backwards
compatibility, I've had to create artificial UserIdentityValue
objects in some of the deprecated methods to avoid making transitional
temporary methods in the UserGroupManager that would take user ID
instead of the UserIdentity. All of this will go away once migration
to UserGroupManager is completed.

Bug: T234921
Change-Id: If29c6a03dfdbb80b2e846243f7e384b334da9f07
2020-06-03 16:46:51 -07:00
Reedy
a8b006426e Fix tests/ PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I0beed1a35e046705fb84c9d1f63cf92afd009bb4
2020-05-16 04:30:21 +01:00
MusikAnimal
a1ddac1d54 Add methods to check if a page is temporarily watched
Add 'mw-watchlink-temp' class to watch link when temporarily watched.

Bug: T248495
Change-Id: I61b24fddf6aaf5233f426602bfa1cc4fafce942b
2020-05-13 19:11:52 +00:00
Nikki Nikkhoui
8d378e977c Update setTemporaryHook() to use scopedRegister()
The new HookContainer.php introduces a scopedRegister() method for
temporarily setting hooks. Let's use that in MediaWikiUnitTestCase
and MediaWikiIntegrationTestCase instead of directly accessing
global $wgHooks to do so.

Also introduces setTemporaryHook() and removeTemporaryHook()
methods in MWIntegrationTestCase for easily adding/removing of
temporary hooks.

Bug: T250300
Change-Id: I8cefd41b66f882c53646b76de76c51f0d8730f72
2020-05-11 14:12:00 +10:00
Petr Pchelko
c339be9ef0 UserTest::testGetNewMessageLinks pass artificial clock by reference
Change-Id: I872cb7c8e07df1aa065dceb8202d514d73c8b391
2020-05-08 07:34:45 -07:00
daniel
5c6df39131 UserTest: Ensure revisions have distinct timestamps
UserTest::testGetNewMessageLinks was sometimes failing under postgres,
when the two revisions got the same timestamp. The reason for this is
that User::getNewMessageLinks() is based on
TalkPageNotificationManager::getLatestSeenMessageTimestamp(). To
reliably test the behavior of User::getNewMessageLinks(), we need to
operate on revisions with distinct timestamps.

Change-Id: I701983c3b241a70167a6bf212c41a6571b9b0f62
2020-05-08 10:37:53 +02:00
Petr Pchelko
d6084c9dcd Fix Postgres user_newtalk table
In mysql the user_id and user_ip fields are not nullable,
but include a default 0 and '', however in Postgress the default
was not set, while user_id was set to not nullable. In the
code that uses this table, we set either user_id or user_ip
depending on whether the user is anon or registered. Thus both
fields should either be nullable, or contain a default.
Given that mysql has defaults set, I've opted for bringing
Postgress closer to what mysql does.

This was always broken and was discovered by adding new tests
for this functionality.

Bug: T239640
Change-Id: I75bf469a30225687a4b0cb550a4068cb07208c01
2020-05-04 11:17:03 -07:00
Petr Pchelko
788331c48a Introduce UserOptionsManager and DefaultOptionsManager
This converts user options management to a separate
service for use in DI context.

User options are accessed quite early on in installation
process and full-on options management depends on the
database. Prior we have protected from accessing the DB
by setting a hacky $wgUser with 0 id, and relying on the
implementation that it doesn't go into the database to
get the default user options. Now we can't really do that
since DBLoadBalancer is required to instantiate the options
manager. Instead, we redefine the options manager with
a DefaultOptionsManager, that only provides access to
default options and doesn't require DB access.

UserOptionsManager uses PreferencesFactory, however
injecting it will produce a cyclic dependency. The problem
is that we separate options to different kinds, which are
inferred from the PreferencesFactory declaration for those
options (e.g. if it's a radio button in the UI declaration,
the option is of multiselect kind). This is plain wrong,
the dependency should be wise versa. This will be addressed
separately, since it's requires larger refactoring. For now
the PreferencesFactory is obtained on demand. This will be
addressed in a followup.

Bug: T248527
Change-Id: I74917c5eaec184d188911a319895b941ed55ee87
2020-04-28 15:42:43 -07:00
Nikki Nikkhoui
7ac981a03e Set logger to null in UserTest.php
The code is appropriately logging when it encounters a database
'Duplicate entry' error. However, the CI interprets that as
an actual exception being thrown. Setting the logger to null
allows the CI to complete.

Bug: T248195
Change-Id: I6419fdb7a6ae54478da1236a3c14b491ade65022
2020-04-07 16:45:05 -07:00
DannyS712
23242d04d1 Add a new UserNameUtils service
This replaces User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonicalName, and ::isIP.

Unlike User::isIP, UserNameUtils::isIP will //not// return true
for IPv6 ranges.

UserNameUtils::isIPRange, like User::isIPRange, accepts a name and
simply calls IPUtils::isValidRange.

User::isValidUserName, ::isUsableName, ::isCreatableName,
::getCanonical, ::isIP, and ::isValidRange are all soft deprecated

A follow up patch will add this to the release notes, to avoid merge
conflicts.

Bug: T245231
Bug: T239527
Change-Id: I46684bc492bb74b728ff102971f6cdd4d746a50a
2020-03-26 01:31:14 +00:00
Thiemo Kreuz
6b2c9deef5 Replace all new stdClass() with identical (object)[]
This should be the exact same. Its more a style change than anything.
So why do it then?
* I believe this is much less confusing than code mentioning a weird
"standard class". Barely anybody knows what this is, and what the
difference between "object" and "stdClass" is.
* The code is shorter.
* It's even faster. In my micro benchmark it's twice as fast.

Change-Id: I7ee0e8ae6d9264a89b6cd1dd861f0466ae620ccc
2020-03-04 21:18:30 +00:00
Daimona Eaytoy
183edf76fd tests: Replace a very long string with str_repeat
Strings like this can make it problematic to scroll the page.

Change-Id: Ic2a5905fc64ea2d3bc1cb76746170953a671d107
2020-02-27 09:41:25 +00:00
Thiemo Kreuz
05fd10ffa9 user: Use more native PHPUnit assertions in UserTest
* Make use of assertGreaterThan() where possible.
* Use the more trivial assertSame() for arrays with only 0 or 1
  elements.
* Flip a few assertions where the expected and actual value have been
  flipped.
* Remove some unused function arguments.

Change-Id: I1d3b5dd55736931fa484065a4aa8d7e336980682
2020-02-20 08:24:00 +01:00
jenkins-bot
bd9bef8add Merge "Use existing $this->user property in UserTest where possible" 2020-02-20 01:35:12 +00:00
Thiemo Kreuz
59f9effce1 Use existing $this->user property in UserTest where possible
Change-Id: Id9fd3dfe4a5c37ec8641f53bce466f4592d47b47
2020-02-17 09:39:01 +01:00
DannyS712
3b0f44970b Add more tests for the user class
Added tests for:
* ::setEmailWithConfirmation
* ::newFromSession, ::getRequest
* ::validateCache, ::getTouched
* ::logout
* ::newFromRow, ::loadFromRow

Fix coverage doc for ::getOptions
Cover missing edge case for ::addGroup

Bug: T233385
Change-Id: I7d6a9718a272be5bd3ef2d135b43f1ae3ed768fa
2020-02-15 02:33:39 +00:00
DannyS712
989c4f7723 Add more tests for the User class
Methods newly tested:
* ::isAllowedAny, ::isAllowedAll, ::isAllowed, ::isNewbie
* ::pingLimiter (basic testing)

Testing expanded for:
* ::checkPasswordValidity
* ::testRealName

Bug: T233385
Change-Id: I2848ecc401b55e4202a853f270f084a093ed46e4
2020-02-11 01:57:04 +00:00
DannyS712
fc9671bdf5 Add more tests for the User class
Newly tested:
* ::getDefaultOption
* ::isCreatableName, ::isUsableName
* ::addToDatabase
* ::changeableGroups
* ::isBlockedFromUpload

Testing expanded for (mostly just specific edge cases):
* ::getIntOption, ::getId, ::getDefaultOptions
* ::addGroup, ::removeGroup
* ::newFromConfirmationCode
* ::idFromName
* ::findUsersByGroup

Bug: T233385
Change-Id: I12bdcffcc6af96da4425e0064f8d395153d05953
2020-02-04 21:14:26 +00:00
DannyS712
0e301253f1 Add more tests for the user class (factory and preferences mostly)
Add tests for
* ::newFromId, ::newFromConfirmationCode
* ::getStubThreshold, ::requiresHTTPS
* ::setItemLoaded, ::isItemLoaded
* ::getGroupMemberships

Expand tests for
* ::getCanonicalName

Bug: T233385
Change-Id: I2c47590e1cef35387aa376303ebfa09e54c0cc34
2020-02-02 07:55:06 +00:00
DannyS712
262501f064 Add more tests for the user class (email and username related mostly)
Add tests for
* ::setId
* ::getName, ::setName
* ::getEmail, ::setEmail, ::invalidateEmail
* ::whoIs

Expand tests for
* ::newFromName

Add coverage tag for ::getDBTouched

Bug: T233385
Change-Id: I565cbc0660d7a9fb16e02595598003228f6fb238
2020-01-27 01:40:57 +00:00
sbassett
b86c6751d0 Password policy to check if a password is a substring of a username
Similar to checkPasswordCannotMatchUsername, MediaWiki should ensure
that users are unable to accidentally create or edit their username
to include their password as a substring of said username.

Bug: T241845
Change-Id: I437e91a5b83a792c5ad31e291915491bbb382dfa
2020-01-13 23:09:13 +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
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
DannyS712
1fcb8a1396 Expand options-related tests for User class
Bug: T233385
Change-Id: I8ef7331eba11a9d275699da6a972fe58b40983f6
2020-01-02 17:05:07 +00:00
jenkins-bot
c14a3ca034 Merge "Expand watchlist-related tests for User class" 2019-12-19 09:32:56 +00:00
Daimona Eaytoy
7b946ffb4b Fixes for PHPUnit 8 compat in DB suite
Once again, this fixes all issues aside from assertArraySubset.

Bug: T192167
Change-Id: I45c91dc1cf23f04140576dc66233558bb6021324
2019-12-15 00:27:54 +00:00