laminelam commented on code in PR #1994: URL: https://github.com/apache/solr/pull/1994#discussion_r1366016833
########## solr/modules/aws-secret-provider/src/test/org/apache/solr/secret/zk/AWSSecretCredentialsProviderTest.java: ########## @@ -0,0 +1,440 @@ +/* + * 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.solr.secret.zk; + +import static org.apache.solr.common.cloud.SolrZkClient.ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME; +import static org.apache.solr.common.cloud.SolrZkClient.ZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAME; +import static org.apache.solr.common.cloud.SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME; +import static org.apache.solr.secret.zk.AWSSecretManagerCredentialsInjector.SECRET_CREDENTIAL_PROVIDER_SECRET_NAME_VM_PARAM; +import static org.apache.solr.secret.zk.AWSSecretManagerCredentialsInjector.SecretMultiCredentials; + +import java.lang.invoke.MethodHandles; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.cloud.AbstractZkTestCase; +import org.apache.solr.cloud.ZkTestServer; +import org.apache.solr.common.cloud.DigestZkACLProvider; +import org.apache.solr.common.cloud.DigestZkCredentialsProvider; +import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; +import org.apache.solr.common.cloud.SolrZkClient; +import org.apache.solr.common.cloud.ZkCredentialsInjector; +import org.apache.solr.common.cloud.ZkCredentialsInjector.ZkCredential; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException.NoAuthException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AWSSecretCredentialsProviderTest extends SolrTestCaseJ4 { + + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private static final Charset DATA_ENCODING = StandardCharsets.UTF_8; + + private static final String ALL_USERNAME = "connectAndAllACLUsername"; + private static final String ALL_PASSWORD = "connectAndAllACLPassword"; + private static final String READONLY_USERNAME = "readonlyACLUsername"; + private static final String READONLY_PASSWORD = "readonlyACLPassword"; + + public static final String SECRET_NAME = "zkSecretCredentialSecretName"; + + protected ZkTestServer zkServer; + + protected Path zkDir; + + @BeforeClass + public static void beforeClass() { + System.setProperty("solrcloud.skip.autorecovery", "true"); + } + + @AfterClass + public static void afterClass() { + System.clearProperty("solrcloud.skip.autorecovery"); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + assumeWorkingMockito(); + if (log.isInfoEnabled()) { + log.info("####SETUP_START {}", getTestName()); + } + + zkDir = createTempDir().resolve("zookeeper/server1/data"); + log.info("ZooKeeper dataDir:{}", zkDir); + setSecuritySystemProperties(); + zkServer = new ZkTestServer(zkDir); + zkServer.run(false); + + System.setProperty("zkHost", zkServer.getZkAddress()); + + setSecretDigestZkSystemProps(); + System.setProperty( + ZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAME, + AllAndReadonlyCredentialZkCredentialsInjector.class.getName()); + + SolrZkClient zkClient = Review Comment: Hi @risdenk This is an existing (copied) code. For some reason (race condition?) you need to close and recreate ZKClient to make the nodes creation successful. You cannot reuse it in the last block because you want to connect to ZK with 'OPEN_ACL_UNSAFE' ACLs. Refactored the existing code and added new tests classes to void code duplication. Created a new _setUpZKNodes_ method. I think _AbstractDigestZkACLAndCredentialsProvidersTestBase_ (which BTW is not _abstract_) needs more refactoring. Didn't want to make this PR bigger than it already is, but we should consider favoring composition over inheritance here. -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org