Commit graph

29 commits

Author SHA1 Message Date
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
DannyS712
35bd84e9ee Comments: use only // instead of more
No need for three or more slashes

Except in some places where a bunch more are
used for drawing attention to something

Change-Id: Ic90358eb89a14a04d2b66c48e52e8fb20de0eb04
2021-03-10 15:05:57 +00: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
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
Thiemo Kreuz
6aa6d10e86 Replace all call_user_func(_array) in all tests
There is native support for all of this now in PHP, thanks to changes
and additions that have been made in later versions. There should be no
need any more to ever use call_user_func() or call_user_func_array().

Reviewing this should be fairly easy: Because this patch touches
exclusivly tests, but no production code, there is no such thing as
"insufficent test coverage". As long as CI goes green, this should be
fine.

Change-Id: Ib9690103687734bb5a85d3dab0e5642a07087bbc
2020-06-06 18:41:20 +02: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
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
James D. Forrester
2e909bcb5f Drop wgPasswordSalt, deprecated since 1.24
Depends-On: Ic9952a1bd8563f218c3c581d4b206ebd6c6c9c44
Change-Id: I8b1d43aba62859645221caf5ff340903e4d61787
2019-07-21 12:25:25 -07:00
Dayllan Maza
4b39919c47 Add password policy setting suggestChangeOnLogin
Password policy checks that fail and have `suggestChangeOnLogin` set to true will
prompt for a password change on login.

Below are some rules that apply to this setting in different scenarios:

- If only one policy fails and has `suggestChangeOnLogin = false`, a password change will
  not be requested
- If more than one policy fails and one or more have `suggestChangeOnLogin` set to true`,
  a password change will be requested
- If `forceChange` is present in any of the failing policies, `suggestChangeOnLogin` value
  will be ignored and password change will be enforced
- if $wgInvalidPasswordReset is set to false `suggestChangeOnLogin` is ignored

IMPORTANT**
Before this patch, suggesting a password change was the default behavior (depending on
$wgInvalidPasswordReset), which means that the necessary changes to $wgPasswordPolicy
need to be in place before this patch is merged and gets to production.

Bug: T211621
Change-Id: I7a4a0a06273fa4e8bd0da3dac54cf5a1b78bb3fd
2019-03-09 14:59:02 -05:00
Gergő Tisza
f15ecc60cd
Add force option to password policy
Adds a way to set an array of options for a password policy. Currently
there is one option, 'forceChange', which forces the user to change
their password (if it fails the given check) before logging in.

Bug: T118774
Change-Id: I28c31fc4eae08c3ac44eff3a05f5e785ce4b9e01
2019-01-02 12:38:11 -08: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
Gergő Tisza
492431bce5
Fix tests for I7afaa955a4b393ef00b11e420709bd62b84fbc71
Change-Id: Id5a2a9768dc64db5259a5988d645e664163ba234
2017-11-14 17:58:49 -08: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
Aaron Schulz
3441ed1900 Make LocalPasswordPrimaryAuthenticationProviderTest use TS_MW timestamp conversion
Bug: T75174
Change-Id: I217a8e1847a21d54434693fafa7f618ec5840876
2017-05-09 19:32:24 -07: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
6124d71e25 Merge "Prevent login-only local password provider from removing passwords" 2016-11-30 16:39:12 +00:00
addshore
b12086b618 Get ConfigFactory & MainConfig from MediaWikiServices
Change-Id: Iafdd7e00747060572463ffb05aae4543f3a06163
2016-11-23 00:12:38 +00:00
Gergő Tisza
6dbe9b2397 Prevent login-only local password provider from removing passwords
When the local password provider is in login-only mode, it should
disable itself as soon as some other primary provider is enabled.
It's impossible to tell whether that is the case though, so err in
the safer direction.

Change-Id: Ie77a9cc6d8f06aa52a893e753d9971e30b0f55e5
2016-11-15 07:27:57 +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
Gergő Tisza
854a462dc0 Remove $wgDisableAuthManager
Change-Id: I2b2c9693a275fcc026916bd97f303e7a5c8df341
2016-08-09 23:00:27 +00:00
Ori Livneh
e638075936 Whenever possible, reuse User objects in unit tests
The unit tests spend nearly half of their run time resetting the user table for
each test. But the majority of tests do not depend on the user table having the
exact value that the setup code resets it to, and do not need to modify the
user objects they require to run.

Fix that by providing an API for tests to get User objects, and to indicate
whether the User object will be subject to destructive modification or not.
This allows User objects to be reused across multiple unit tests.

Change-Id: I17ef1f519759c5e7796c259282afe730ef722e96
2016-05-26 20:42:31 +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