SOLR-13637: reject duplicate jar updates

This commit is contained in:
noble 2019-07-22 16:23:44 -04:00
parent 2ef0ba3dce
commit 7f04604d56
2 changed files with 19 additions and 4 deletions

View File

@ -25,6 +25,7 @@ import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.solr.api.ApiBag;
import org.apache.solr.client.solrj.SolrRequest;
@ -59,6 +60,7 @@ import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.apache.solr.common.util.CommandOperation.captureErrors;
import static org.apache.solr.common.util.StrUtils.formatString;
import static org.apache.solr.core.RuntimeLib.SHA512;
public class CollectionHandlerApi extends BaseHandlerApiSupport {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -204,7 +206,11 @@ public class CollectionHandlerApi extends BaseHandlerApiSupport {
}
} else {
if (existing == null) {
op.addError(StrUtils.formatString("The jar with a name ''{0}'' doesn not exist", name));
op.addError(StrUtils.formatString("The jar with a name ''{0}'' does not exist", name));
return false;
}
if(Objects.equals( existing.get(SHA512) , op.getDataMap().get(SHA512))){
op.addError("Trying to update a jar with the same sha512");
return false;
}
}

View File

@ -529,7 +529,6 @@ public class TestContainerReqHandler extends SolrCloudTestCase {
"loader", MemClassLoader.class.getName()));
payload = "{update-runtimelib:{name : 'foo', url: 'http://localhost:" + port + "/jar2.jar', " +
"sha512 : 'bc5ce45ad281b6a08fb7e529b1eb475040076834816570902acb6ebdd809410e31006efdeaa7f78a6c35574f3504963f5f7e4d92247d0eb4db3fc9abdda5d417'}}";
new V2Request.Builder("/cluster")
@ -539,13 +538,23 @@ public class TestContainerReqHandler extends SolrCloudTestCase {
assertEquals(getObjectByPath(Utils.fromJSONString(payload), true, "update-runtimelib/sha512"),
getObjectByPath(new ClusterProperties(cluster.getZkClient()).getClusterProperties(), true, "runtimeLib/foo/sha512"));
try {
new V2Request.Builder("/cluster")
.withPayload(payload)
.withMethod(SolrRequest.METHOD.POST)
.build().process(cluster.getSolrClient());
fail("should have failed");
} catch (BaseHttpSolrClient.RemoteExecutionException e) {
assertTrue("actual output : " + Utils.toJSONString(e.getMetaData()), e.getMetaData()._getStr("error/details[0]/errorMessages[0]", "").contains("Trying to update a jar with the same sha512"));
}
assertResponseValues(10,
cluster.getSolrClient(),
new GenericSolrRequest(SolrRequest.METHOD.GET, "/get?abc=xyz", params),
Utils.makeMap("get", "org.apache.solr.core.RuntimeLibSearchComponent",
"loader", MemClassLoader.class.getName(),
"Version","2"));
"loader", MemClassLoader.class.getName(),
"Version", "2"));
} finally {
cluster.deleteAllCollections();
cluster.shutdown();