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();
}
}
}
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);
}
}
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);
}
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());
}
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);
}
Aggregations