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

Fix expiration logic for ldap internal credential cache #11395

Merged
merged 4 commits into from
Jul 1, 2021

Conversation

loquisgon
Copy link

Fixes a bug with the expiration logic for LdapUserPrincipal. The entry should unconditionally expire when maxDuration is up among other conditions. It was not expiring in that case.

This PR has:

  • [ X] been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • [X ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.


public void testIsExpiredWhenMaxDurationIsSmall() throws InterruptedException
{
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could avoid the sleeps by changing isExpired to accept "now" as a parameter, and passing in an explicit "created at" time when creating the principal

Copy link
Author

Choose a reason for hiding this comment

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

What about exposing the private constructor (for testing) and adding the now parameter as you indicate? however passing now to isExpired feels like an error prone decision (callers may make mistakes violating the contract of the expiration logic --- violation of encapsulation)

Copy link
Author

@loquisgon loquisgon Jun 30, 2021

Choose a reason for hiding this comment

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

Done. I left the original isExpired method and added a new isExpired, visible for testing, with the new parameters.

Copy link
Member

@nishantmonu51 nishantmonu51 left a comment

Choose a reason for hiding this comment

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

👍 , LGTM

Copy link
Contributor

@zachjsh zachjsh left a comment

Choose a reason for hiding this comment

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

LGTM

Assert.assertTrue(PRINCIPAL.isExpired(100, 1000));
}

public void testIsExpiredWhenMaxDurationIsSmall() throws InterruptedException
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception is never thrown. Same for other tests below. Failing intelliJ inspection because of this.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@suneet-s suneet-s merged commit a9c4b47 into apache:master Jul 1, 2021
jihoonson pushed a commit to jihoonson/druid that referenced this pull request Jul 12, 2021
* Fix expiration logic for ldap internal credential cache

* Removed sleeps from tests

* Make method package scoped so it can be used in unit tests

* Removed unused thrown exceptions
@clintropolis clintropolis added this to the 0.22.0 milestone Aug 12, 2021
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.

None yet

6 participants