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 16:19:30 UTC

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

zachjsh commented on a change in pull request #11395:
URL: https://github.com/apache/druid/pull/11395#discussion_r661628009



##########
File path: extensions-core/druid-basic-security/src/test/java/org/apache/druid/security/basic/authentication/LdapUserPrincipalTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * 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;
+import java.time.Instant;
+
+public class LdapUserPrincipalTest extends TestCase
+{
+
+  private static final BasicAuthenticatorCredentials USER_CREDENTIALS = new BasicAuthenticatorCredentials(
+      new BasicAuthenticatorCredentialUpdate("helloworld", 20)
+  );
+
+  private static final long CREATED_MILLIS = 10000;
+
+  // this will create a cache with createdAt now():
+  private static final LdapUserPrincipal PRINCIPAL = new LdapUserPrincipal(
+      "foo",
+      USER_CREDENTIALS,
+      new SearchResult("foo", null, null),
+      Instant.ofEpochMilli(CREATED_MILLIS)
+  );
+
+  public void testIsNotExpired()
+  {
+    Assert.assertFalse(PRINCIPAL.isExpired(1, 10, CREATED_MILLIS + 500));
+  }
+
+  public void testIsObviouslyExpired()
+  {
+    // real clock now should be so much bigger than CREATED_MILLIS....so it must have expired...
+    Assert.assertTrue(PRINCIPAL.isExpired(100, 1000));
+  }
+
+  public void testIsExpiredWhenMaxDurationIsSmall() throws InterruptedException

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




-- 
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