Commit Graph

133 Commits

Author SHA1 Message Date
Côme Chilliet
8d5165e8dc
Adapt tests to config value typing
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2023-04-05 17:42:14 +02:00
Artur Neumann
37cfccabc1
unit tests for Manager::invalidateTokensOfUser
Signed-off-by: Artur Neumann <artur@jankaritech.com>
2023-03-14 17:13:30 +01:00
Joas Schilling
a81d8ecef5
Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
2023-02-09 16:15:47 +01:00
Côme Chilliet
f5c361cf44
composer run cs:fix
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2023-01-20 11:45:08 +01:00
Marcel Klehr
adfe367106
PublickKeyTokenProvider: Fix password update routine with password hash
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
2023-01-04 08:30:53 +01:00
Christoph Wurst
9d0e79f10d
Fix PublicKeyTokenProviderTest import and mock
* IDBConnection import missing
* Atomic doesn't need a mock

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2022-11-10 15:40:35 +01:00
Julius Härtl
298d2b9b58
Skip general login with email for non-valid addresses and LDAP
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2022-10-26 12:30:25 +02:00
Christoph Wurst
c5922e67d3
Run session token renewals in a database transaction
The session token renewal does
1) Read the old token
2) Write a new token
3) Delete the old token

If two processes succeed to read the old token there can be two new tokens because
the queries were not run in a transaction. This is particularly problematic on
clustered DBs where 1) would go to a read node and 2) and 3) go to a write node.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2022-10-18 08:28:22 +02:00
Carl Schwan
9919116716
Merge pull request #31499 from nextcloud/bugfix/empty-secret
Add fallback routines for empty secret cases
2022-10-17 16:02:58 +02:00
Carl Schwan
702445ba3b
Handle one time password better
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-07-28 14:26:25 +02:00
Carl Schwan
1c23c029af Handler large passwords
For passwords bigger than 250 characters, use a bigger key since the
performance impact is minor (around one second to encrypt the password).

For passwords bigger than 470 characters, give up earlier and throw
exeception recommanding admin to either enable the previously enabled
configuration or use smaller passwords.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-07-05 11:37:14 +02:00
Carl Schwan
cdf3b60555 Handle one time passwords
This adds an option to disable storing passwords in the database. This
might be desirable when using single use token as passwords or very
large passwords.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-07-05 11:25:44 +02:00
Joas Schilling
7b3e2217de
Fix user agent trimming on installation
Signed-off-by: Joas Schilling <coding@schilljs.com>
2022-05-09 08:36:34 +02:00
Joas Schilling
d683e0d3d1
Automatically cut the token name on the first level
Signed-off-by: Joas Schilling <coding@schilljs.com>
2022-03-23 21:38:53 +01:00
Joas Schilling
343476f54f
Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
2022-03-23 11:00:34 +01:00
Carl Schwan
01e2a26749 Fix unit tests
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-03-10 14:19:48 +01:00
Joas Schilling
3e20cffc86
More test fixing
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-12-01 22:38:57 +01:00
Joas Schilling
c6ae53096c
More test fixing
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-12-01 22:17:19 +01:00
Joas Schilling
9f00179037
More unit test adjustments
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-12-01 21:40:14 +01:00
Côme Chilliet
bc3acfc957
Fix test class names
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2021-11-23 09:28:57 +01:00
Christoph Wurst
7dd7256cfe
Prevent duplicate auth token activity updates
The auth token activity logic works as follows
* Read auth token
* Compare last activity time stamp to current time
* Update auth token activity if it's older than x seconds

This works fine in isolation but with concurrency that means that
occasionally the same token is read simultaneously by two processes and
both of these processes will trigger an update of the same row.
Affectively the second update doesn't add much value. It might set the
time stamp to the exact same time stamp or one a few seconds later. But
the last activity is no precise science, we don't need this accuracy.

This patch changes the UPDATE query to include the expected value in a
comparison with the current data. This results in an affected row when
the data in the DB still has an old time stamp, but won't affect a row
if the time stamp is (nearly) up to date.

This is a micro optimization and will possibly not show any significant
performance improvement. Yet in setups with a DB cluster it means that
the write node has to send fewer changes to the read nodes due to the
lower number of actual changes.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2021-10-22 09:32:22 +02:00
Joas Schilling
4ed296db9f
Fix Authentication test
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-04-22 15:36:34 +02:00
Roeland Jago Douma
5ee9e1f784 Move 2FA registration to IBootstrap
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2021-04-20 21:01:16 +02:00
Roeland Jago Douma
b5ffca00f7 Fix unit test
* Fix namespace
* Fix test

Was broken after https://github.com/nextcloud/server/pull/26529

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2021-04-16 09:47:52 +02:00
Roeland Jago Douma
3c5cf825b3 Add real events for enabled 2fa providers for users
* Shiny new events
* Listener to still emit the old event

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2021-03-22 20:57:10 +01:00
Roeland Jago Douma
cd457cc68b Always renew apppasswords on login
Else you can end up that you renewed your password (LDAP for example).
But they still don't work because you did not use them before you logged
in.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2021-02-10 19:02:37 +01:00
Christoph Wurst
99d525eb36
Convert 2FA token type to string
The IConfig service is documented to handle its data as strings, hence
this changes the code a bit to ensure we store keys as string and
convert them back when reading.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2021-01-22 14:09:37 +01:00
Joas Schilling
49ff48fcd3
Use PSR logger in authentication
Signed-off-by: Joas Schilling <coding@schilljs.com>
2020-10-12 22:07:04 +02:00
Christoph Wurst
d9015a8c94
Format code to a single space around binary operators
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-10-05 20:25:24 +02:00
Roeland Jago Douma
76a7600e2e
Allow configuring the activity update interval of token
On some systems with a lot of users this creates a lot of extra DB
writes.
Being able to increase this interval helps there.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2020-10-04 09:31:41 +02:00
Christoph Wurst
adf100a42f
Fix undefined class property access after upgrade from 19 to 20
The serialized data in 19 has one property less and this was not
considered in the code. Hence adding a fallback. Moreover I'm changing
the deserialization into an array instead of object, as that is the
safer option.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-09-07 13:31:24 +02:00
Lionel Elie Mamane
2c8e7912f3
adapt testGetLoginCredentialsInvalidTokenLoginCredentials() unit test to uid != loginname
Signed-off-by: Lionel Elie Mamane <lionel@mamane.lu>
2020-08-20 16:02:23 +02:00
Morris Jobke
725fecee34
Merge pull request #21344 from nextcloud/fix/twofactor-cleanup-event
Emit an event for every disabled 2FA provider during cleanup
2020-08-13 07:25:01 +02:00
Morris Jobke
234b510652
Change PHPDoc type hint from PHPUnit_Framework_MockObject_MockObject to \PHPUnit\Framework\MockObject\MockObject
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
2020-08-12 13:55:19 +02:00
Christoph Wurst
68794ebc92
Emit an event for every disabled 2FA provider during cleanup
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-06-16 14:38:33 +02:00
Christoph Wurst
3474afa938
Clean up auth tokens when user is deleted
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-06-15 19:24:04 +02:00
Julius Härtl
2eadf9d567
Do not create remember me cookie
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2020-04-23 19:12:54 +02:00
Christoph Wurst
caff1023ea
Format control structures, classes, methods and function
To continue this formatting madness, here's a tiny patch that adds
unified formatting for control structures like if and loops as well as
classes, their methods and anonymous functions. This basically forces
the constructs to start on the same line. This is not exactly what PSR2
wants, but I think we can have a few exceptions with "our" style. The
starting of braces on the same line is pracrically standard for our
code.

This also removes and empty lines from method/function bodies at the
beginning and end.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-04-10 14:19:56 +02:00
Christoph Wurst
14c996d982
Use elseif instead of else if
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-04-10 10:35:09 +02:00
Christoph Wurst
afbd9c4e6e
Unify function spacing to PSR2 recommendation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-04-09 13:54:22 +02:00
Christoph Wurst
2a529e453a
Use a blank line after the opening tag
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-04-09 11:50:14 +02:00
Christoph Wurst
85e369cddb
Fix multiline comments
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-04-08 22:24:54 +02:00
Roeland Jago Douma
84f3d2ddeb
[POC] Event for failed login attempts
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2020-03-31 21:41:02 +02:00
Christoph Wurst
463b388589
Merge pull request #20170 from nextcloud/techdebt/remove-unused-imports
Remove unused imports
2020-03-27 17:14:08 +01:00
Christoph Wurst
2ee65f177e
Use the shorter phpunit syntax for mocked return values
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-03-25 22:21:27 +01:00
Christoph Wurst
74936c49ea
Remove unused imports
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-03-25 22:08:08 +01:00
Joas Schilling
9935c71ec3
Check the user on remote wipe
Signed-off-by: Joas Schilling <coding@schilljs.com>
2020-03-16 09:29:28 +01:00
Christoph Wurst
60d4b45e89
Clean up 2FA provider registry when a user is deleted
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2020-01-08 10:51:44 +01:00
Roeland Jago Douma
3a7cf40aaa
Mode to modern phpunit
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2019-11-27 15:27:18 +01:00
Roeland Jago Douma
c007ca624f
Make phpunit8 compatible
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2019-11-27 13:34:41 +01:00