Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store user_webdavauth users in DB + code cleanup #12799

Closed
wants to merge 1 commit into from

Conversation

LukasReschke
Copy link
Member

This commit introduces the storing of user_webdavauth users in the database which is a pre-requisite of #12620.

Furthermore, I refactored the code and removed deprecated code, as a little gimmick I added unit tests for the backend. - Especially considering that some people are using this as reference implementation for an authentication backend I consider it important that this backend follows best-practises. (still not perfect - but way better)

@MorrisJobke Please review.

@karlitschek Thought you might like that since you created that app. Care to review as well? - Don't worry, most of the change are unit tests :-)

@karlitschek
Copy link
Contributor

I forgot this app already. ;-)
looks good 👍

@LukasReschke
Copy link
Member Author

@DeepDiver1975 Our CI is running amok again :-(

if(substr($returnCode, 0, 1) === '2') {
if(!$this->userExists($uid)) {
$query = $this->db->prepareQuery('INSERT INTO `'.$this->tableName.'` (`uid`) VALUES (?)');
$query->bindValue(1, $uid);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MorrisJobke @DeepDiver1975 I wanted to mock bindValue also in the tests. But somehow it never worked. Any idea? - I just noticed that it is not really within the defined class and is just annotated:

/**
* small wrapper around \Doctrine\DBAL\Driver\Statement to make it behave, more like an MDB2 Statement
*
* @method boolean bindValue(mixed $param, mixed $value, integer $type = null);
* @method string errorCode();
* @method array errorInfo();
* @method integer rowCount();
* @method array fetchAll(integer $fetchMode = null);
*/

Any idea?

@LukasReschke
Copy link
Member Author

@blizzz I guess this makes user_ldap compatible again with user_webdavauth?

@blizzz
Copy link
Contributor

blizzz commented Dec 11, 2014

@LukasReschke did not test, but code-wise you fixed the issue.

A potential thing: in checkPassword(), if webdav does not care about case sensitivity, $uid could have different cases, resulting in different users. If this is the case, consider lowercasing it.

Also, since webdav users can show up out of nothing, the returned $uid in checkPassword could collide with an existing user. It's like creating a user without name checks. I.e. it could be crafted to get access to the data of a local or other user. In LDAP, I check available names before returning a new username.

@LukasReschke
Copy link
Member Author

A potential thing: in checkPassword(), if webdav does not care about case sensitivity, $uid could have different cases, resulting in different users. If this is the case, consider lowercasing it.

True. Needs investigation.

Also, since webdav users can show up out of nothing, the returned $uid in checkPassword could collide with an existing user. It's like creating a user without name checks. I.e. it could be crafted to get access to the data of a local or other user. In LDAP, I check available names before returning a new username.

I guess you do that by querying the usermanager before and asking if the user exists?

@blizzz
Copy link
Contributor

blizzz commented Dec 11, 2014

Also, since webdav users can show up out of nothing, the returned $uid in
checkPassword could collide with an existing user. It's like creating a
user without name checks. I.e. it could be crafted to get access to the
data of a local or other user. In LDAP, I check available names before
returning a new username.
I guess you do that by querying the usermanager before and asking if the
user exists?

You know my methods, Watson.

@LukasReschke
Copy link
Member Author

@blizzz THX for the heads-up. Incorporated your comments.

@LukasReschke
Copy link
Member Author

(failing test is unrelated)

@DeepDiver1975
Copy link
Member

Well - in the past months almost any user backend we implemented in some point in time introduced it's own table to store the users. We might want to think about some consolidation .....

*/
public function getHome($uid) {
if ($this->userExists($uid)) {
return $this->config->getSystemValue('datadirectory', $this->serverRoot . '/data') . '/' . $uid;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it make more sense to have an api to get the data dir instead of implementing this logic in several places? THX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return false or don't implement it – getHome() is only to override ownCloud default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MorrisJobke as blizzz explained - no need to implement this function - just kill it.

serverroot should no longer be required as well - THX

@LukasReschke
Copy link
Member Author

Well - in the past months almost any user backend we implemented in some point in time introduced it's own table to store the users. We might want to think about some consolidation .....

The problem I see there is that we will loose a lot of flexibility with that approach. User backends might allow different login names (for example the LDAP app does this) and also might require the need to store additional information about the backend. (for example the remote server if we're going to support such scenarios in the future)

I'm not quite sure how we can tackle this with a single table.

@MorrisJobke
Copy link
Contributor

@LukasReschke rebase needed

</field>

<index>
<name>webdav_uid</name>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We require PKs on all tables - please add

       <primary>true</primary>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to myself: Learn more about that mysterious database.xml - THX! ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

???

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I added a commit to this branch o.O

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Database noob here: Isn't the unique one line below exactly the same? 🙈

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unique != primary ;)

@MorrisJobke MorrisJobke mentioned this pull request Dec 22, 2014
27 tasks
@DeepDiver1975 DeepDiver1975 added this to the 8.0-current milestone Dec 22, 2014
@MorrisJobke MorrisJobke force-pushed the store-users-for-webdav-auth branch from 50deaab to b5c62d7 Compare December 23, 2014 10:19
@MorrisJobke
Copy link
Contributor

I rebase, fixed the merge conflict and added the primary key. But I'm not able to fix the other stuff. @LukasReschke Can you have a look at this?

@MorrisJobke
Copy link
Contributor

I also dropped the method getHome

@LukasReschke
Copy link
Member Author

I think it's better to keep this for 8.1 now.

@LukasReschke
Copy link
Member Author

Rebased. Ready to review.

* @return \OCP\IDateTimeZone
* Get the timezone of the current user, based on his session information and config data
*
* @return \DateTimeZone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the server is meant to return ocp interfaces

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

This commit introduces the storing of user_webdavauth users in the database which is a pre-requisite of #12620.

Furthermore, I refactored the code and removed deprecated code, as a little gimmick I added unit tests for the backend.

Conflicts:
	lib/private/server.php

Conflicts:
	apps/user_webdavauth/appinfo/app.php
	apps/user_webdavauth/user_webdavauth.php
@LukasReschke LukasReschke force-pushed the store-users-for-webdav-auth branch from 7723c53 to d4fc829 Compare February 24, 2015 12:05
@LukasReschke
Copy link
Member Author

Rebased as well.

@ghost
Copy link

ghost commented Feb 24, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/9884/
Test PASSed.

@scrutinizer-notifier
Copy link

The inspection completed: 51 new issues, 32 updated code elements

@canepan
Copy link

canepan commented Mar 10, 2015

Hello.
I'm wondering if it is possible to make this patch (and external users management) more useful.
Right now, an user which logs in via webdav does not belong to any group, has no email or display name, so apart from storing files and sharing via link or directly with other users.
It's not possible to assign quota, or do anything with external users.

I think this is the same for all external authentication methods (apart from LDAP, which can map LDAP groups to OC groups, I guess)

@MorrisJobke
Copy link
Contributor

@DeepDiver1975 @LukasReschke Still something for 8.1?

@DeepDiver1975 DeepDiver1975 modified the milestones: 8.2-next, 8.1-current Apr 7, 2015
@ghost
Copy link

ghost commented Apr 30, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/12064/
💣 Test FAILed. 💣

nooo432

@MorrisJobke
Copy link
Contributor

@LukasReschke You said, that you want to have a look at this :)

@DeepDiver1975
Copy link
Member

@LukasReschke 9.0 ????

@LukasReschke LukasReschke modified the milestones: 9.0-next, 8.2-current Sep 21, 2015
@LukasReschke
Copy link
Member Author

Replaced by #19229 then I guess.

@LukasReschke LukasReschke deleted the store-users-for-webdav-auth branch September 21, 2015 15:52
@MorrisJobke MorrisJobke removed this from the 9.0-next milestone Sep 21, 2015
@DeepDiver1975
Copy link
Member

Replaced by #19229 then I guess.

yep

@lock lock bot locked as resolved and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants