Commit graph

42 commits

Author SHA1 Message Date
DannyS712
791e890fd5 AuthManager: inject more services
- BotPasswordStore
- UserFactory
- UserIdentityLookup
- UserOptionsManager

Bug: T265769
Bug: T141495
Change-Id: If220a25b8dfc9105faee5c04ea17ae8487b275f0
2021-08-05 21:31:02 +00:00
Alexander Vorwerk
84b8655fb5 AuthManager: inject remaining services
Bug: T141495
Change-Id: Ibb549da3ebc2a9cb7709aaaa31407066361cbaa2
2021-07-30 16:09:24 +02:00
Alexander Vorwerk
b55eb734e2 AuthManager: stop injecting unused BlockErrorFormatter service
last usage was removed in I8d223508ccec7122eef5e0bf136964ad65d64ab7

Bug: T141495
Change-Id: I3cf9d16364b7c5c122c2cc2507ab59fa51283e02
2021-07-23 15:42:24 +02:00
Vlad.shapik
9763c48d17 Reapply "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName""
This reverts commit ecf826a2ee.

Reason for revert: need to edit the patch and then it will be GTG in order to finish hard deprecating of User ::getCanonicalName, ::isUsableName, ::isCreatableName

Change-Id: I2f57f56728fcbeada96dc2228f07dc8bcaa5d4f6
2021-05-31 16:01:36 +03:00
vladshapik
f4627f064c Create AuthenticationProviderTestTrait to facilitate testing of an AuthenticationProvider
Create new AuthenticationProviderTestTrait and AuthenticationProviderTestTrait
::initProvider method. Replace uses of AbstractAuthenticationProvider::init with new method in
tests.

Bug: T282781
Change-Id: Ie65c7558bfbacbf6678eea77e4a9b2cf68026456
2021-05-25 16:14:39 +03:00
DannyS712
e11939f1d0 Inject load balancers into some authentication providers
Change-Id: Ie2407cdebf1bf565b0db2f0a6bd0f5dec043a1b9
2021-05-10 16:56:32 +00:00
Ppchelko
ecf826a2ee Revert "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName"
This reverts commit b491279268.

Reason for revert: caused CentralAuth tests to fail.

Change-Id: Icb3ed094578df427622e0da2a7462645adcc3d6f
2021-05-05 02:14:47 +00:00
vladshapik
b491279268 Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName
Bug: T275030
Change-Id: I60689ee6519c2dbd6d000afa8ac05c3e6b7895d2
2021-05-04 21:20:50 +03: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
vladshapik
3a150275de Implement injecting of dependencies to an AuthenticationProvider
init() method was added to AuthenticationProvider. It helps to inject
dependecies. Overridable postInitSetup() method was added to
AbstractAuthenticationProvider. A provider can override this to do
any necessary setup.
AbstractAuthenticationProvider ::setLogger(), ::setManager(), ::setConfig(),
::setHookContainer() were soft deprecated. Now developers must use
AbstractAuthenticationProvider::init().

Bug: T275030
Change-Id: I6ca63eddac1b177eeadbdcce992e71c44a480160
2021-04-26 15:17:34 +03:00
Thiemo Kreuz
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02:00
Cindy Cicalese
ce6a4ef45e Use WatchlistManager in auth classes
Change-Id: Ib8d338bc0b167277f36ab6c5d45c98c35e4a9ba9
2021-04-21 02:48:31 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Petr Pchelko
c44d44639b Make stricter type checks on user email and real name
Currently both email and real name are documented as
non-nullable, but it seems there's code that breaks
this contract. Try stricter type checks.

Depends-On: Ie8fa1e7881e1b016dccdc9097a1763a07cc140b9
Depends-On: Id3bf35fe56c459597ed6a602bdf6ca4860271f6e
Change-Id: I2f4b7b3500a2b25f7d5cf25147f65ad412d61955
2021-04-01 15:21:41 -06:00
Petr Pchelko
2ebb44eac4 Convert AuthManager to Authority: step 1.
Cut the explicit dependency on PermissionManager
and rely on the fact that User implements Authority.

There's still a few ends we need to cut before converting
the method parameters to Authority, but that can be done
in followup steps.

Bug: T273510
Change-Id: I69617e624f47944f8a383d0b28885678c1249f23
2021-02-22 15:40:37 -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
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
Umherirrender
64b8d8ad42 Inject BlockManager and BlockErrorFormatter into AuthManager
Change-Id: Icf5a68fa9477bb30afd6f3dd32d96ae44e95fed2
2020-10-30 14:52:08 +01:00
Umherirrender
8d71235c20 Use UserNameUtils in AuthManager
Bug: T141495
Change-Id: I1c1cb5bf9807ee18e3cc4be84f8a3d6a52959add
2020-10-15 20:11:23 +02:00
Umherirrender
aeb7e6d615 Inject ReadOnlyMode service into AuthManager service
Bug: T141495
Change-Id: I54178452c5166cc28081e8fbf2d470fad98a739d
2020-10-13 19:31:05 +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
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +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
Nikki Nikkhoui
0adc5f3428 Hook Container
New classes and modificatons to existing classes to support the new Hooks system. All changes are documented in RFC https://phabricator.wikimedia.org/T240307.

- HookContainer.php: Class for doing much of what Hooks.php has historically done, but enabling new-style hooks to be processed and registered. Changes include new ways of defining hook handler functions as an object with defined dependencies in extension.json, removing runWithoutAbort() and addit it to an $options parameter to be passed to HookContainer::run(), being able to decipher whether a hook handler is legacy or non-legacy style and run them in the appropriate way, etc.
- DeprecatedHooks.php: For marking hooks deprecated and verifying if one is deprecated
- DeprecatedHooksTest.php: Unit tests for DeprecatedHooks.php
- Hooks.php: register() will now additionally register hooks with handlers in new HooksContainer.php. getHandlers() will be a legacy wrapper for calling the newer HookContainer::getHandlers()
- MediaWikiServices.php: Added getHookContainer() for retrieving HookContainer singleton
- ExtensionProcessor.php: modified extractHooks() to be able to extract new style handler objects being registered in extension.json
- ServiceWiring.php: Added HookContainer to list of services to return
- HookContainerTest.php: Unit tests for HookContainer.php
- ExtensionProcessorTest.php: Moved file out of /unit folder and now extends MediaWikiTestCase instead of MediaWikiUnitTestCase (as the tests are not truly unit tests). Modified existing tests for ExtensionProcessor::extractHooks() to include a test case for new style handler

Bug: T240307
Change-Id: I432861d8995cfd7180e77e115251d8055b7eceec
2020-04-17 15:48:38 +10:00
DannyS712
909f0bef6e Replace calls to Title::getUserPermissionsErrors (part 5)
This does //not// fix all calls in core.

Bug: T244929
Change-Id: I02ffcca31fa0bdc6bffddf21e82f4ff5e9ab5374
2020-02-26 03:00:33 +00:00
Gergő Tisza
8a08f2a806
Use dependency injection for AuthManager and allow it for providers
Change-Id: Icf3345bec993f8cb103f065e76b04fe1f3521639
2020-02-19 01:18:16 -08: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
Max Semenik
d1604f7445 Mention requiring email address in password reset emails
Bug: T233969
Change-Id: Ife55911370bb672e25a6694d4cbbbfb7eeb9645b
2019-10-23 13:38:17 -07:00
Umherirrender
2fcaf74be7 Enable email in TemporaryPasswordPrimaryAuthenticationProviderTest
Change-Id: I1bc01a3634d11c56292881be7e6477e37ac61d03
2019-05-11 10:34:25 +00:00
Alangi Derick
b86593a2da Fix undefined NS with @covers tags in /includes/auth/
Should MW Codesniffer also handle these as well?

Change-Id: Ieb493bddd5f3674fb889b4a780d51b50d89c4f65
2018-11-01 12:48:52 +01: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
Umherirrender
9cd5a3fccf clone keyword must not be used as a function
Also changed a require_once

Change-Id: Ib8030ea5320a62ee4f114d8d506382c5665e3e02
2017-06-28 16:29:33 +02: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
Timo Tijhof
447ce7e39a phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat
The default will remain PHPUnit 4.x due to PHP 5.5 support.

But, we should allow developers to run tests with newer PHPUnit
versions which are noticably faster (especially for code coverage
reports).

* <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0>
  PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock().
  It instead introduces the shortcut createMock() which has better defaults
  than getMockBuilder(). For example, it sets 'disableArgumentCloning' and
  other things by default.

  Going forward, code should either use getMockBuilder directly and configure
  it using the setter methods (instead of the confusing variadic arguments
  of getMock) or simply use the new minimalistic createMock method. This patch
  backports the createMock method to MediaWikiTestCase so that we can start
  using it.

Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
2017-04-06 00:44:32 +00:00
jenkins-bot
d6dcf23a8f Merge "Get ConfigFactory & MainConfig from MediaWikiServices" 2016-11-24 18:08:36 +00:00
addshore
b12086b618 Get ConfigFactory & MainConfig from MediaWikiServices
Change-Id: Iafdd7e00747060572463ffb05aae4543f3a06163
2016-11-23 00:12:38 +00:00
Brian Wolff
f12a3edff7 Remove passwordreset capture feature
If anyone wants such a thing, they can make their own extension.

I asked stewards, and they said they don't use this.

See also T32636 / 9de2bfd1fe

Bug: T150930
Change-Id: I3ab5962dba668e5d628e55ad0c0feae471d82b5e
2016-11-23 00:02:33 +00:00
umherirrender
34fe90ac52 Remove empty lines at end of functions
It looks like there is something missing after the last statement
Also remove some other empty lines at begin of functions, ifs or loops
while at these files

Change-Id: Ib00b5cfd31ca4dcd0c32ce33754d3c80bae70641
2016-11-05 11:55:10 +01:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Brad Jorsch
9e5e48b028 Clean up use of UTSysop in TemporaryPasswordPrimaryAuthenticationProviderTest
No idea what's causing T146498, but maybe this cleanup will fix it.

Note we can't clean up every use because we can't create test users from
data providers.

Bug: T146498
Change-Id: I5c7ea7f49ed42cb2ed36460afcf6aec30e9359de
2016-09-28 14:45:12 +00:00
Gergő Tisza
854a462dc0 Remove $wgDisableAuthManager
Change-Id: I2b2c9693a275fcc026916bd97f303e7a5c8df341
2016-08-09 23:00:27 +00:00
Brad Jorsch
d245bd25ae Add AuthManager
This implements the AuthManager class and its needed interfaces and
subclasses, and integrates them into the backend portion of MediaWiki.
Integration with frontend portions of MediaWiki (e.g. ApiLogin,
Special:Login) is left for a followup.

Bug: T91699
Bug: T71589
Bug: T111299
Co-Authored-By: Gergő Tisza <gtisza@wikimedia.org>
Change-Id: If89d24838e326fe25fe867d02181eebcfbb0e196
2016-05-16 15:11:02 +00:00