mirror of https://github.com/apache/lucene.git
SOLR-7967: AddSchemaFieldsUpdateProcessorFactory does not check if the ConfigSet is immutable
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1707424 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
54e79b8179
commit
4a78c824a5
|
@ -242,6 +242,8 @@ Bug Fixes
|
|||
|
||||
* SOLR-7666: Many small fixes to Angular UI (Upayavira, Alexandre Rafalovitch)
|
||||
|
||||
* SOLR-7967: AddSchemaFieldsUpdateProcessorFactory does not check if the ConfigSet is immutable (Gregory Chanan)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import java.util.Set;
|
|||
|
||||
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
|
||||
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
|
||||
import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -290,6 +291,9 @@ public class AddSchemaFieldsUpdateProcessorFactory extends UpdateRequestProcesso
|
|||
// nothing to do - no fields will be added - exit from the retry loop
|
||||
log.debug("No fields to add to the schema.");
|
||||
break;
|
||||
} else if ( isImmutableConfigSet(core) ) {
|
||||
final String message = "This ConfigSet is immutable.";
|
||||
throw new SolrException(BAD_REQUEST, message);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -399,5 +403,11 @@ public class AddSchemaFieldsUpdateProcessorFactory extends UpdateRequestProcesso
|
|||
}
|
||||
return selector;
|
||||
}
|
||||
|
||||
private boolean isImmutableConfigSet(SolrCore core) {
|
||||
NamedList args = core.getConfigSetProperties();
|
||||
Object immutable = args != null ? args.get(IMMUTABLE_CONFIGSET_ARG) : null;
|
||||
return immutable != null ? Boolean.parseBoolean(immutable.toString()) : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.Map;
|
|||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.util.RestTestBase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -48,9 +50,8 @@ public class TestConfigSetImmutable extends RestTestBase {
|
|||
FileUtils.write(new File(tmpConfDir, "configsetprops.json"), new StringBuilder("{\"immutable\":\"true\"}"));
|
||||
|
||||
System.setProperty("managed.schema.mutable", "true");
|
||||
System.setProperty("enable.update.log", "false");
|
||||
|
||||
createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-managed-schema.xml", "schema-rest.xml",
|
||||
createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-schemaless.xml", "schema-rest.xml",
|
||||
"/solr", true, null);
|
||||
}
|
||||
|
||||
|
@ -95,4 +96,24 @@ public class TestConfigSetImmutable extends RestTestBase {
|
|||
assertNotNull(map.get("errors"));
|
||||
assertTrue(map.get("errors").toString().contains("immutable"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSchemaFieldsImmutable() throws Exception {
|
||||
final String error = "error";
|
||||
|
||||
// check writing an existing field is okay
|
||||
String updateXMLSafe = "<add><doc><field name=\"id\">\"testdoc\"</field></doc></add>";
|
||||
String response = restTestHarness.update(updateXMLSafe);
|
||||
XMLResponseParser parser = new XMLResponseParser();
|
||||
NamedList<Object> listResponse = parser.processResponse(new StringReader(response));
|
||||
assertNull(listResponse.get(error));
|
||||
|
||||
// check writing a new field is not okay
|
||||
String updateXMLNotSafe = "<add><doc><field name=\"id\">\"testdoc\"</field>" +
|
||||
"<field name=\"newField67\">\"foobar\"</field></doc></add>";
|
||||
response = restTestHarness.update(updateXMLNotSafe);
|
||||
listResponse = parser.processResponse(new StringReader(response));
|
||||
assertNotNull(listResponse.get(error));
|
||||
assertTrue(listResponse.get(error).toString().contains("immutable"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue