Add query test that resolving "self" fails for anonymous users
Change-Id: Ib9312e9706f30c914e69f89f16b7310627e95f0f
This commit is contained in:
committed by
Edwin Kempin
parent
c3c55cfb4a
commit
4a4ab7b1a8
@@ -64,6 +64,7 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInput;
|
||||
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.index.FieldDef;
|
||||
@@ -3095,6 +3096,23 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
assertQuery("project:repo+foo", change);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selfFailsForAnonymousUser() throws Exception {
|
||||
for (String query : ImmutableList.of("assignee:self", "starredby:self", "is:starred")) {
|
||||
assertQuery(query);
|
||||
RequestContext oldContext = requestContext.setContext(anonymousUserProvider::get);
|
||||
|
||||
try {
|
||||
requestContext.setContext(anonymousUserProvider::get);
|
||||
assertThatAuthException(query)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Must be signed-in to use this operator");
|
||||
} finally {
|
||||
requestContext.setContext(oldContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ChangeInserter newChange(TestRepository<Repo> repo) throws Exception {
|
||||
return newChange(repo, null, null, null, null, false);
|
||||
}
|
||||
@@ -3224,6 +3242,15 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
protected ThrowableSubject assertThatAuthException(Object query) throws Exception {
|
||||
try {
|
||||
newQuery(query).get();
|
||||
throw new AssertionError("expected AuthException for query: " + query);
|
||||
} catch (AuthException e) {
|
||||
return assertThat(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected TestRepository<Repo> createProject(String name) throws Exception {
|
||||
gApi.projects().create(name).get();
|
||||
return new TestRepository<>(repoManager.openRepository(new Project.NameKey(name)));
|
||||
|
||||
Reference in New Issue
Block a user