Extend tests of owner: search with trailing slash

Add tests to confirm behavior when passing an invalid query
containing trailing slash.

For Lucene: return bad request
For Elasticsearch: return no result

Bug: Issue 4168
Change-Id: I0187c49f6b73b3792fd5df27d6db6ca7fd50ca80
This commit is contained in:
David Pursehouse
2016-06-08 13:11:30 +09:00
parent 7959720c79
commit c2e1e12b58
3 changed files with 27 additions and 0 deletions

View File

@@ -27,12 +27,14 @@ import com.google.gerrit.server.index.IndexModule.IndexType;
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.gerrit.testutil.InMemoryRepositoryManager.Repo;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Config;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.elasticsearch.common.settings.Settings;
@@ -41,6 +43,7 @@ import org.elasticsearch.node.NodeBuilder;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.nio.file.Path;
@@ -179,4 +182,13 @@ public class ElasticQueryChangesTest extends AbstractQueryChangesTest {
return httpAddress.substring(httpAddress.indexOf(':') + 1,
httpAddress.length());
}
@Test
public void byOwnerInvalidQuery() throws Exception {
TestRepository<Repo> repo = createProject("repo");
insert(repo, newChange(repo), userId);
String nameEmail = user.asIdentifiedUser().getNameEmail();
assertQuery("owner: \"" + nameEmail + "\"\\");
}
}

View File

@@ -374,6 +374,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
assertQuery("owner:" + userId.get(), change1);
assertQuery("owner:" + user2, change2);
String nameEmail = user.asIdentifiedUser().getNameEmail();
assertQuery("owner: \"" + nameEmail + "\"", change1);
}
@Test

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.query.change;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.gerrit.testutil.InMemoryRepositoryManager.Repo;
@@ -52,4 +53,15 @@ public class LuceneQueryChangesTest extends AbstractQueryChangesTest {
assertQuery("message:one.two", change2);
assertQuery("message:one two", change2);
}
@Test
public void byOwnerInvalidQuery() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo), userId);
String nameEmail = user.asIdentifiedUser().getNameEmail();
exception.expect(BadRequestException.class);
exception.expectMessage("Cannot create full-text query with value: \\");
assertQuery("owner: \"" + nameEmail + "\"\\", change1);
}
}