anshumg commented on a change in pull request #112: URL: https://github.com/apache/solr/pull/112#discussion_r627675744
########## File path: solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java ########## @@ -0,0 +1,159 @@ +/* + * 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.cloud; + +import java.io.IOException; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; + +import org.apache.lucene.util.LuceneTestCase.Slow; +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrResponse; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.response.CollectionAdminResponse; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.cloud.DocCollection; +import org.apache.solr.common.cloud.Replica; +import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.util.Utils; +import org.apache.solr.security.BasicAuthPlugin; +import org.apache.solr.security.RuleBasedAuthorizationPlugin; +import org.apache.solr.util.LogLevel; +import org.junit.BeforeClass; + +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; +import static org.apache.solr.cloud.TestPullReplica.assertNumberOfReplicas; +import static org.apache.solr.cloud.TestPullReplica.assertUlogPresence; +import static org.apache.solr.cloud.TestPullReplica.waitForDeletion; +import static org.apache.solr.cloud.TestPullReplica.waitForNumDocsInAllReplicas; +import static org.apache.solr.security.Sha256AuthenticationProvider.getSaltedHashedValue; + +@Slow +@LogLevel("org.apache.solr.handler.ReplicationHandler=DEBUG,org.apache.solr.handler.IndexFetcher=DEBUG") +public class TestPullReplicaWithAuth extends SolrCloudTestCase { + + private static final String USER = "solr"; + private static final String PASS = "SolrRocksAgain"; + private static final String collectionName = "testPullReplicaWithAuth"; + + @BeforeClass + public static void setupClusterWithSecurityEnabled() throws Exception { + final String SECURITY_JSON = Utils.toJSONString + (Map.of("authorization", + Map.of("class", RuleBasedAuthorizationPlugin.class.getName(), + "user-role", singletonMap(USER, "admin"), + "permissions", singletonList(Map.of("name", "all", "role", "admin"))), + "authentication", + Map.of("class", BasicAuthPlugin.class.getName(), + "blockUnknown", true, + "credentials", singletonMap(USER, getSaltedHashedValue(PASS))))); + + configureCluster(2) + .addConfig("conf", configset("cloud-minimal")) + .withSecurityJson(SECURITY_JSON) + .configure(); + } + + private <T extends SolrRequest<? extends SolrResponse>> T withBasicAuth(T req) { + req.setBasicAuthCredentials(USER, PASS); + return req; + } + + private QueryResponse queryWithBasicAuth(HttpSolrClient client, SolrQuery q) throws IOException, SolrServerException { + return withBasicAuth(new QueryRequest(q)).process(client); + } + + @SuppressWarnings("unchecked") Review comment: This might not be needed 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
