janhoy commented on code in PR #5323: URL: https://github.com/apache/solr/pull/5323#discussion_r4551287162
########## solr/packaging/src/test/org/apache/solr/shell/AuthTest.java: ########## @@ -0,0 +1,109 @@ +/* + * 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.shell; + +import java.io.IOException; +import java.nio.file.Files; +import org.apache.lucene.util.IOUtils; +import org.apache.solr.shell.exec.Shell; +import org.junit.Before; +import org.junit.Test; + +/** + * Port of {@code test_auth.bats}. There are further auth tests in {@link SslTest}. + * + * <p>Kept close to the original, including the order of the tests and the text each asserts on. + * Where it differs: + * + * <ul> + * <li>{@code curl} becomes {@link #http}, which now also carries credentials, {@code curl -u + * user:password --basic} being half of what this suite does. + * <li>{@code solr auth enable} rewrites the include file, by default the distribution's own and + * so shared with every concurrent class, so {@link #cleanSetup} points {@code SOLR_INCLUDE} + * at a private copy — as {@code SslTest} does. + * <li>The original's {@code setup} runs {@code solr auth disable} before every test, to undo what + * a previous test left in the include file and in ZooKeeper. Here the include file is a + * pristine copy per test and {@code SOLR_HOME} — which holds the embedded ZooKeeper's data — + * is wiped per test, so there is nothing to disable. + * <li>The two {@code auth enable} calls the original lets succeed-or-fail silently are asserted + * to succeed. + * </ul> + */ +public class AuthTest extends SolrShellTestCase { + + @Before + public void cleanSetup() throws IOException { + // BATS' common_clean_setup: every test here starts its own Solr, from a clean SOLR_HOME. The + // wipe also discards the embedded ZooKeeper's data, and with it any security.json. + IOUtils.rm(harnessEnv.solrHome()); + Files.createDirectories(harnessEnv.logsDir()); + + // 'solr auth enable' appends to the include file, which by default belongs to the distribution + // every test class shares, so each test gets a private copy in its own work directory. The + // name has to keep its extension: bin\solr.cmd CALLs the include file. + String includeFile = cli.shell() == Shell.BASH ? "solr.in.sh" : "solr.in.cmd"; Review Comment: Fair ask. I think this is the only place we use this pattern. Once we reach 3 I'd agree it is a framework candidate... CATS is so far fairly generic.. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
