Search in sources :

Example 1 with LogLevel

use of org.apache.solr.util.LogLevel in project lucene-solr by apache.

the class BasicAuthStandaloneTest method testBasicAuth.

@Test
@LogLevel("org.apache.solr=DEBUG")
public void testBasicAuth() throws Exception {
    String authcPrefix = "/admin/authentication";
    HttpClient cl = null;
    HttpSolrClient httpSolrClient = null;
    try {
        cl = HttpClientUtil.createClient(null);
        String baseUrl = buildUrl(jetty.getLocalPort(), "/solr");
        httpSolrClient = getHttpSolrClient(baseUrl);
        verifySecurityStatus(cl, baseUrl + authcPrefix, "/errorMessages", null, 20);
        // Write security.json locally. Should cause security to be initialized
        securityConfHandler.persistConf(new SecurityConfHandler.SecurityConfig().setData(Utils.fromJSONString(STD_CONF.replaceAll("'", "\""))));
        securityConfHandler.securityConfEdited();
        verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20);
        String command = "{\n" + "'set-user': {'harry':'HarryIsCool'}\n" + "}";
        GenericSolrRequest genericReq = new GenericSolrRequest(SolrRequest.METHOD.POST, authcPrefix, new ModifiableSolrParams());
        genericReq.setContentStreams(Collections.singletonList(new ContentStreamBase.ByteArrayStream(command.getBytes(UTF_8), "")));
        HttpSolrClient finalHttpSolrClient = httpSolrClient;
        HttpSolrClient.RemoteSolrException exp = expectThrows(HttpSolrClient.RemoteSolrException.class, () -> {
            finalHttpSolrClient.request(genericReq);
        });
        assertEquals(401, exp.code());
        command = "{\n" + "'set-user': {'harry':'HarryIsUberCool'}\n" + "}";
        HttpPost httpPost = new HttpPost(baseUrl + authcPrefix);
        setBasicAuthHeader(httpPost, "solr", "SolrRocks");
        httpPost.setEntity(new ByteArrayEntity(command.getBytes(UTF_8)));
        httpPost.addHeader("Content-Type", "application/json; charset=UTF-8");
        verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication.enabled", "true", 20);
        HttpResponse r = cl.execute(httpPost);
        int statusCode = r.getStatusLine().getStatusCode();
        Utils.consumeFully(r.getEntity());
        assertEquals("proper_cred sent, but access denied", 200, statusCode);
        verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/credentials/harry", NOT_NULL_PREDICATE, 20);
        // Read file from SOLR_HOME and verify that it contains our new user
        assertTrue(new String(Utils.toJSON(securityConfHandler.getSecurityConfig(false).getData()), Charset.forName("UTF-8")).contains("harry"));
    } finally {
        if (cl != null) {
            HttpClientUtil.close(cl);
            httpSolrClient.close();
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) HttpPost(org.apache.http.client.methods.HttpPost) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test) LogLevel(org.apache.solr.util.LogLevel)

Example 2 with LogLevel

use of org.apache.solr.util.LogLevel in project lucene-solr by apache.

the class TestManagedSchemaThreadSafety method testThreadSafety.

@Test
@LogLevel("org.apache.solr.common.cloud.SolrZkClient=debug")
public void testThreadSafety() throws Exception {
    //
    final String configsetName = "managed-config";
    try (SolrZkClient client = new SuspendingZkClient(zkServer.getZkHost(), 30000)) {
        // we can pick any to load configs, I suppose, but here we check
        client.upConfig(configset("cloud-managed-upgrade"), configsetName);
    }
    ExecutorService executor = ExecutorUtil.newMDCAwareCachedThreadPool("threadpool");
    try (SolrZkClient raceJudge = new SuspendingZkClient(zkServer.getZkHost(), 30000)) {
        ZkController zkController = createZkController(raceJudge);
        List<Future<?>> futures = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            futures.add(executor.submit(indexSchemaLoader(configsetName, zkController)));
        }
        for (Future<?> future : futures) {
            future.get();
        }
    } finally {
        ExecutorUtil.shutdownAndAwaitTermination(executor);
    }
}
Also used : ZkController(org.apache.solr.cloud.ZkController) MockZkController(org.apache.solr.cloud.MockZkController) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test) LogLevel(org.apache.solr.util.LogLevel)

Example 3 with LogLevel

use of org.apache.solr.util.LogLevel in project lucene-solr by apache.

the class SolrTestCaseJ4 method initMethodLogLevels.

@Before
public void initMethodLogLevels() {
    Method method = RandomizedContext.current().getTargetMethod();
    LogLevel annotation = method.getAnnotation(LogLevel.class);
    if (annotation == null) {
        return;
    }
    Map<String, String> previousLevels = LogLevel.Configurer.setLevels(annotation.value());
    savedMethodLogLevels.putAll(previousLevels);
}
Also used : Method(java.lang.reflect.Method) LogLevel(org.apache.solr.util.LogLevel) Before(org.junit.Before)

Example 4 with LogLevel

use of org.apache.solr.util.LogLevel in project lucene-solr by apache.

the class TestLogLevelAnnotations method testMethodLogLevels.

@Test
@LogLevel("org.apache.solr.MethodLogLevel=debug")
public void testMethodLogLevels() {
    Logger classLogLevel = Logger.getLogger("org.apache.solr.ClassLogLevel");
    assertEquals(Level.ERROR, classLogLevel.getLevel());
    Logger methodLogLevel = Logger.getLogger("org.apache.solr.MethodLogLevel");
    assertEquals(Level.DEBUG, methodLogLevel.getLevel());
}
Also used : Logger(org.apache.log4j.Logger) Test(org.junit.Test) LogLevel(org.apache.solr.util.LogLevel)

Example 5 with LogLevel

use of org.apache.solr.util.LogLevel in project lucene-solr by apache.

the class SolrTestCaseJ4 method initClassLogLevels.

public static void initClassLogLevels() {
    Class currentClass = RandomizedContext.current().getTargetClass();
    LogLevel annotation = (LogLevel) currentClass.getAnnotation(LogLevel.class);
    if (annotation == null) {
        return;
    }
    Map<String, String> previousLevels = LogLevel.Configurer.setLevels(annotation.value());
    savedClassLogLevels.putAll(previousLevels);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) LogLevel(org.apache.solr.util.LogLevel)

Aggregations

LogLevel (org.apache.solr.util.LogLevel)5 Test (org.junit.Test)3 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 HttpResponse (org.apache.http.HttpResponse)1 HttpClient (org.apache.http.client.HttpClient)1 HttpPost (org.apache.http.client.methods.HttpPost)1 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)1 Logger (org.apache.log4j.Logger)1 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)1 GenericSolrRequest (org.apache.solr.client.solrj.request.GenericSolrRequest)1 MockZkController (org.apache.solr.cloud.MockZkController)1 ZkController (org.apache.solr.cloud.ZkController)1 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1