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

add a catch block for expected exceptions in password check #453

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

karakayasemi
Copy link
Contributor

@karakayasemi karakayasemi commented Oct 6, 2019

Fixes https://github.com/owncloud/enterprise/issues/3496

This PR adds a catch blog for expected exceptions in password check, to not show internal error for users.

ldap_connect only applies syntactic checks for given parameters, does not contact the server. In our implementation, as far as I see, we assume the server will be available if a request passes from this check. I clarified this situation with comment lines for further usages.

@karakayasemi karakayasemi added this to the development milestone Oct 6, 2019
@karakayasemi karakayasemi self-assigned this Oct 6, 2019
@CLAassistant
Copy link

CLAassistant commented Oct 6, 2019

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Oct 9, 2019

Codecov Report

Merging #453 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #453   +/-   ##
=========================================
  Coverage     35.72%   35.72%           
  Complexity     1340     1340           
=========================================
  Files            31       31           
  Lines          3790     3790           
=========================================
  Hits           1354     1354           
  Misses         2436     2436
Impacted Files Coverage Δ Complexity Δ
lib/User/Manager.php 60.09% <ø> (ø) 68 <0> (ø) ⬇️
lib/Connection.php 72.56% <100%> (ø) 110 <0> (ø) ⬇️
lib/User_LDAP.php 49.05% <100%> (ø) 39 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5ea851...10d79fd. Read the comment docs.

@karakayasemi karakayasemi changed the title do not try login on backup server after BindFailedException [WIP] do not try login on backup server after BindFailedException Oct 9, 2019
@karakayasemi karakayasemi changed the title [WIP] do not try login on backup server after BindFailedException add a catch blog for expected exceptions in password check Oct 10, 2019
@@ -574,6 +574,9 @@ private function establishConnection() {
}

/**
* Performs syntactic check against given host and port,
* If ldapTLS disabled, the server will not be contacted!
Copy link
Member

Choose a reason for hiding this comment

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

this sounds like a configuration issue. Did you check with a server without TLS? I mean, if your LDAP server requires a TLS connection, you won't be able to connect to that server if the option is disabled, but that's part of the connection configuration.

Copy link
Member

@VicDeo VicDeo Oct 11, 2019

Choose a reason for hiding this comment

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

yep. IIRC ldapTLS is autoprobed while testing the connection.
So "If ldapTLS was changed on the server after the connection had been saved, the connection will fail" is true and just "If ldapTLS disabled, the server will not be contacted!" doesn't look correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So "If ldapTLS was changed on the server after the connection had been saved, the connection will fail" is true

No, in the stated case doConnect method will not fail, it will return true if the host and port parameters are in the right format. This is what I am trying to explain in the phpdoc of the method.

I tried to highlight the documentation note of the ldap_connect method: https://www.php.net/manual/en/function.ldap-connect.php . According to its documentationldap_connect method is only used for checks whether the given host and port are plausible, the actual connect happens with the next calls to ldap_*. In our doConnect method, we only make the next call if ldapTLS configuration is enabled (by calling ldap_start_tls).

However,

Util::DEBUG); // log only in debug mod because this is triggered by wrong passwords
this comment assumes that, since ldap_bind method will run after doConnect method, it can only fail in the wrong password case, which is wrong. In addition,
if ($this->curFunc === 'ldap_bind') {
this line makes impossible to learn why ldap_bind fail by disabling error code check.

If you want, we can think of a better sentence for doConnect method phpdoc to explain the described behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jvillafanez, @VicDeo Do you have any suggestions to complete this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe change the doc to something like:

This method will perform some setup required to connect to the LDAP server,
but it won't connect to the LDAP server

which also makes me think if the method should throw a "ServerNotAvailableException"... probably something to review in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jvillafanez the thing is if TLS enabled, it will run ldap_start_tls and perform a connect.

Copy link
Member

Choose a reason for hiding this comment

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

This method will perform some setup required to connect to the LDAP server,
but it won't connect to the LDAP server unless ldap_start_tls is activated

or something along those lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for redirection, phpdoc updated.

@jvillafanez
Copy link
Member

code changes looks fine, though I haven't tested them.

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

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

Code looks good assuming it works the way we want.

@karakayasemi
Copy link
Contributor Author

karakayasemi commented Oct 18, 2019

Some of the newly added acceptance tests are failing, unrelated to this PR: owncloud/core#36283

@karakayasemi
Copy link
Contributor Author

I will restart tests after owncloud/core#36293 resolved.

@dpakach
Copy link
Contributor

dpakach commented Oct 18, 2019

Fix for the drone test failure is done in owncloud/core#36294. Hopefully it will be available in next qa-tarball.

@karakayasemi karakayasemi merged commit 40ee018 into master Oct 21, 2019
@delete-merged-branch delete-merged-branch bot deleted the bind-ex branch October 21, 2019 16:01
@phil-davis phil-davis changed the title add a catch blog for expected exceptions in password check add a catch block for expected exceptions in password check Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants