Skip to content

Specific errors subclassing Net::LDAP::Error #183

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

Merged
merged 11 commits into from
Jan 16, 2015

Conversation

satoryu
Copy link
Collaborator

@satoryu satoryu commented Jan 4, 2015

I and my colleagues are looking forward to the release of @DenisKnauf's work #61 but unfortunately there were some conflicts while he was being busy 🏃

so to take over the remaining work, I've recreated new pull request.

@@ -0,0 +1,31 @@
class Net::LDAP
class Error < StandardError; end
Copy link
Member

Choose a reason for hiding this comment

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

👍 for switching the name from LdapError to just Error. Does anyone have strong opinions on having a backwards compatibility placeholder?

class LdapError < Error
  def message
    "Deprecation warning: Net::LDAP::LdapError is no longer used. Use Net::LDAP::Error or rescue one of it's subclasses. [link to this file]\n" + super
  end
end

We're pre 1.0, there's no obligation for us to do this. I'm fine with either because it's an easy error to fix if anyone runs into it and we can document it in History.md

Copy link
Member

Choose a reason for hiding this comment

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

@jch I support the rename and keeping around the backwards compatible constant, though the semantics of the backwards compatible constant is a bit trickier than inheriting from Error. What needs to be backwards compatible is this:

begin
  # something that could fail
rescue Net::LDAP::LdapError => error
  # handle error
end

The problem with the above is that it wouldn't actually catch anything that inherits from Net::LDAP::Error, only the specific Net::LDAP::LdapError subclass. Instead, I think we can just have a constant assignment that would work as expected:

class Net::LDAP
  class Error < StandardError; end
  LdapError = Error
end

begin
rescue Net::LDAP::LdapError
  # should work
end

Copy link
Member

Choose a reason for hiding this comment

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

@mtodd good eye. What about having Error inherit from LdapError for a few point releases so that we can add a deprecation warning?

class Net::LDAP
  class LdapError < StandardError
    def message
      "Deprecation warning... " + super
    end
  end

  class Error < LdapError; end
end

This allows us to eventually remove LdapError.

Copy link
Member

Choose a reason for hiding this comment

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

That would work!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@jch
Copy link
Member

jch commented Jan 5, 2015

@satoryu nice start on this PR. Could you go over the changes and make sure that you're using the specific error when one is appropriate instead of using the generic Net::LDAP::Error class? Let me know when you have that done, and I can review again.

@jch jch self-assigned this Jan 5, 2015
@jch jch changed the title Take over @DenisKnauf's work(#61) Specific errors subclassing Net::LDAP::Error Jan 5, 2015
when :ssha
salt = SecureRandom.random_bytes(16)
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
srand; salt = (rand * 1000).to_i.to_s
Copy link
Member

Choose a reason for hiding this comment

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

👎 we need to continue using SecureRandom for this.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @mtodd. This is also out of scope for 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.

It may indicate that your branch was behind upstream master.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:feelsgood: I miss it in merging.

@mtodd
Copy link
Member

mtodd commented Jan 5, 2015

make sure that you're using the specific error

I think the goal should be that we don't raise Net::LDAP::Error directly, always using the specific error class. Does that sound right, @jch?

@jch
Copy link
Member

jch commented Jan 6, 2015

I think the goal should be that we don't raise Net::LDAP::Error directly, always using the specific error class.

👍 The base error class serves as a convenient catch-all for users to rescue.

@satoryu
Copy link
Collaborator Author

satoryu commented Jan 6, 2015

@jch @mtodd I got the goal. I think there are

  • use SecureRandom as salt in lib/net/ldap/password.rb
  • Define Net::LDAP::LdapError again and it says WARNING message.
  • Replace Net::LDAP::Error with appropriate error object

when :ssha
salt = SecureRandom.random_bytes(16)
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
srand; salt = SecureRandom.random_bytes(16)
Copy link
Member

Choose a reason for hiding this comment

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

@satoryu Remove this dangling srand.

@satoryu
Copy link
Collaborator Author

satoryu commented Jan 9, 2015

ops, Rubocop says that Net::LDAP::Connection#search offenses...
I'll try to fix it.

@mtodd
Copy link
Member

mtodd commented Jan 9, 2015

@satoryu looks like @mynameisrufus is working on a fix here: #185

@satoryu
Copy link
Collaborator Author

satoryu commented Jan 9, 2015

👍 good news.

jch pushed a commit that referenced this pull request Jan 16, 2015
Unblocks #183. There is a
proposed fix in #185, but it's
not ready yet.
@jch jch merged commit 5a2b2ca into ruby-ldap:master Jan 16, 2015
@jch
Copy link
Member

jch commented Jan 16, 2015

I merged this manually after disabling rubocop in CI. We can continue to iterate on #185, but I wanted these changes in the release I'm cutting today (0.10.2).

@satoryu
Copy link
Collaborator Author

satoryu commented Jan 16, 2015

@jch thanks!

@jch jch mentioned this pull request Jan 21, 2015
astratto pushed a commit to astratto/ruby-net-ldap that referenced this pull request Dec 18, 2015
Unblocks ruby-ldap#183. There is a
proposed fix in ruby-ldap#185, but it's
not ready yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants