Commit graph

40 commits

Author SHA1 Message Date
umherirrender
c572d18661 Fixed spacing
- Removed space after cast
- Removed spaces in array index
- Removed double spaces
- Added spaces around string concat
- Fixed mixed tabs and spaces at begin of line

Change-Id: I38e849723f055d2d4c05cba72f5c245a28e8d5da
2015-09-26 20:44:54 +00:00
Sam Smith
16cea35d85 Configure logged in session length independently
* Add the $wgExtendedLoginCookies configuration variable, which defines
  the set of login cookies that can have their lifetime configured
  independently
* Add the $wgExtendedLoginCookieExpiration configuration variable, which
  dictates when the extended lifetime login cookies expire
* Default $wgExtendedLoginCookieExpiration to null so that the current
  behaviour is unaffected

Bug: T68699
Change-Id: I0cc24524e4d7d9d1d21c9fa8a28c7c76b677b96c
2015-06-23 19:31:20 -04:00
csteipp
1a20dc9362 Password validity by policy per group
Make password policies defined in a configurable policy, which is
defined by group. A user's password policy will be the maximum of
each group policy that the user belongs to.

Bug: T94774
Change-Id: Iad8e49ffcffed38df6293db0ef31a227d3962003
2015-06-10 10:34:17 -07:00
Aaron Schulz
8c5406a437 Added CAS logic to User::addAutopromoteOnceGroups
* This should avoid duplicate logging events on races or when
  the cache fails to update.
* Also added getDBTouched() method to get user_touched itself.

Bug: T48834
Change-Id: Ib2cd0a2c72629fa4e13dcff4d2d6fbac8e690b32
2015-04-16 13:31:40 -07:00
Timo Tijhof
8b1d94082d User: Add unit tests for getId, isAnon and isLoggedIn
Change-Id: Ie007d9da47df871f99ca19c4d7364f46f71c255b
2015-04-02 07:13:54 +00:00
Tyler Romeo
63cf33d825 SECURITY: Set maximal password length for DoS
Prevent DoS attacks caused by the amount of time
it takes to hash long passwords by setting a limit
on password length.

Slightly restructures the behavior of User::checkPasswordValidity
in order to accommodate for the difference between
passwords the user should be able to log in with and
passwords they should not.

Bug: T64685
Change-Id: I24f33474c6f934fb8d94bb054dc23093abfebd5e
2015-04-01 09:55:42 -07:00
Matthew Flaschen
e980ec63fd Fix testGetCanonicalName PHPUnit test:
* assertEquals takes expected, prior to actual
  https://phpunit.de/manual/3.7/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.assertions.assertEquals
* ' trailing space ' test was failing with wgCapitalLinks false.  Since the test is not about that,
  I changed it to ' Trailing space '.  The alternative would be to force wgCapitalLinks to true
  with setMwGlobals or skip the test if it's true.

Change-Id: I677273045bdabb6248ffe2c2f003a3673b3fa51c
2015-02-27 06:06:06 +00:00
Kunal Mehta
fc7cfb78c4 Add missing @covers tag
Change-Id: I491929e3d77688bf07640db4218ef99d6b888a82
2015-01-13 10:25:41 -08:00
Niklas Laxström
80ca508ed1 Add User::equals
Seems stupid omission. Title has one. Why do I need to think how
to determine how to users objects point to the same user. Allows
more expressive code.

Also fixes a bug in multiple places where users "0" and "00" were
considered equal.

Change-Id: I682392e564b332b77ab489f2ad394fa2d28098a5
2015-01-13 15:04:45 +01:00
Ricordisamoa
fc5fd5c37a Typo fixes and non-code tweaks
Skipped replacements:
* prefered → preferred
* prolly → probably

Skipped files:
* resources/lib/jquery.ui/jquery.ui.mouse.js
* resources/lib/jquery/jquery.form.js

Change-Id: Ib7923f362ddfca1b892bf5d601785d6b5aa5d44c
2014-12-12 18:31:15 +00:00
umherirrender
bb910388c7 Use setMwGlobals in UserTest::testPasswordExpire
Change-Id: Ida1a43629853abf648867f29e3bf15bdfd4291a6
2014-10-16 19:38:31 +02:00
aude
9d95be4f90 UserTest: Fix edit count test which incorrectly added user to db
Although 'added' to the database, the user name was cleared
in User::loadDefaults() and not added correctly to the database.

Then if one has BetaFeatures extension, then the test fails.
Via a hook, BetaFeatures does "User::newFromName( $user->getName() );",
that produces a null object as name is '127.0.0.1' and then
$user->getOption() fails.

loadDefaults() is automatically called by addToDatabase() with correct
parameters, so we can just remove the call.

Bug: 68626
Change-Id: Ibb5c60192eb83b2608f72b59d7705854549a5dac
2014-09-20 23:57:35 +02:00
Bartosz Dziewoński
03be8f40f5 UserTest: Don't rely on the behavior of unknown user options
They are not actually expected to be preserved, although they might be.

Change-Id: I34e15f3d1e5b9b825e6fc14814c8e9a6ac151ce9
2014-09-20 18:56:31 +02:00
Timo Tijhof
96771e3a65 test: Clean up data providers that should be static
Follows-up b36d883.

By far most data providers are static (and PHPUnit expects them
to be static and calls them that way).

Most of these classes already had their data providers static
but additional commits sloppily introduced non-static ones.

* ResourceLoaderWikiModuleTest, 8968d8787f.
* TitleTest, 545f1d3a73.
  Odd unused method 'dataTestIsValidMoveOperation' was introduced
  in 550b878e63.
* GlobalVarConfigTest, a3e18c3670.

Change-Id: I5da99f7cd3da68c550ae507ffe1f725d31e7666f
2014-09-18 12:52:44 -07:00
umherirrender
f3dbe5ba36 Add tests for User::getCanonicalName()
Change-Id: I00097a4706c4ada41a5697470b550c925ae6051d
2014-09-05 13:46:00 +00:00
Timo Tijhof
2e3b1076c0 UserTest: Cover User::isIP and User::isValidUserName better
Change-Id: I4663c37871492c1415152b2af0fda4f6de4f212f
2014-07-01 18:31:07 +02:00
Siebrand Mazeland
4916e08d8e Pass phpcs-strict on some test files (4/x)
Change-Id: Ifdbb431a6018c514b15ae71cc0c21b653a5e466d
2014-04-24 18:51:42 +02:00
csteipp
ea7687a7fd Refactor password validity checking
Refactor the password checks to return a status object, so the function
can handle the entire error message, or return multiple error messages.

This patchset aims to keep the functionality identical. A followup
patchset can further improve the functionality. E.g., although
getPasswordValidity stated it could return an array of messages, it
never did so except from the hook, so most callers expect and handle a
single string.

Change-Id: I87644486f5572dc067ebdbacd01fb39c67e5612a
2014-03-15 06:30:25 +00:00
csteipp
01c8c421f8 Password Expiration
Add functionality to expire users' passwords:
 * Adds column to the user table to keep a password expiration
 * Adds $wgPasswordExpirationDays, which will force users to reset
   their passwords after a set number of days. By default, this set
   to false, so passwords never expire.
 * Adds a default grace period of 7 days, where if the user's password
   is expired, they can still login, but are encouraged to reset their
   password.
 * Adds hook 'LoginPasswordResetMessage' to update reset message, in
   case an extension wants to vary the message on a particular reset
   event.
 * Adds hook 'ResetPasswordExpiration' to allow extensions to change
   the expiration date when the user resets their password. E.g., if
   an extension wants to vary the expiration based on the user's group.

If the user is in the grace period, they get a password reset form
added to the login successful page. If an extension prevents showing
the login successful page (like CentralAuth), it should be updated to
show a password change form during the grace period. After the grace
period, the user will not be able to login without changing their
password.

Also prevents a successful reset if the user is "changing" their
password to their existing password.

No passwords will expire by default. Sites will have to call
User->expirePassword() from their own maintenance script to trigger a
password reset for a user.

Bug: 54997
Change-Id: I92a9fc63b409b182b1d7b48781d73fc7216f8061
2014-02-20 09:41:51 -08:00
Mattflaschen
2855210048 Revert "User::saveOptions() optimization"
The hooks are not actually being called multiple times,
since getDefaultOptions caches its return value
(except while unit testing).

However, this change caused a regression due to different
handling of saved values (e.g. false no longer saves
when the default is true).

This reverts commit ff355e87e2.

Bug: 60653
Change-Id: Ibbd34dde5ec5fafbdf6097337cc0fa94614f0b85
2014-01-31 00:37:24 +00:00
Antoine Musso
ff355e87e2 User::saveOptions() optimization
Since we only want to save non default user options, we have to strip
out any user option that match the default ones. We did that by calling
User::getDefaultOption( 'some option name' ); on each of the option.

Since the User mOptions property is a merge of the default option, we
end up doing a lot of unneeded processing. The loop roughly looks like:

 User::getDefaultOption()
   User::getDefaultOptions()
     Language->getCode()
     SearchEngine::searchableNamespaces()
       language->getNamespaces()
       wfRunHooks('SearcheableNamespaces')
     wfRunHooks('UserGetDefaultOptions')

For EACH of the mOptions.

Instead this patch does an array_diff to strip out from mObjects any
default option.  We still skip options whose value is false or null.

Test provided to make sure we only save what we want.

Change-Id: Ie98d3a17edab74401ed32f759ba11f723b56e376
2014-01-24 11:09:11 -08:00
addshore
fb16eb2abe Add more @covers tags and test cleanup
Other cleanup includes
 - Adding method scopes
 - Fixing php comments
 - Adding todos

Change-Id: I0a231008e6a59110ffcab6af1bd8c4d3ee13f21d
2013-10-22 08:59:42 +00:00
Brad Jorsch
08adf46b26 Add 'viewmyprivateinfo', 'editmyprivateinfo', and 'editmyoptions' rights
These are needed for OAuth grants.

Note that we don't bother with a 'viewmyoptions' right, since the
majority will be determinable from just observing the interface.

Note that the fact of having a confirmed email address cannot be
reliably hidden, and if the user has 'sendemail' they may be able to
determine the real name and email address by sending an email to another
account that they control.

Change-Id: I3f03dd010020e8d43cc2d3bca7b3ef7196d1c548
2013-07-03 13:40:04 -04:00
Siebrand Mazeland
7a24666935 Update formatting
2 of n.

Change-Id: I5406673e99ed53e4e330ed47f022a17177544daa
2013-02-14 12:36:35 +01:00
Antoine Musso
0fd05285d7 pass codesniffer on tests/
Fix almost all occurences of the following sniffs:

Generic.CodeAnalysis.UselessOverridingMethod.Found
Generic.Formatting.NoSpaceAfterCast.SpaceFound
Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma
Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine
Generic.PHP.LowerCaseConstant.Found
PSR2.Classes.PropertyDeclaration.ScopeMissing
PSR2.Files.EndFileNewline.TooMany
PSR2.Methods.MethodDeclaration.StaticBeforeVisibility

Change-Id: I96aacef5bafe5a2bca659744fba1380999cfc37d
2013-01-28 12:14:26 +01:00
aude
c5ca90e715 fix testEditCount to work with non-wikitext content in main NS
consistent with WikiPageTest and other places, perform the test
with the Help namespace as a workaround for now.

Change-Id: I2b766c17f35e0e79662b6302c122225a1a33e7be
2012-11-08 18:06:32 +01:00
parent5446
edf5632f6a (bug 37963) Fixed loading process for user options.
The bug has actually already been fixed, so this
patch just removes extraneous function calls and code in
User::getOption() and User::setOption(). It also adds
unit tests for user options (including a test for the
case provided in the bug report).

Change-Id: Idd8af9cf1a26a4adbde3ca71dde64539ecd0a207
2012-10-30 20:28:39 +01:00
Antoine Musso
93dcfa9f05 raise timeout for UserTest::testEditCount
UserTest::testEditCount did eleven calls to doEdit which is slow when
used with the sqlite backend. I have made to do less edits and also
marked it as '@group medium' which means the timeout will be 10 seconds
instead of 2 seconds.

Change-Id: If2d055075470f837009568d56b1119a57b177ba3
2012-10-26 15:40:29 +02:00
Marius Hoch
e65eb02d3e Unit test for User::getEditCount
Rather trivial test for User::getEditCount as suggested by
Siebrand in https://gerrit.wikimedia.org/r/26457

This required adding the User in the test to DB, as the data
is written to and read from the DB.

Change-Id: Ic4e55c01247158315b759654b34fdbdf9a61db01
2012-10-18 16:48:35 +02:00
Timo Tijhof
181c7cdc8e Clean and repair many phpunit tests (+ fix implied configuration)
This commit depends on the introduction of
MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4.

Various tests already set their globals, but forgot to restore
them afterwards, or forgot to call the parent setUp, tearDown...

Either way they won't have to anymore with setMwGlobals.

Consistent use of function characteristics:
* protected function setUp
* protected function tearDown
* public static function (provide..)

(Matching the function signature with PHPUnit/Framework/TestCase.php)

Replaces:
 * public function (setUp|tearDown)\(
 * protected function $1(

 * \tfunction (setUp|tearDown)\(
 * \tprotected function $1(

 * \tfunction (data|provide)\(
 * \tpublic static function $1\(

Also renamed a few "data#", "provider#" and "provides#" functions
to "provide#" for consistency. This also removes confusion where
the /media tests had a few private methods called dataFile(),
which were sometimes expected to be data providers.

Fixes:

TimestampTest often failed due to a previous test setting a
different language (it tests "1 hour ago" so need to make sure
it is set to English).

MWNamespaceTest became a lot cleaner now that it executes with
a known context. Though the now-redundant code that was removed
didn't work anyway because wgContentNamespaces isn't keyed by
namespace id, it had them was values...

FileBackendTest:
* Fixed: "PHP Fatal: Using $this when not in object context"

HttpTest
* Added comment about:
  "PHP Fatal: Call to protected MWHttpRequest::__construct()"
  (too much unrelated code to fix in this commit)

ExternalStoreTest
* Add an assertTrue as well, without it the test is useless
  because regardless of whether wgExternalStores is true or false
  it only uses it if it is an array.

Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-09 03:01:51 +02:00
umherirrender
fdd2df0a80 Add UserTest::testAllRightsWithMessage
New test case, which checked, if for all available rights a right-
message exist (Core and Extensions)

Some missing rights added with extra patch sets (need merge/rebasing
before merge of this)

Change-Id: I28957835fb77a01a799439ad7b3d22b96db07204
2012-08-13 23:26:58 +02:00
Sam Reed
ec4604de3d Documentation and whitespace
Clearing another w/c
2012-01-19 14:56:18 +00:00
Tim Starling
3da36a9103 Reverted r92364 (per-namespace permissions).
This is the wrong configuration format for such a feature, and the wrong interface. We already have certain per-namespace permissions in the Title class, and we didn't need to add extra formal parameters to a whole lot of User methods in order to get them. The feature should be implemented wholly in Title, and the concept of user rights should remain relatively simple and easy to understand, and independent of its many applications, i.e. a user either has a right or doesn't. Rights are just a tool for developing access policies; the complexity should be in the caller.

The revert was mostly done by hand, since there were a lot of conflicts. I tried to preserve the gist of conflicting changes in r102187 and r102873. The test changes are not simple reverts, rather I just edited out the per-namespace tests. I reverted the followups r92589 and r104310.
2011-12-12 06:03:01 +00:00
Santhosh Thottingal
462319d089 Use dataProvider for the testIsValidUserName method. Followup r99466 2011-10-11 10:25:58 +00:00
Santhosh Thottingal
08aac7bd40 Stylize.php changes 2011-10-11 10:02:50 +00:00
Santhosh Thottingal
2a7c8be024 Testcases for isValidUserName method of User.php.
There are many cases this method will fail for non-latin languages, 
but not added now since there are bugs reported on that already and results
a rewrite of the method as per UAX 31 standard.
2011-10-11 09:17:36 +00:00
Platonides
2d9bb42682 Since r92364 UserTest.php needs a database 2011-07-19 21:41:25 +00:00
Bryan Tong Minh
1fb5d73612 First steps for bug 14801: add backend support for per-namespace permissions to core. This extends $wgGroupPermissions syntax from $wgGroupPermissions[$group][$right] = bool to $wgGroupPermissions[$group][$right] = array( NS_X => bool ). This is safely backwards compatible; the booleans are still fully supported, and any unset namespace will default to false.
* User::getRights(), User::isAllowed() and User::getGroupPermissions now optionally accept a namespace parameter. If not set, it will check whether the user has the right for all namespaces.
* Anything that uses Title::getUserPermissionsErrorsInternal() automatically supports per-namespace permissions. This includes Title::getUserPermissionsErrors and Title::(quick)UserCan.
* Fix tests that set User::mRights

The next step would be to change all User::isAllowed() to Title::quickUserCan or pass the namespace to User::isAllowed().
2011-07-16 16:09:00 +00:00
Bryan Tong Minh
6a16bea0d2 Follow-up r91895: Call parent destructor as well, just to be safe. 2011-07-11 18:38:26 +00:00
Bryan Tong Minh
8d89af55cc Add unit tests for $wgGroupPermissions/$wgRevokePermissions 2011-07-11 18:36:29 +00:00