You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/06/30 00:10:04 UTC

[GitHub] [druid] jon-wei commented on a change in pull request #11395: Fix expiration logic for ldap internal credential cache

jon-wei commented on a change in pull request #11395:
URL: https://github.com/apache/druid/pull/11395#discussion_r661042623



##########
File path: extensions-core/druid-basic-security/src/test/java/org/apache/druid/security/basic/authentication/LdapUserPrincipalTest.java
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.security.basic.authentication;
+
+import junit.framework.TestCase;
+import org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorCredentialUpdate;
+import org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorCredentials;
+import org.junit.Assert;
+
+import javax.naming.directory.SearchResult;
+
+public class LdapUserPrincipalTest extends TestCase
+{
+
+  private static final BasicAuthenticatorCredentials USER_CREDENTIALS = new BasicAuthenticatorCredentials(
+      new BasicAuthenticatorCredentialUpdate("helloworld", 20)
+  );
+
+  // this will create a cache with createdAt now():
+  private static final LdapUserPrincipal principal = new LdapUserPrincipal(
+      "foo",
+      USER_CREDENTIALS,
+      new SearchResult("foo", null, null)
+  );
+
+  public void testIsNotExpired()
+  {
+    Assert.assertFalse(principal.isExpired(1000, 1000));
+  }
+
+  public void testIsExpiredWhenMaxDurationIsSmall() throws InterruptedException
+  {
+    Thread.sleep(1000);

Review comment:
       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




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org