You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2016/07/05 07:24:58 UTC
[1/2] lucene-solr:branch_6x: SOLR-8048: Stop using deprecated
CollectionAdminRequest.Reload constructor (cherry picked from commit 8653be9)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 50a915346 -> 119ea15ad
SOLR-8048: Stop using deprecated CollectionAdminRequest.Reload constructor
(cherry picked from commit 8653be9)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/119ea15a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/119ea15a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/119ea15a
Branch: refs/heads/branch_6x
Commit: 119ea15ad6efaaf2c3b2d833820f152998599b2e
Parents: 31316f7
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Tue Jul 5 12:53:35 2016 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Tue Jul 5 12:54:49 2016 +0530
----------------------------------------------------------------------
.../org/apache/solr/security/BasicAuthIntegrationTest.java | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/119ea15a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
index f2a79c1..5cb322f 100644
--- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
@@ -154,8 +154,7 @@ public class BasicAuthIntegrationTest extends TestMiniSolrCloudClusterBase {
("name", "collection-admin-edit", "role", "admin"))), "harry", "HarryIsUberCool" );
verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/permissions[2]/name", "collection-admin-edit", 20);
- CollectionAdminRequest.Reload reload = new CollectionAdminRequest.Reload();
- reload.setCollectionName(defaultCollName);
+ CollectionAdminRequest.Reload reload = CollectionAdminRequest.reloadCollection(defaultCollName);
try (HttpSolrClient solrClient = getHttpSolrClient(baseUrl)) {
try {
@@ -172,13 +171,11 @@ public class BasicAuthIntegrationTest extends TestMiniSolrCloudClusterBase {
}
}
- cloudSolrClient.request(new CollectionAdminRequest.Reload()
- .setCollectionName(defaultCollName)
+ cloudSolrClient.request(CollectionAdminRequest.reloadCollection(defaultCollName)
.setBasicAuthCredentials("harry", "HarryIsUberCool"));
try {
- cloudSolrClient.request(new CollectionAdminRequest.Reload()
- .setCollectionName(defaultCollName)
+ cloudSolrClient.request(CollectionAdminRequest.reloadCollection(defaultCollName)
.setBasicAuthCredentials("harry", "Cool12345"));
fail("This should not succeed");
} catch (HttpSolrClient.RemoteSolrException e) {
[2/2] lucene-solr:branch_6x: SOLR-8048: Close the http client in a
finally clause at the end of the test (cherry picked from commit 2d6b7ea)
Posted by sh...@apache.org.
SOLR-8048: Close the http client in a finally clause at the end of the test
(cherry picked from commit 2d6b7ea)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/31316f76
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/31316f76
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/31316f76
Branch: refs/heads/branch_6x
Commit: 31316f7682f47acdbbd3367e9067b093f25044e5
Parents: 50a9153
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Tue Jul 5 12:48:04 2016 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Tue Jul 5 12:54:49 2016 +0530
----------------------------------------------------------------------
.../solr/security/BasicAuthIntegrationTest.java | 230 ++++++++++---------
1 file changed, 118 insertions(+), 112 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/31316f76/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
index 89e4140..f2a79c1 100644
--- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
@@ -86,135 +86,141 @@ public class BasicAuthIntegrationTest extends TestMiniSolrCloudClusterBase {
cloudSolrClient.setDefaultCollection(null);
NamedList<Object> rsp;
- HttpClient cl = HttpClientUtil.createClient(null);
- String baseUrl = getRandomReplica(zkStateReader.getClusterState().getCollection(defaultCollName), random()).getStr(BASE_URL_PROP);
- verifySecurityStatus(cl, baseUrl + authcPrefix, "/errorMessages", null, 20);
- zkClient.setData("/security.json", STD_CONF.replaceAll("'", "\"").getBytes(UTF_8), true);
- verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20);
-
- boolean found = false;
- for (JettySolrRunner jettySolrRunner : miniCluster.getJettySolrRunners()) {
- if(baseUrl.contains(String.valueOf(jettySolrRunner.getLocalPort()))){
- found = true;
- jettySolrRunner.stop();
- jettySolrRunner.start();
- verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20);
- break;
- }
- }
-
- assertTrue("No server found to restart , looking for : "+baseUrl , found);
-
- 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), "")));
+ HttpClient cl = null;
try {
- cloudSolrClient.request(genericReq);
- fail("Should have failed with a 401");
- } catch (HttpSolrClient.RemoteSolrException e) {
- }
- 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);
- baseUrl = getRandomReplica(zkStateReader.getClusterState().getCollection(defaultCollName), random()).getStr(BASE_URL_PROP);
-
- verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/credentials/harry", NOT_NULL_PREDICATE, 20);
- command = "{\n" +
- "'set-user-role': {'harry':'admin'}\n" +
- "}";
-
- executeCommand(baseUrl + authzPrefix, cl,command, "solr", "SolrRocks");
-
- baseUrl = getRandomReplica(zkStateReader.getClusterState().getCollection(defaultCollName), random()).getStr(BASE_URL_PROP);
- verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/user-role/harry", NOT_NULL_PREDICATE, 20);
-
- executeCommand(baseUrl + authzPrefix, cl, Utils.toJSONString(singletonMap("set-permission", Utils.makeMap
- ("collection", "x",
- "path", "/update/*",
- "role", "dev"))), "harry", "HarryIsUberCool" );
-
- verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/permissions[1]/collection", "x", 20);
+ cl = HttpClientUtil.createClient(null);
+ String baseUrl = getRandomReplica(zkStateReader.getClusterState().getCollection(defaultCollName), random()).getStr(BASE_URL_PROP);
+ verifySecurityStatus(cl, baseUrl + authcPrefix, "/errorMessages", null, 20);
+ zkClient.setData("/security.json", STD_CONF.replaceAll("'", "\"").getBytes(UTF_8), true);
+ verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20);
+
+ boolean found = false;
+ for (JettySolrRunner jettySolrRunner : miniCluster.getJettySolrRunners()) {
+ if(baseUrl.contains(String.valueOf(jettySolrRunner.getLocalPort()))){
+ found = true;
+ jettySolrRunner.stop();
+ jettySolrRunner.start();
+ verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20);
+ break;
+ }
+ }
- executeCommand(baseUrl + authzPrefix, cl,Utils.toJSONString(singletonMap("set-permission", Utils.makeMap
- ("name", "collection-admin-edit", "role", "admin"))), "harry", "HarryIsUberCool" );
- verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/permissions[2]/name", "collection-admin-edit", 20);
+ assertTrue("No server found to restart , looking for : "+baseUrl , found);
- CollectionAdminRequest.Reload reload = new CollectionAdminRequest.Reload();
- reload.setCollectionName(defaultCollName);
+ String command = "{\n" +
+ "'set-user': {'harry':'HarryIsCool'}\n" +
+ "}";
- try (HttpSolrClient solrClient = getHttpSolrClient(baseUrl)) {
+ GenericSolrRequest genericReq = new GenericSolrRequest(SolrRequest.METHOD.POST, authcPrefix, new ModifiableSolrParams());
+ genericReq.setContentStreams(Collections.singletonList(new ContentStreamBase.ByteArrayStream(command.getBytes(UTF_8), "")));
try {
- rsp = solrClient.request(reload);
- fail("must have failed");
+ cloudSolrClient.request(genericReq);
+ fail("Should have failed with a 401");
} catch (HttpSolrClient.RemoteSolrException e) {
-
}
- reload.setMethod(SolrRequest.METHOD.POST);
- try {
- rsp = solrClient.request(reload);
- fail("must have failed");
- } catch (HttpSolrClient.RemoteSolrException e) {
+ 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);
+ baseUrl = getRandomReplica(zkStateReader.getClusterState().getCollection(defaultCollName), random()).getStr(BASE_URL_PROP);
+
+ verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/credentials/harry", NOT_NULL_PREDICATE, 20);
+ command = "{\n" +
+ "'set-user-role': {'harry':'admin'}\n" +
+ "}";
+
+ executeCommand(baseUrl + authzPrefix, cl,command, "solr", "SolrRocks");
+
+ baseUrl = getRandomReplica(zkStateReader.getClusterState().getCollection(defaultCollName), random()).getStr(BASE_URL_PROP);
+ verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/user-role/harry", NOT_NULL_PREDICATE, 20);
+
+ executeCommand(baseUrl + authzPrefix, cl, Utils.toJSONString(singletonMap("set-permission", Utils.makeMap
+ ("collection", "x",
+ "path", "/update/*",
+ "role", "dev"))), "harry", "HarryIsUberCool" );
+
+ verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/permissions[1]/collection", "x", 20);
+
+ executeCommand(baseUrl + authzPrefix, cl,Utils.toJSONString(singletonMap("set-permission", Utils.makeMap
+ ("name", "collection-admin-edit", "role", "admin"))), "harry", "HarryIsUberCool" );
+ verifySecurityStatus(cl, baseUrl + authzPrefix, "authorization/permissions[2]/name", "collection-admin-edit", 20);
+
+ CollectionAdminRequest.Reload reload = new CollectionAdminRequest.Reload();
+ reload.setCollectionName(defaultCollName);
+
+ try (HttpSolrClient solrClient = getHttpSolrClient(baseUrl)) {
+ try {
+ rsp = solrClient.request(reload);
+ fail("must have failed");
+ } catch (HttpSolrClient.RemoteSolrException e) {
- }
- }
- cloudSolrClient.request(new CollectionAdminRequest.Reload()
- .setCollectionName(defaultCollName)
- .setBasicAuthCredentials("harry", "HarryIsUberCool"));
+ }
+ reload.setMethod(SolrRequest.METHOD.POST);
+ try {
+ rsp = solrClient.request(reload);
+ fail("must have failed");
+ } catch (HttpSolrClient.RemoteSolrException e) {
- try {
+ }
+ }
cloudSolrClient.request(new CollectionAdminRequest.Reload()
.setCollectionName(defaultCollName)
- .setBasicAuthCredentials("harry", "Cool12345"));
- fail("This should not succeed");
- } catch (HttpSolrClient.RemoteSolrException e) {
+ .setBasicAuthCredentials("harry", "HarryIsUberCool"));
- }
+ try {
+ cloudSolrClient.request(new CollectionAdminRequest.Reload()
+ .setCollectionName(defaultCollName)
+ .setBasicAuthCredentials("harry", "Cool12345"));
+ fail("This should not succeed");
+ } catch (HttpSolrClient.RemoteSolrException e) {
- cloudSolrClient.setDefaultCollection(old);
- executeCommand(baseUrl + authzPrefix, cl,"{set-permission : { name : update , role : admin}}", "harry", "HarryIsUberCool");
+ }
- SolrInputDocument doc = new SolrInputDocument();
- doc.setField("id","4");
- UpdateRequest update = new UpdateRequest();
- update.setBasicAuthCredentials("harry","HarryIsUberCool");
- update.add(doc);
- update.setCommitWithin(100);
- cloudSolrClient.request(update);
+ cloudSolrClient.setDefaultCollection(old);
+ executeCommand(baseUrl + authzPrefix, cl,"{set-permission : { name : update , role : admin}}", "harry", "HarryIsUberCool");
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.setField("id","4");
+ UpdateRequest update = new UpdateRequest();
+ update.setBasicAuthCredentials("harry","HarryIsUberCool");
+ update.add(doc);
+ update.setCommitWithin(100);
+ cloudSolrClient.request(update);
- executeCommand(baseUrl + authzPrefix, cl, "{set-property : { blockUnknown: true}}", "harry", "HarryIsUberCool");
- String[] toolArgs = new String[]{
- "status", "-solr", baseUrl};
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
- SolrCLI.StatusTool tool = new SolrCLI.StatusTool(stdoutSim);
- try {
- System.setProperty("basicauth", "harry:HarryIsUberCool");
- tool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), toolArgs));
- Map obj = (Map) Utils.fromJSON(new ByteArrayInputStream(baos.toByteArray()));
- assertTrue(obj.containsKey("version"));
- assertTrue(obj.containsKey("startTime"));
- assertTrue(obj.containsKey("uptime"));
- assertTrue(obj.containsKey("memory"));
- } catch (Exception e) {
- log.error("RunExampleTool failed due to: " + e +
- "; stdout from tool prior to failure: " + baos.toString(StandardCharsets.UTF_8.name()));
+
+ executeCommand(baseUrl + authzPrefix, cl, "{set-property : { blockUnknown: true}}", "harry", "HarryIsUberCool");
+ String[] toolArgs = new String[]{
+ "status", "-solr", baseUrl};
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
+ SolrCLI.StatusTool tool = new SolrCLI.StatusTool(stdoutSim);
+ try {
+ System.setProperty("basicauth", "harry:HarryIsUberCool");
+ tool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(tool.getOptions()), toolArgs));
+ Map obj = (Map) Utils.fromJSON(new ByteArrayInputStream(baos.toByteArray()));
+ assertTrue(obj.containsKey("version"));
+ assertTrue(obj.containsKey("startTime"));
+ assertTrue(obj.containsKey("uptime"));
+ assertTrue(obj.containsKey("memory"));
+ } catch (Exception e) {
+ log.error("RunExampleTool failed due to: " + e +
+ "; stdout from tool prior to failure: " + baos.toString(StandardCharsets.UTF_8.name()));
+ }
+ executeCommand(baseUrl + authzPrefix, cl, "{set-property : { blockUnknown: false}}", "harry", "HarryIsUberCool");
+ } finally {
+ if (cl != null) {
+ HttpClientUtil.close(cl);
+ }
}
- executeCommand(baseUrl + authzPrefix, cl, "{set-property : { blockUnknown: false}}", "harry", "HarryIsUberCool");
- HttpClientUtil.close(cl);
}
public static void executeCommand(String url, HttpClient cl, String payload, String user, String pwd) throws IOException {