Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle large properly values in manual indexes better
* At the moment if you try to add a manual index with a very large property value you'll get an overflow exception because the value gets included in the response header and exceeds the value configured with Jetty. * This commit makes that value configurable and fails early if it looks like the response header size is going to exceed the configured value. We give 512 bytes for any other headers so you might need to set the value a bit higher than you want.
- Loading branch information
Mark Needham
committed
Mar 30, 2015
1 parent
abf94a0
commit 3af617d
Showing
17 changed files
with
279 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
community/server/src/test/java/org/neo4j/server/LegacyIndexIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.theories.DataPoints; | ||
import org.junit.experimental.theories.Theories; | ||
import org.junit.experimental.theories.Theory; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.IOException; | ||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.SecureRandom; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Random; | ||
import javax.net.ssl.HttpsURLConnection; | ||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
import org.neo4j.server.configuration.ServerSettings; | ||
import org.neo4j.test.server.ExclusiveServerTestBase; | ||
import org.neo4j.test.server.HTTP; | ||
|
||
import static org.hamcrest.CoreMatchers.startsWith; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.neo4j.server.helpers.CommunityServerBuilder.server; | ||
import static org.neo4j.test.server.HTTP.GET; | ||
import static org.neo4j.test.server.HTTP.POST; | ||
import static org.neo4j.test.server.HTTP.RawPayload.quotedJson; | ||
|
||
@RunWith(Theories.class) | ||
public class LegacyIndexIT extends ExclusiveServerTestBase | ||
{ | ||
private CommunityNeoServer server; | ||
|
||
public static @DataPoints String[] candidates = {"", "get_or_create", "create_or_fail"}; | ||
|
||
@After | ||
public void stopTheServer() | ||
{ | ||
server.stop(); | ||
} | ||
|
||
@Before | ||
public void startServer() throws NoSuchAlgorithmException, KeyManagementException, IOException | ||
{ | ||
server = server().withHttpsEnabled() | ||
.withProperty( "remote_shell_enabled", "false" ) | ||
.withProperty( "dbms.security.auth_enabled", "false" ) | ||
.usingDatabaseDir( folder.cleanDirectory( name.getMethodName() ).getAbsolutePath() ) | ||
.build(); | ||
} | ||
|
||
@Theory | ||
public void shouldRejectIndexValueLargerThanConfiguredSize(String uniqueness) throws Exception | ||
{ | ||
//Given | ||
server.getConfiguration().setProperty( ServerSettings.maximum_response_header_size.name(), "5000" ); | ||
server.start(); | ||
|
||
// When | ||
String nodeURI = HTTP.POST( server.baseUri().toString() + "db/data/node").header( "Location" ); | ||
|
||
Random r = new Random(); | ||
String value = ""; | ||
for ( int i = 0; i < 6_000; i++ ) | ||
{ | ||
value += (char)(r.nextInt(26) + 'a'); | ||
} | ||
HTTP.Response response = | ||
HTTP.POST( server.baseUri().toString() + "db/data/index/node/favorites?uniqueness=" + uniqueness, | ||
quotedJson( "{ 'value': '" + value + " ', 'uri':'" + nodeURI + "', 'key': 'some-key' }" ) ); | ||
|
||
// Then | ||
assertThat( response.status(), is( 413 ) ); | ||
} | ||
|
||
@Theory | ||
public void shouldNotRejectIndexValueThatIsJustSmallerThanConfiguredSize(String uniqueness) throws Exception | ||
{ | ||
//Given | ||
server.getConfiguration().setProperty( ServerSettings.maximum_response_header_size.name(), "5000" ); | ||
server.start(); | ||
|
||
// When | ||
String nodeURI = HTTP.POST( server.baseUri().toString() + "db/data/node").header( "Location" ); | ||
|
||
Random r = new Random(); | ||
String value = ""; | ||
for ( int i = 0; i < 4_000; i++ ) | ||
{ | ||
value += (char)(r.nextInt(26) + 'a'); | ||
} | ||
HTTP.Response response = | ||
HTTP.POST( server.baseUri().toString() + "db/data/index/node/favorites?uniqueness=" + uniqueness, | ||
quotedJson( "{ 'value': '" + value + " ', 'uri':'" + nodeURI + "', 'key': 'some-key' }" ) ); | ||
|
||
// Then | ||
assertThat( response.status(), is( 201 ) ); | ||
} | ||
} |
Oops, something went wrong.