Commit graph

7 commits

Author SHA1 Message Date
Umherirrender
167fb2a979 unit tests: Use MainConfigNames constant to refer configs
When creating ServiceOptions objects or fake HashConfigs use the
constant to refer the config name

Change-Id: I59a29f25b76e896c07e82156c6cc4494f98e64cc
2022-08-17 22:33:58 +02:00
Tim Starling
e8dbf5f80c TempUser infrastructure and services
Add services and utilities for automatic creation of temporary user
accounts on page save, in order to avoid exposing the user's IP
address.

* Add $wgAutoCreateTempUser, for configuring the system
* Add TempUserConfig service, which interprets the config.
* Add TempUserCreator service, which creates users during page save as
  requested by EditPage. With proxy methods to TempUserConfig for
  convenience.
* Add table user_autocreate_serial. Table creation is necessary before
  the feature is enabled but is not necessary before deployment of this
  commit.

Bug: T300263
Change-Id: Ib14a352490fc42039106523118e8d021844e3dfb
2022-04-14 09:23:55 +10:00
Tim Starling
97b8262d1f Use UserRigorOptions directly
Conventionally, public constants are accessed via their declaring
class, except for self:: which is an acceptable shortcut.

Change-Id: If05eab72140267e6ef54736710d751d7f24a7860
2022-03-25 10:06:34 +11:00
Ammarpad
c06dd6f667 UserNameUtils: Always strip subject namespace in canonical username.
Username with namespace prefix is not valid username. It's neither
creatable nor usable.

If the rigor validation passed to getCanonical() is not RIGOR_NONE,
this namespace prefix will always be removed by TitleParser.

We will now remove it even if the validation rigor is RIGOR_NONE
since the prefix can never appear in legal username, and its presence
will cause issues later even if the strict validation is not requested.

The validation is turned off usually when it's not known whether the
username is IP address or not, as is the case for T283915.

Bug: T283915
Change-Id: I34aa1d257f8bd90c80f40a76190a756d1e93e254
2022-02-21 22:37:44 +01:00
DannyS712
bbbc66f1ab UserNameUtilsTest: avoid duplication in testGetCanonical_interwiki
Merge as another case in provideGetCanonical now that we don't
need separate configuration because 'interwiki' is configured as an
interwiki prefix for all of the tests.

Follow-up: I3b54909e33e69fea8bb5ec55c99848c196859185
Change-Id: I5cc358be8a4f037d4bf336aeecc6fa1b157aeeb6
2021-07-28 21:20:13 +00:00
DannyS712
91ac8a717d Add UserNameUtils to DummyServicesTrait, and use it
Allows us to reduce direct mocking in individual tests, or relying
on MediaWikiServices, by having a reusable service instead that
can be used in unit tests.

Make use of it in a few places.

This dummy service is also less coupled to individual tests;
in the rest handler tests, replacing mocks that report that
only a specific string is an ip address with the actual implementation
that accepts other ip address, and in BlockUtilsTest use
an actually invalid user name instead of making the mock
UserNameUtils complain about a perfectly valid name.

Change-Id: Iaa3195002ac4ae7e0c9c58ed57c80c02762d4070
2021-07-27 12:17:06 +00:00
DannyS712
edd9ae23be Allow using MediaWikiTitleCodec with errors in unit tests
MediaWikiTitleCodec can throw MalformedTitleException,
which cannot be created in unit tests (see T281935). Until
that changes, add a helper callback
MediaWikiTitleCodec::$createMalformedTitleException
that will by default return a MalformedTitleException, but
tests can override this to return a mock.

We add this as an option to DummyServicesTrait to throw
generic `MalformedTitleException`s without regard to the
specifics of the message or parameters provided, this
can be used if no finer control is needed, or callers
can manually change the callback.

Demonstrate using it by moving the tests for UserNameUtils
to be unit tests - the only thing blocking this was the
creation of `MalformedTitleException`s.

Change-Id: I11ae4c6292465626ad1e432f7c6e9754c8ef36c2
2021-07-27 11:27:56 +00:00
Renamed from tests/phpunit/includes/user/UserNameUtilsTest.php (Browse further)